1400 Commits

Author SHA1 Message Date
hjagasiaAMD
a76750e6de
Revert "[SimplifyCFG] Extend jump-threading to allow live local defs … (#190269)
…(#135079)"

This reverts commit a757f23404c594f4a48b4ddb6625f88b349d11d5. Commit
causes reduce.cu file in hipcub/warp go from 2 minutes of compilation to
taking several hours.
2026-04-02 23:05:26 +00:00
Fady Farag
6ddb2be00a
[clang][test] Add missing FileCheck pipe in constant-string-class-1.m (#189514)
The test had a CHECK directive that was never executed because the RUN
line did not pipe output to FileCheck.
2026-03-31 07:42:05 -04:00
Peter Rong
3e2f0bce95
[ObjCDirectPreconditionThunk] precondition check thunk generation (#170618)
## TL;DR

This is a stack of PRs implementing features to expose direct methods
ABI.
You can see the RFC, design, and discussion
[here](https://discourse.llvm.org/t/rfc-optimizing-code-size-of-objc-direct-by-exposing-function-symbols-and-moving-nil-checks-to-thunks/88866).

https://github.com/llvm/llvm-project/pull/170616 Flag
`-fobjc-direct-precondition-thunk` set up
https://github.com/llvm/llvm-project/pull/170617 Code refactoring to
ease later reviews
https://github.com/llvm/llvm-project/pull/170618 **Thunk generation**
https://github.com/llvm/llvm-project/pull/170619 Optimizations, some
class objects can be known to be realized

## Implementation details

### Dispatching
- `GetDirectMethodCallee` handles the dispatching logic. Previously we
only need to call `GenerateDirectMethod` to get the declaration of a
direct method.
- `GenerateDirectMethod` first attempts to acquire the declaration of
the implementation, and return it if the flag is not set.
- Generate and return thunk if we can't dispatch to true implementation
(i.e. we can't reason receiver is def not null or class object is not
realized)

### Precondition check thunk generation

- `GenerateObjCDirectThunk` generates the thunk, it is called on demand
by `GetDirectMethodCallee`
- Thunk inherits all attributes from the true implementation, see
`StartObjCDirectThunk` for more detail.
- `StartObjCDirectThunk` and `FinishObjCDirectThunk` follows the design
pattern of `StartThunk` and `FinishThunk` in CGVTable.

### Precondition check inline generation

- If the function need to have precondition check inlined
(`shouldHaveNilCheckInline`), caller will emit the nil check during
`EmitMessageSend`
- Class realization is generated inline
- No extra nil check is generated - we reuse `NullReturnState` to emit
the nil check for us, it already emits nil check at caller side to
handle `ns_consumed`, we just need to tell `NullReturnState` to do the
work by setting the flag `RequiresNullCheck |= ReceiverCanBeNull;`

### Visibility and linkage

- Visibility is still by default `Hidden`. But `StartObjCMethod` will
now respect source level visibility attributes so methods with
`__attribute((visibility("default"))` can be used in other linking units
- Linkage is by default `External`

## Tests

- `expose-direct-method.m` follow the example of `direct-method.m`
- `direct-method-ret-mismatch.m` make sure we can handle the corner case
- `expose-direct-method-consumed.m ` and
`expose-direct-method-linkedlist.m` executable test on Mac only to
validate ARC correctness
- `expose-direct-method-varargs.m`
- `expose-direct-method-visibility-linkage.m`
2026-03-30 10:32:09 -07:00
Timm Baeder
cb8b65e320
[clang][bytecode] Add support for objc array- and dictionary literals (#189058) 2026-03-28 05:52:23 +01:00
Akira Hatanaka
154d2267b8
[ObjC] Emit number, array, and dictionary literals as constants (#185130)
When targeting runtimes that support constant literal classes, emit ObjC
literal expressions @(number), @[], and @{} as compile-time constant
data structures rather than runtime msgSend calls. This reduces code
size and runtime overhead at the cost of increased data segment size,
and avoids repeated heap allocation of equivalent literal objects.

The feature is not supported with the fragile ABI or GNU runtimes, where
it is automatically disabled.

The feature can be disabled altogether with -fno-objc-constant-literals,
or individually per literal kind:
  -fno-constant-nsnumber-literals
  -fno-constant-nsarray-literals
  -fno-constant-nsdictionary-literals

Custom backing class names can be specified via:
  -fconstant-array-class=<name>
  -fconstant-dictionary-class=<name>
  -fconstant-integer-number-class=<name>
  -fconstant-float-number-class=<name>
  -fconstant-double-number-class=<name>

rdar://45380392
rdar://168106035

---------

Co-authored-by: Ben D. Jones <bendjones@apple.com>
2026-03-25 15:03:14 -07:00
Akira Hatanaka
186dd22e5a
[ObjC] Emit class msgSend stub calls (#186433)
Instead of translating class messages to `objc_msgSend` calls, clang now
emits calls to stub functions that are synthesized by the linker. Each
stub loads the class reference and the selector name and forwards them
to `objc_msgSend`.

The stub function is named using the following format:
`objc_msgSendClass$selName$_OBJC_CLASS_$_className`

Note that the optimization is disabled in the following cases:

- When the class name is unknown at compile time (e.g,
  `[idclassMethod]`).
- The selector name contains a `$`, which serves as the delimiter in
  stub function names.
- The class is annotated with either `objc_class_stub` or
  `objc_runtime_visible`.

In such cases, clang reverts to the existing message send optimization,
where each stub loads only the selector name.

Also add class objects to llvm.used when class msgSend optimization is
enabled. This is needed as the linker currently cannot generate the
stub, which references the class object, if LTO internalizes the global
variable for the class object.

This reapplies 077991463253, which was reverted because it broke
offload-Xarch.c and openmp-offload-gpu.c. 14e04edf0725 prevents the
assertion from failing.

rdar://147604613
2026-03-13 09:48:47 -07:00
Akira Hatanaka
5cffcc547d
[ObjC] Support emission of selector stubs calls instead of objc_msgSend. (#186293)
This optimizes objc_msgSend calls by emitting "selector stubs" instead.

Usually, the linker redirects calls to external symbols to a symbol stub
it generates, which loads the target function's address from the GOT and
branches to it:

  <symbol stub for _func:>
    adrp x16, _func@GOTPAGE
    ldr x16, [x16, _func@GOTPAGEOFF]
    br x16

with msgSend selector stubs, we extend that to compute the selector as
well:

  <selector stub for "foo":>
    adrp x1, <selector ref for "foo">@PAGE
    ldr x1, [x1, <selector ref for "foo">@PAGEOFF]
    adrp x16, _objc_msgSend@GOTPAGE
    ldr x16, [x16, _objc_msgSend@GOTPAGEOFF]
    br x16

This lets us avoid loading the selector in the compiler, hopefully
leading to codesize reductions.

We're considering two kinds of stubs, the combined one above with the
objc_msgSend dispatch included, or a shorter one that forwards to the
existing stub for objc_msgSend. That's a decision to be made in the
linker.

Concretely, instead of something like:

  %sel = load i8*, i8** @<selector ref for "foo">
  call ... @objc_msgSend(i8* self, i8* sel)

we emit a call to a newly-declared external "function":

  call ... @"objc_msgSend$foo"(i8* self, i8* undef)

where "objc_msgSend$foo" is treated as any other external symbol
reference throughout the compiler, and, at link-time, is recognized by
the linker as a selector stub.

There are other ways to implement this. An obvious one is to combine
away the objc_msgSend(self, load(sel)) pattern at the IR level.

Both seem feasible, but the IRGen approach might save us a tiny bit of
compile-time, with the assumption that loads need more mid-level
analysis than boring external functions.

This optimization requires linker version 811.2 or newer for arm64,
arm64e, and arm64_32.

This reapplies 6758becb8f19, which was reverted because it broke
offload-Xarch.c and openmp-offload-gpu.c. 14e04edf0725 prevents the
assertion from failing.

rdar://84437635

Co-authored-by: Ahmed Bougacha <ahmed@bougacha.org>
2026-03-13 09:02:39 -07:00
Douglas Yung
fc5e9bfb54 Revert "[ObjC] Support emission of selector stubs calls instead of objc_msgSend. (#183922)"
This reverts commit 6758becb8f19593f5341b2e4d575dbf411ad706e.

This change was causing 2 test failures on a build bot https://lab.llvm.org/buildbot/#/builders/190/builds/38293.
2026-03-12 02:15:46 -07:00
Douglas Yung
5025166f52 Revert "[ObjC] Emit class msgSend stub calls (#183923)"
This reverts commit 077991463253b9295f291d4e4d2078521e518717.

Need to revert this follow up commit to 6758becb8f19593f5341b2e4d575dbf411ad706e
in order to revert an earlier commit which caused 2 test failures on a bot.
2026-03-12 02:15:46 -07:00
Akira Hatanaka
0779914632
[ObjC] Emit class msgSend stub calls (#183923)
Instead of translating class messages to `objc_msgSend` calls, clang now
emits calls to stub functions that are synthesized by the linker. Each
stub loads the class reference and the selector name and forwards them
to `objc_msgSend`.

The stub function is named using the following format:
`objc_msgSendClass$selName$_OBJC_CLASS_$_className`

Note that the optimization is disabled in the following cases:
- When the class name is unknown at compile time (e.g, `[id
classMethod]`).
- The selector name contains a `$`, which serves as the delimiter in
stub
   function names.
- The class is annotated with either `objc_class_stub` or
  `objc_runtime_visible`.

In such cases, clang reverts to the existing message send optimization,
where each stub loads only the selector name.

Also add class objects to llvm.used when class msgSend optimization is
enabled. This is needed as the linker currently cannot generate the
stub,
which references the class object, if LTO internalizes the global
variable
for the class object.

rdar://147604613

---------

Co-authored-by: Ahmed Bougacha <ahmed@bougacha.org>
2026-03-11 15:21:50 -07:00
Akira Hatanaka
6758becb8f
[ObjC] Support emission of selector stubs calls instead of objc_msgSend. (#183922)
This optimizes objc_msgSend calls by emitting "selector stubs" instead.

Usually, the linker redirects calls to external symbols to a symbol stub
it generates, which loads the target function's address from the GOT and
branches to it:

  <symbol stub for _func:>
    adrp x16, _func@GOTPAGE
    ldr x16, [x16, _func@GOTPAGEOFF]
    br x16

with msgSend selector stubs, we extend that to compute the selector as
well:

  <selector stub for "foo":>
    adrp x1, <selector ref for "foo">@PAGE
    ldr x1, [x1, <selector ref for "foo">@PAGEOFF]
    adrp x16, _objc_msgSend@GOTPAGE
    ldr x16, [x16, _objc_msgSend@GOTPAGEOFF]
    br x16

This lets us avoid loading the selector in the compiler, hopefully
leading to codesize reductions.

We're considering two kinds of stubs, the combined one above with the
objc_msgSend dispatch included, or a shorter one that forwards to the
existing stub for objc_msgSend. That's a decision to be made in the
linker.

Concretely, instead of something like:

  %sel = load i8*, i8** @<selector ref for "foo">
  call ... @objc_msgSend(i8* self, i8* sel)

we emit a call to a newly-declared external "function":

  call ... @"objc_msgSend$foo"(i8* self, i8* undef)

where "objc_msgSend$foo" is treated as any other external symbol
reference throughout the compiler, and, at link-time, is recognized by
the linker as a selector stub.

There are other ways to implement this. An obvious one is to combine
away the objc_msgSend(self, load(sel)) pattern at the IR level.

Both seem feasible, but the IRGen approach might save us a tiny bit of
compile-time, with the assumption that loads need more mid-level
analysis than boring external functions.

This optimization requires linker version 811.2 or newer for arm64,
arm64e, and arm64_32.

rdar://84437635
2026-03-11 13:21:11 -07:00
Nikita Popov
b3d99ac2cd
[CodeGen] Use data layout aware constant folder in CGBuilder (#184819)
Use the DataLayout-aware TargetFolder instead of ConstantFolder in
Clang's CGBuilder. The primary impact of this change is that GEP
constant expressions are now emitted in canonical `getelementptr i8`
form. This is in preparation for the migration to ptradd, which requires
this form.

Part of the test updates were performed by Claude Code and reviewed by
me.
2026-03-06 08:33:34 +00:00
Dave Bartolomeo
ae79165399
[clang][NFC][diagnostics] Remove several uses of getCustomDiagID() (#172532)
This change converts all existing uses of `getCustomDiagID()` within the
`clang/AST` library into regular diagnostics defined in
`DiagnosticASTKinds.td`.

This is mostly just cleanup, but it will also help with future changes
to the diagnostic system by letting us focus on the custom diagnostic
scenarios that _don't_ fit into the usual pre-declared diagnostic
scenario.
2026-03-01 16:25:23 +00:00
Damian Malarczyk
ba294608be
Move the ObjC blocks layout bitmap to the cstring section (#182398)
This is a follow-up to https://github.com/llvm/llvm-project/pull/174705

There's one additional place in the ObjC code gen logic to make sure the
ObjC blocks layout is generated in the regular cstring section.
2026-02-23 10:44:09 -08:00
Sam Elliott
df1eec77b5
[clang] Ensure -mno-outline adds attributes (#163692)
Before this change, `-mno-outline` and `-moutline` only controlled the
pass pipelines for the invoked compiler/linker.

The drawback of this implementation is that, when using LTO, only the
flag provided to the linker invocation is honoured (and any files which
individually use `-mno-outline` will have that flag ignored).

This change serialises the `-mno-outline` flag into each function's
IR/Bitcode, so that we can correctly disable outlining from functions in
files which disabled outlining, without affecting outlining choices for
functions from other files. This matches how other optimisation flags
are handled so the IR/Bitcode can be correctly merged during LTO.
2026-02-18 10:16:31 -08:00
Alex Bradbury
c9fa7424c7
[clang][test] Set triple explicitly for attr-no-outline.m test (#181621)
The test fails on targets that have a different LLVM IR lowering (e.g.
RISC-V which produces `signext i32` for the return type). Rather than
complicate the test with more complex patterns, just set the triple
explicitly to x86-64 (as various other generic clang/test/CodeGen* tests
do).

Test was introduced by #163666.

This fixes RISC-V CI.
2026-02-16 10:09:32 +00:00
Sam Elliott
d2be26a9f2
[clang] Add clang::no_outline Attribute (#163666)
This change:

- Adds a `[[clang::no_outline]]` function attribute for C and C++. There
is no equivalent GNU syntax for this attribute, so no `__attribute__`
syntax.
- Uses the presence of `[[clang::no_outline]]` to add the `nooutline`
attribute to IR function definitions.
- Adds test for the above.

The `nooutline` attribute disables both the Machine Outliner (enabled at
Oz for some targets), and the IR Outliner (disabled by default).

Fixes #144135
2026-02-13 18:29:22 -08:00
John Hui
b791501e80
Revert "Reapply "[CGObjC] Allow clang.arc.attachedcall on -O0 (#164875)" (#177285)" (#177533)
This reverts commit 4b939beb79e3390046b760bef71b7d891ba9b4df.

This commit seems to be causing these test failures:

- ThreadSanitizer-x86_64-iossim.Darwin.norace-objcxx-run-time.mm
https://ci.swift.org/job/llvm.org/job/clang-san-iossim/14230/testReport/junit/ThreadSanitizer-x86_64-iossim/Darwin/norace_objcxx_run_time_mm/
- ThreadSanitizer-x86_64-iossim.Darwin.objc-synchronize-cycle-tagged.mm
https://ci.swift.org/job/llvm.org/job/clang-san-iossim/14230/testReport/junit/ThreadSanitizer-x86_64-iossim/Darwin/objc_synchronize_cycle_tagged_mm/
- ThreadSanitizer-x86_64-iossim.Darwin.objc-synchronize-tagged.mm
https://ci.swift.org/job/llvm.org/job/clang-san-iossim/14230/testReport/junit/ThreadSanitizer-x86_64-iossim/Darwin/objc_synchronize_tagged_mm/
- ThreadSanitizer-x86_64-iossim.Darwin.objc-synchronize.mm
https://ci.swift.org/job/llvm.org/job/clang-san-iossim/14230/testReport/junit/ThreadSanitizer-x86_64-iossim/Darwin/objc_synchronize_mm/


With the error message:

```
fatal error: error in backend: Cannot select: intrinsic %llvm.objc.clang.arc.noop.use
```
2026-01-23 11:56:31 +01:00
AZero13
4b939beb79
Reapply "[CGObjC] Allow clang.arc.attachedcall on -O0 (#164875)" (#177285)
This reverts commit 8eac375a4bff84f0a10a9c8ee23c4da409a805f9.

A unit test needed to be updated, that was all.

I do not have merge permissions.
2026-01-22 19:31:29 +01:00
Aiden Grossman
8eac375a4b Revert "[CGObjC] Allow clang.arc.attachedcall on -O0 (#164875)"
This reverts commit 5c29b64fda6a5a66e09378eec9f28a42066a7c6a.

This was causing failures at HEAD on x86-64 Linux.
2026-01-21 22:57:06 +00:00
AZero13
5c29b64fda
[CGObjC] Allow clang.arc.attachedcall on -O0 (#164875)
It is supported in GlobalISel there. On X86, we always kick to
SelectionDAG anyway, so there is no point in not doing it for X86 too.

I do not have merge permissions.
2026-01-21 23:41:32 +01:00
Aiden Grossman
e2d7cd685d
[IR] Make dead_on_return attribute optionally sized
This patch makes the dead_on_return parameter attribute optionally require a number
of bytes to be passed in to specify the number of bytes known to be dead
upon function return/unwind. This is aimed at enabling annotating the
this pointer in C++ destructors with dead_on_return in clang. We need
this to handle cases like the following:

```
struct X {
  int n;
  ~X() {
    this[n].n = 0;
  }
};
void f() {
  X xs[] = {42, -1};
}
```

Where we only certain that sizeof(X) bytes are dead upon return of ~X.
Otherwise DSE would be able to eliminate the store in ~X which would not
be correct.

This patch only does the wiring within IR. Future patches will make
clang emit correct sizing information and update DSE to only delete
stores to objects marked dead_on_return that are provably in bounds of
the number of bytes specified to be dead_on_return.

Reviewers: nikic, alinas, antoniofrighetto

Pull Request: https://github.com/llvm/llvm-project/pull/171712
2026-01-21 08:22:05 -08:00
cooperp
c54f1ed3db
Move the ObjC layout bitmap to the cstring section. (#174705)
Currently the layout bitmap is emitted as a "class name" but its not
actually a name at all. This moves the bitmap to the regular cstring
section for now.

In Apple, our linker and other tools try to optimize sections such as
objc strings. As layout bitmaps aren't really strings at all, they block
some optimizations. We don't currently try to optimize sections such as
cstring, which is why that is the section i used here for now.
2026-01-20 10:04:20 -08:00
Akira Hatanaka
9361113ffc
[CodeGen] Remove the check that allowed non-POD compound literals to be directly evaluated into the destination even when it might alias the source (#167344)
Evaluate all aggregate compound literals into a temporary and then copy
it to the destination if aliasing is possible.

This fixes a latent issue exposed by #154490, where evaluating the RHS
directly into the destination could ignore potential aliasing.

rdar://164094548
2025-11-12 13:16:29 -08:00
Sirraide
e4a1b5f36e
[Clang] [C2y] Implement N3355 ‘Named Loops’ (#152870)
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-09-02 16:37:19 +00:00
Michael Buch
8fa55a023b
[clang][DebugInfo][test] Move debug-info tests from CodeGenObjC to DebugInfo 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-21 22:09:34 +01:00
Oliver Hunt
fb14f91305
[clang][Obj-C][PAC] Make block descriptor pointer signing configurable (#153700)
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-14 17:20:27 -07:00
Oliver Hunt
d8850ee6c0
[clang][Obj-C][PAC] Add support for authenticating block metadata (#152978)
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-13 22:01:24 -07:00
Nikita Popov
c23b4fbdbb
[IR] Remove size argument from lifetime intrinsics (#150248)
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-08-08 11:09:34 +02:00
LU-JOHN
a757f23404
[SimplifyCFG] Extend jump-threading to allow live local defs (#135079)
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-31 09:44:14 -04:00
Antonio Frighetto
9e0c06d708 [clang][CodeGen] Set dead_on_return when passing arguments indirectly
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-18 11:50:18 +02:00
Hugo Melder
0b784269f1
[CodeGen][ObjC] Include all referenced protocols in protocol list (#148827)
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-15 13:42:42 +01:00
Oliver Hunt
451a9ce9ff
[clang][ObjC][PAC] Add ptrauth protections to objective-c (#147899)
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-07-14 19:32:18 -07:00
Aaron Ballman
5c8ba28c75
[C11] Implement WG14 N1285 (temporary lifetimes) (#133472)
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-04-10 08:12:14 -04:00
AZero13
6720465c47
[ObjC] Expand isClassLayoutKnownStatically to base classes as long as the 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-03-04 08:34:18 -08:00
Akira Hatanaka
f5c5bc5ed5
[CodeGen][ObjC] Invalidate cached ObjC class layout information after 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-02-17 11:50:44 -08:00
Nikita Popov
29441e4f5f
[IR] Convert from nocapture to captures(none) (#123181)
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-29 16:56:47 +01:00
Sirraide
12f78e740c
[Clang] [NFC] Fix unintended -Wreturn-type warnings everywhere in the test 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.
2025-01-18 19:16:33 +01:00
Pedro Lobo
f28e52274c
[Clang] Change two placeholders from undef to poison [NFC] (#119141)
- 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-12-10 15:57:55 +00:00
CarolineConcatto
cb43021e57
[CLANG]Add Scalable vectors for mfloat8_t (#101644)
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-17 09:22:55 +01:00
yabinc
627746581b
Reapply "[clang][CodeGen] Zero init unspecified fields in initializers in C" (#109898) (#110051)
This reverts commit d50eaac12f0cdfe27e942290942b06889ab12a8c. Also fixes
a bug calculating offsets for bit fields in the original patch.
2024-10-14 16:32:24 -07:00
Eli Friedman
d50eaac12f
Revert "[clang][CodeGen] Zero init unspecified fields in initializers in C" (#109898)
Reverts llvm/llvm-project#97121

Causing failures on LNT bots; log shows a crash in
ConstStructBuilder::BuildStruct.
2024-09-24 20:31:54 -07:00
yabinc
7a086e1b2d
[clang][CodeGen] Zero init unspecified fields in initializers in C (#97121)
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-24 19:06:20 -07:00
Timm Baeder
bd8d432d7b
[clang][bytecode] Add support for creating dummies for expressions (#108394)
And use that to fix VisitObjCBoxedExprs.
2024-09-12 17:25:40 +02:00
Frederik Carlier
7c25ae87f7
Set dllimport on Objective C ivar offsets (#107604)
Ensures that offsets for instance variables are marked with `dllimport`
if the interface to which they belong has this attribute.
2024-09-11 12:38:00 +01:00
Chaitanya
62ced8116b
[Sanitizer] Make sanitizer passes idempotent (#99439)
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-12 11:16:44 +05:30
Hari Limaye
94473f4db6
[IRBuilder] Generate nuw GEPs for struct member accesses (#99538)
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-09 13:25:04 +01:00
Nikita Popov
77011b00ad [Clang] Fix path-sensitivity in ubsan-bool.m test (NFC)
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-08-05 12:56:33 +02:00
AtariDreams
eb61956d1a
[ObjC][CodeGen] Assume a for-in loop is in bounds and cannot overflow (#94885)
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-11 10:21:14 +01:00
Akira Hatanaka
997e5e8703
[CodeGen] Add a flag to disable emitting block signature strings (#96944)
Users who don't need the signature string to be emitted can use the flag
to reduce code size.

rdar://121933818
2024-07-09 07:18:06 -07:00