aboutsummaryrefslogtreecommitdiff
path: root/clang/test/CodeGenObjC
AgeCommit message (Collapse)AuthorFilesLines
2025-09-02[Clang] [C2y] Implement N3355 ‘Named Loops’ (#152870)Sirraide1-0/+174
This implements support for [named loops](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3355.htm) for C2y. When parsing a `LabelStmt`, we create the `LabeDecl` early before we parse the substatement; this label is then passed down to `ParseWhileStatement()` and friends, which then store it in the loop’s (or switch statement’s) `Scope`; when we encounter a `break/continue` statement, we perform a lookup for the label (and error if it doesn’t exist), and then walk the scope stack and check if there is a scope whose preceding label is the target label, which identifies the jump target. The feature is only supported in C2y mode, though a cc1-only option exists for testing (`-fnamed-loops`), which is mostly intended to try and make sure that we don’t have to refactor this entire implementation when/if we start supporting it in C++. --------- Co-authored-by: Balazs Benics <benicsbalazs@gmail.com>
2025-08-21[clang][DebugInfo][test] Move debug-info tests from CodeGenObjC to DebugInfo ↵Michael Buch57-1888/+0
directory (#154781) This patch works towards consolidating all Clang debug-info into the `clang/test/DebugInfo` directory (https://discourse.llvm.org/t/clang-test-location-of-clang-debug-info-tests/87958). Here we move only the `clang/test/CodeGenObjC` tests. The list of files i came up with is: 1. searched for anything with `*debug-info*` in the filename 2. searched for occurrences of `debug-info-kind` in the tests
2025-08-14[clang][Obj-C][PAC] Make block descriptor pointer signing configurable (#153700)Oliver Hunt2-3/+14
Pointer auth protection of the block descriptor pointer is only supported in some constrained environments so we do actually need it to be configurable. We had made it non configurable in the first PR to protect block metadata because we believed that was an option but subsequently realised it does need to remain configurable. This PR revives the flags that permit this.
2025-08-13[clang][Obj-C][PAC] Add support for authenticating block metadata (#152978)Oliver Hunt2-2/+31
Introduces the use of pointer authentication to protect the invocation, copy and dispose, reference, and descriptor pointers in Objective-C block objects. Resolves #141176
2025-08-08[IR] Remove size argument from lifetime intrinsics (#150248)Nikita Popov5-102/+102
Now that #149310 has restricted lifetime intrinsics to only work on allocas, we can also drop the explicit size argument. Instead, the size is implied by the alloca. This removes the ability to only mark a prefix of an alloca alive/dead. We never used that capability, so we should remove the need to handle that possibility everywhere (though many key places, including stack coloring, did not actually respect this).
2025-07-31[SimplifyCFG] Extend jump-threading to allow live local defs (#135079)LU-JOHN1-10/+9
Extend jump-threading to allow local defs that are live outside of the threaded block. Allow threading to destinations where the local defs are not live. --------- Signed-off-by: John Lu <John.Lu@amd.com>
2025-07-18[clang][CodeGen] Set `dead_on_return` when passing arguments indirectlyAntonio Frighetto3-6/+6
Let Clang emit `dead_on_return` attribute on pointer arguments that are passed indirectly, namely, large aggregates that the ABI mandates be passed by value; thus, the parameter is destroyed within the callee. Writes to such arguments are not observable by the caller after the callee returns. This should desirably enable further MemCpyOpt/DSE optimizations. Previous discussion: https://discourse.llvm.org/t/rfc-add-dead-on-return-attribute/86871.
2025-07-15[CodeGen][ObjC] Include all referenced protocols in protocol list (#148827)Hugo Melder1-0/+25
When constructing the protocol list in the class metadata generation (`GenerateClass`), only the protocols from the base class are added but not protocols declared in class extensions. This is fixed by using `all_referenced_protocol_{begin, end}` instead of `protocol_{begin, end}`, matching the behaviour on Apple platforms. A unit test is included to check if all protocol metadata was emitted and that no duplication occurs in the protocol list. Fixes https://github.com/gnustep/libobjc2/issues/339 CC: @davidchisnall
2025-07-14[clang][ObjC][PAC] Add ptrauth protections to objective-c (#147899)Oliver Hunt10-9/+477
This PR introduces the use of pointer authentication to objective-c[++]. This includes: * __ptrauth qualifier support for ivars * protection of isa and super fields * protection of SEL typed ivars * protection of class_ro_t data * protection of methodlist pointers and content
2025-04-10[C11] Implement WG14 N1285 (temporary lifetimes) (#133472)Aaron Ballman1-2/+3
This feature largely models the same behavior as in C++11. It is technically a breaking change between C99 and C11, so the paper is not being backported to older language modes. One difference between C++ and C is that things which are rvalues in C are often lvalues in C++ (such as the result of a ternary operator or a comma operator). Fixes #96486
2025-03-04[ObjC] Expand isClassLayoutKnownStatically to base classes as long as the ↵AZero1315-52/+89
implementation of it is known (#85465) Only NSObject we can trust the layout of won't change even though we cannot directly see its @implementation
2025-02-17[CodeGen][ObjC] Invalidate cached ObjC class layout information after ↵Akira Hatanaka2-2/+49
parsing ObjC class implementations if new ivars are added to the interface (#126591) The layout and the size of an ObjC interface can change after its corresponding implementation is parsed when synthesized ivars or ivars declared in categories are added to the interface's list of ivars. This can cause clang to mis-compile if the optimization that emits fixed offsets for ivars (see 923ddf65f4e21ec67018cf56e823895de18d83bc) uses an ObjC class layout that is outdated and no longer reflects the current state of the class. For example, when compiling `constant-non-fragile-ivar-offset.m`, clang emits 20 instead of 24 as the offset for `IntermediateClass2Property` as the class layout for `SuperClass2`, which is created when the implementation of IntermediateClass3 is parsed, is outdated when the implementation of `IntermediateClass2` is parsed. This commit invalidates the stale layout information of the class and its subclasses if new ivars are added to the interface. With this change, we can also stop using ObjC implementation decls as the key to retrieve ObjC class layouts information as the layout retrieved using the ObjC interface as the key will always be up to date. rdar://139531391
2025-01-29[IR] Convert from nocapture to captures(none) (#123181)Nikita Popov1-13/+13
This PR removes the old `nocapture` attribute, replacing it with the new `captures` attribute introduced in #116990. This change is intended to be essentially NFC, replacing existing uses of `nocapture` with `captures(none)` without adding any new analysis capabilities. Making use of non-`none` values is left for a followup. Some notes: * `nocapture` will be upgraded to `captures(none)` by the bitcode reader. * `nocapture` will also be upgraded by the textual IR reader. This is to make it easier to use old IR files and somewhat reduce the test churn in this PR. * Helper APIs like `doesNotCapture()` will check for `captures(none)`. * MLIR import will convert `captures(none)` into an `llvm.nocapture` attribute. The representation in the LLVM IR dialect should be updated separately.
2025-01-18[Clang] [NFC] Fix unintended `-Wreturn-type` warnings everywhere in the test ↵Sirraide11-12/+15
suite (#123464) In preparation of making `-Wreturn-type` default to an error (as there is virtually no situation where you’d *want* to fall off the end of a function that is supposed to return a value), this patch fixes tests that have relied on this being only a warning, of which there seem to be 3 kinds: 1. Tests which for no apparent reason have a function that triggers the warning. I suspect that a lot of these were on accident (or from before the warning was introduced), since a lot of people will open issues w/ their problematic code in the `main` function (which is the one case where you don’t need to return from a non-void function, after all...), which someone will then copy, possibly into a namespace, possibly renaming it, the end result of that being that you end up w/ something that definitely is not `main` anymore, but which still is declared as returning `int`, and which still has no return statement (another reason why I think this might apply to a lot of these is because usually the actual return type of such problematic functions is quite literally `int`). A lot of these are really old tests that don’t use `-verify`, which is why no-one noticed or had to care about the extra warning that was already being emitted by them until now. 2. Tests which test either `-Wreturn-type`, `[[noreturn]]`, or what codegen and sanitisers do whenever you do fall off the end of a function. 3. Tests where I struggle to figure out what is even being tested (usually because they’re Objective-C tests, and I don’t know Objective-C), whether falling off the end of a function matters in the first place, and tests where actually spelling out an expression to return would be rather cumbersome (e.g. matrix types currently don’t support list initialisation, so I can’t write e.g. `return {}`). For tests that fall into categories 2 and 3, I just added `-Wno-error=return-type` to the `RUN` lines and called it a day. This was especially necessary for the former since `-Wreturn-type` is an analysis-based warning, meaning that it is currently impossible to test for more than one occurrence of it in the same compilation if it defaults to an error since the analysis pass is skipped for subsequent functions as soon as an error is emitted. I’ve also added `-Werror=return-type` to a few tests that I had already updated as this patch was previously already making the warning an error by default, but we’ve decided to split that into two patches instead.
2024-12-10[Clang] Change two placeholders from `undef` to `poison` [NFC] (#119141)Pedro Lobo1-1/+1
- Use `poison` instead of `undef` as a phi operand for an unreachable path (the predecessor will not go the BB that uses the value of the phi). - Call `@llvm.vector.insert` with a `poison` subvec when performing a `bitcast` from a fixed vector to a scalable vector.
2024-10-17[CLANG]Add Scalable vectors for mfloat8_t (#101644)CarolineConcatto1-0/+3
This patch adds these new vector sizes for sve: svmfloat8_t According to the ARM ACLE PR#323[1]. [1] ARM-software/acle#323
2024-10-14Reapply "[clang][CodeGen] Zero init unspecified fields in initializers in C" ↵yabinc1-1/+1
(#109898) (#110051) This reverts commit d50eaac12f0cdfe27e942290942b06889ab12a8c. Also fixes a bug calculating offsets for bit fields in the original patch.
2024-09-24Revert "[clang][CodeGen] Zero init unspecified fields in initializers in C" ↵Eli Friedman1-1/+1
(#109898) Reverts llvm/llvm-project#97121 Causing failures on LNT bots; log shows a crash in ConstStructBuilder::BuildStruct.
2024-09-24[clang][CodeGen] Zero init unspecified fields in initializers in C (#97121)yabinc1-1/+1
When an initializer is provided to a variable, the Linux kernel relied on the compiler to zero-initialize unspecified fields, as clarified in https://www.spinics.net/lists/netdev/msg1007244.html. But clang doesn't guarantee this: 1. For a union type, if an empty initializer is given, clang only initializes bytes for the first field, left bytes for other (larger) fields are marked as undef. Accessing those undef bytes can lead to undefined behaviors. 2. For a union type, if an initializer explicitly sets a field, left bytes for other (larger) fields are marked as undef. 3. When an initializer is given, clang doesn't zero initialize padding. So this patch makes the following change: 1. In C, when an initializer is provided for a variable, zero-initialize undef and padding fields in the initializer. 2. Document the change in LanguageExtensions.rst. As suggested in https://github.com/llvm/llvm-project/issues/78034#issuecomment-2183437928, the change isn't required by C23, but it's standards conforming to do so. Fixes: https://github.com/llvm/llvm-project/issues/97459
2024-09-12[clang][bytecode] Add support for creating dummies for expressions (#108394)Timm Baeder1-0/+1
And use that to fix VisitObjCBoxedExprs.
2024-09-11Set dllimport on Objective C ivar offsets (#107604)Frederik Carlier1-2/+2
Ensures that offsets for instance variables are marked with `dllimport` if the interface to which they belong has this attribute.
2024-08-12[Sanitizer] Make sanitizer passes idempotent (#99439)Chaitanya1-1/+1
This PR changes the sanitizer passes to be idempotent. When any sanitizer pass is run after it has already been run before, double instrumentation is seen in the resulting IR. This happens because there is no check in the pass, to verify if IR has been instrumented before. This PR checks if "nosanitize_*" module flag is already present and if true, return early without running the pass again.
2024-08-09[IRBuilder] Generate nuw GEPs for struct member accesses (#99538)Hari Limaye21-118/+118
Generate nuw GEPs for struct member accesses, as inbounds + non-negative implies nuw. Regression tests are updated using update scripts where possible, and by find + replace where not.
2024-08-05[Clang] Fix path-sensitivity in ubsan-bool.m test (NFC)Nikita Popov1-6/+6
This test was failing whenever the path contained the string "f1", e.g. as part of a commit hash. Double-fix the issue by both not embedding the path in the IR at all, and making the CHECK-LABELs more specific.
2024-07-11[ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (#94885)AtariDreams1-2/+2
When accessing data in the buffer, we know we won't overrun the buffer, so we know it is inbounds. In addition, we know that the addition to increase the index is also NUW because the buffer's end has to be unsigned-greater-than 0, which becomes untrue if the bounds ever has an unsigned wrap.
2024-07-09[CodeGen] Add a flag to disable emitting block signature strings (#96944)Akira Hatanaka1-2/+9
Users who don't need the signature string to be emitted can use the flag to reduce code size. rdar://121933818
2024-06-14 [RemoveDIs] Print IR with debug records by default (#91724)Stephen Tozer4-9/+9
This patch makes the final major change of the RemoveDIs project, changing the default IR output from debug intrinsics to debug records. This is expected to break a large number of tests: every single one that tests for uses or declarations of debug intrinsics and does not explicitly disable writing records. If this patch has broken your downstream tests (or upstream tests on a configuration I wasn't able to run): 1. If you need to immediately unblock a build, pass `--write-experimental-debuginfo=false` to LLVM's option processing for all failing tests (remember to use `-mllvm` for clang/flang to forward arguments to LLVM). 2. For most test failures, the changes are trivial and mechanical, enough that they can be done by script; see the migration guide for a guide on how to do this: https://llvm.org/docs/RemoveDIsDebugInfo.html#test-updates 3. If any tests fail for reasons other than FileCheck check lines that need updating, such as assertion failures, that is most likely a real bug with this patch and should be reported as such. For more information, see the recent PSA: https://discourse.llvm.org/t/psa-ir-output-changing-from-debug-intrinsics-to-debug-records/79578
2024-06-11[clang][Interp] Support ObjCEncodeExprsTimm Bäder1-0/+1
2024-06-10[CodeGen] Simplify codegen for array initialization (#93956)Nikita Popov2-9/+6
This makes codegen for array initialization simpler in two ways: 1. Drop the zero-index GEP at the start, which is no longer needed with opaque pointers. 2. Emit GEPs directly to the correct element, instead of having a long chain of +1 GEPs. This is more canonical, and also avoids regressions in unoptimized builds from #93823.
2024-05-04[test] %clang_cc1: remove redundant actionsFangrui Song1-1/+1
2024-05-04[test] %clang_cc1 -emit-llvm: remove redundant -SFangrui Song21-66/+66
And replace -emit-llvm -o - with -emit-llvm-only
2024-05-03[clang,test] Convert text files from CRLF to LFFangrui Song1-53/+53
Skip files with intentional CRLF line endings.
2024-04-29Re-apply "Emit missing cleanups for stmt-expr" and other commits (#89154)Utkarsh Saxena2-7/+12
Latest diff: https://github.com/llvm/llvm-project/pull/89154/files/f1ab4c2677394bbfc985d9680d5eecd7b2e6a882..adf9bc902baddb156c83ce0f8ec03c142e806d45 We address two additional bugs here: ### Problem 1: Deactivated normal cleanup still runs, leading to double-free Consider the following: ```cpp struct A { }; struct B { B(const A&); }; struct S { A a; B b; }; int AcceptS(S s); void Accept2(int x, int y); void Test() { Accept2(AcceptS({.a = A{}, .b = A{}}), ({ return; 0; })); } ``` We add cleanups as follows: 1. push dtor for field `S::a` 2. push dtor for temp `A{}` (used by ` B(const A&)` in `.b = A{}`) 3. push dtor for field `S::b` 4. Deactivate 3 `S::b`-> This pops the cleanup. 5. Deactivate 1 `S::a` -> Does not pop the cleanup as *2* is top. Should create _active flag_!! 6. push dtor for `~S()`. 7. ... It is important to deactivate **5** using active flags. Without the active flags, the `return` will fallthrough it and would run both `~S()` and dtor `S::a` leading to **double free** of `~A()`. In this patch, we unconditionally emit active flags while deactivating normal cleanups. These flags are deleted later by the `AllocaTracker` if the cleanup is not emitted. ### Problem 2: Missing cleanup for conditional lifetime extension We push 2 cleanups for lifetime-extended cleanup. The first cleanup is useful if we exit from the middle of the expression (stmt-expr/coro suspensions). This is deactivated after full-expr, and a new cleanup is pushed, extending the lifetime of the temporaries (to the scope of the reference being initialized). If this lifetime extension happens to be conditional, then we use active flags to remember whether the branch was taken and if the object was initialized. Previously, we used a **single** active flag, which was used by both cleanups. This is wrong because the first cleanup will be forced to deactivate after the full-expr and therefore this **active** flag will always be **inactive**. The dtor for the lifetime extended entity would not run as it always sees an **inactive** flag. In this patch, we solve this using two separate active flags for both cleanups. Both of them are activated if the conditional branch is taken, but only one of them is deactivated after the full-expr. --- Fixes https://github.com/llvm/llvm-project/issues/63818 Fixes https://github.com/llvm/llvm-project/issues/88478 --- Previous PR logs: 1. https://github.com/llvm/llvm-project/pull/85398 2. https://github.com/llvm/llvm-project/pull/88670 3. https://github.com/llvm/llvm-project/pull/88751 4. https://github.com/llvm/llvm-project/pull/88884
2024-03-18[RemoveDIs] Update Clang front end to handle DbgRecords (#84756)Orlando Cazalet-Hyams1-1/+1
This patch fixes problems that pop up when clang emits DbgRecords instead of debug intrinsics. Note: this doesn't mean clang is emitting DbgRecords yet, because the modules it creates are still always in the old debug mode. That will come in a future patch. Depends on #84739
2024-03-18Revert "[RemoveDIs] Update Clang front end to handle DbgRecords (#84756)"Orlando Cazalet-Hyams1-1/+1
This reverts commit 6f60ad7e9a3508f19d54c827cf11f7930a0685ee. Buildbots: https://lab.llvm.org/buildbot/#/builders/196/builds/47206
2024-03-18[RemoveDIs] Update Clang front end to handle DbgRecords (#84756)Orlando Cazalet-Hyams1-1/+1
This patch fixes problems that pop up when clang emits DbgRecords instead of debug intrinsics. Note: this doesn't mean clang is emitting DbgRecords yet, because the modules it creates are still always in the old debug mode. That will come in a future patch. Depends on #84739
2024-03-05[ObjC] Check entire chain of superclasses to see if class layout is ↵AtariDreams1-0/+102
statically known (#81335) As of now, we only check if a class directly inherits from NSObject to determine if said class has fixed offsets and can therefore "opt-out" from the non-fragile ABI for ivars. However, if an NSObject subclass has fixed offsets, then so must the subclasses of that subclass, so this allows us to optimize instances of subclasses of subclasses that inherit from NSObject and so on. To determine this, we need to find that the compiler can see the implementation of each intermediate class, as that means it is statically linked. Fixes: #81369
2024-01-24[InstCombine] Canonicalize constant GEPs to i8 source element type (#68882)Nikita Popov1-2/+2
This patch canonicalizes getelementptr instructions with constant indices to use the `i8` source element type. This makes it easier for optimizations to recognize that two GEPs are identical, because they don't need to see past many different ways to express the same offset. This is a first step towards https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699. This is limited to constant GEPs only for now, as they have a clear canonical form, while we're not yet sure how exactly to deal with variable indices. The test llvm/test/Transforms/PhaseOrdering/switch_with_geps.ll gives two representative examples of the kind of optimization improvement we expect from this change. In the first test SimplifyCFG can now realize that all switch branches are actually the same. In the second test it can convert it into simple arithmetic. These are representative of common optimization failures we see in Rust. Fixes https://github.com/llvm/llvm-project/issues/69841.
2024-01-22Enable direct methods and fast alloc calls for libobjc2. (#78030)David Chisnall1-0/+37
These will be supported in the upcoming 2.2 release and so are gated on that version. Direct methods call `objc_send_initialize` if they are class methods that may not have called initialize. This is guarded by checking for the class flag bit that is set on initialisation in the class. This bit now forms part of the ABI, but it's been stable for 30+ years so that's fine as a contract going forwards.
2024-01-12[ObjC]: Make type encoding safe in symbol names (#77797)Frederik Carlier2-18/+42
Type encodings are part of symbol names in the Objective C ABI. Replace characters which are reseved in symbol names: - ELF: avoid including '@' characters in type encodings - Windows: avoid including '=' characters in type encodings
2024-01-11[Clang] Set writable and dead_on_unwind attributes on sret arguments (#77116)Nikita Popov8-16/+16
Set the writable and dead_on_unwind attributes for sret arguments. These indicate that the argument points to writable memory (and it's legal to introduce spurious writes to it on entry to the function) and that the argument memory will not be used if the call unwinds. This enables additional MemCpyOpt/DSE/LICM optimizations.
2024-01-10Objective C: use C++ exceptions on MinGW+GNUstep (#77255)Frederik Carlier2-2/+56
The GNUstep Objective C runtime (libobjc2) is adding support for the GNU ABI on Windows (more specifically, MinGW). The libobjc2 runtime uses C++ exceptions in that configuration; this PR updates clang to act accordingly. The corresponding change to libobjc2 is here: https://github.com/gnustep/libobjc2/pull/267
2024-01-09Set dllstorage on ObjectiveC ivar offsets (#77385)Frederik Carlier1-0/+29
Mark instance variable offset symbols with `dllexport`/`dllimport` if they are not hidden and the interface declaration is marked with `dllexport`/`dllimport`, when using the GNUstep 2.x ABI. /cc @davidchisnall
2024-01-03ObjcRuntime.h: Add mips64, aarch64, and riscv64 to non-legacy dispatch (#76694)Hugo Melder1-1/+2
This PR updates the list of architectures for which libobjc2 has fast-path objc_msgSend implementations. Related to: https://github.com/gnustep/libobjc2/pull/261
2023-11-06Reland "[Intrinsics][ObjC] Mark objc_retain and friends as thisreturn."Jon Roelofs2-8/+13
This reverts commit cb62f67088aaf79493350547f74870318b71acc5. Fixes: https://github.com/llvm/llvm-project/issues/69658
2023-11-06Revert "Reland "[Intrinsics][ObjC] Mark objc_retain and friends as thisreturn.""Jon Roelofs2-15/+10
This reverts commit 30414fc614d80a45bad4c89763a353f50d3e04d6. Broke some buildbots.
2023-11-06Reland "[Intrinsics][ObjC] Mark objc_retain and friends as thisreturn."Jon Roelofs2-10/+15
This reverts commit cb62f67088aaf79493350547f74870318b71acc5. Fixes: https://github.com/llvm/llvm-project/issues/69658
2023-10-24[CXXNameMangler] Correct the mangling of SVE ACLE types within function ↵Paul Walker1-2/+2
names. (#69460) * Mark SVE ACLE types as substitution candidates. * Change mangling of svbfloat16_t from __SVBFloat16_t to __SVBfloat16_t. https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst This is an ABI break with the old behaviour available via "-fclang-abi-compat=17".
2023-10-20Revert "[Intrinsics][ObjC] Mark objc_retain and friends as thisreturn."Jon Roelofs2-15/+10
This reverts commit ed83797f3cbfc8fb2a1af63542f97d7ec1d5505a. Reverting pending the investigation of https://github.com/llvm/llvm-project/issues/69658
2023-09-26[Clang][ObjC] Add optionality to property attribute strings. (#66507)Alastair Houghton1-1/+9
Add a new attribute, "?", to the property attribute string for properties of protocols that are declared @optional. (Previously https://reviews.llvm.org/D135273) rdar://100463524