[AMDGPU] Don't emit .amdgcn_target for each inline asm blob (#234195)
When the integrated assembler is used for textual output, AsmPrinter
parses every inline asm blob with a new AMDGPUAsmParser and calls
Run() on it. Run() invokes onEndOfFile() as if the blob were a complete
file, and that emits the deferred .amdgcn_target directive. Since each
parser tracked on its own whether the directive had been emitted, a
copy was printed after every inline asm statement, in addition to the
one AsmPrinter emits for the module.
Track this on AMDGPUTargetStreamer instead, which AsmPrinter and the
inline asm parsers share, so the directive is emitted at most once per
output file regardless of who gets there first. Assembling with
llvm-mc behaves as before.
This only shows up in textual output with the integrated assembler
enabled, which AMDGPU does not do yet, so there is no test here. Once
it is enabled the existing CodeGen/AMDGPU inline asm tests cover it.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Fix infinite recursion from DFSan reaches function argument callbacks. (#233982)
With `-dfsan-reaches-function-callbacks`, a reaches function callback
that is marked uninstrumented in the ABI list and registered with the
runtime overflows the stack whenever a stale non-zero label sits in
`__dfsan_arg_tls`. The runtime calls the `dfsw$` wrapper, which reads
argument shadows from `__dfsan_arg_tls` and reports them, re-entering
the callback through the runtime before the callback's own reentrancy
guard runs. Nothing clears the stale label, so this repeats until the
stack overflows.
Two defects contribute. Wrappers get argument callbacks even though they
may be called from uninstrumented code, where their argument shadows are
stale. Also, the argument callback instrumentation is inserted before
the visitor runs, so the visitor instruments it again: argument shadow
loads are treated as application loads, and the callback calls as
instrumented calls whose argument shadow stores clobber
`__dfsan_arg_tls`.
Skip argument callbacks in wrappers, and add the inserted instructions
to `SkipInsts`.
[SLP]Keep scalar GEP index for external uses
The power-of-2 external-use heuristic swapped a cheap scalar GEP
index for an extractelement. The extracted index hid the consecutive
accesses from later trees, so they were gathered instead of
vectorized as wide loads.
Assisted-by: Cursor
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/234338
[BoundsSafety][NFC] Add late-parsed type attribute lists to declarators
This is groundwork for late-parsing type attributes in every type
position where an ordinary type attribute can appear. Ordinary type
attributes are kept on the DeclSpec, on each DeclaratorChunk and on the
Declarator. Give late-parsed type attributes the same three homes, with
nothing producing or consuming them yet.
No functional change: no caller passes a list yet, so the lists stay
empty. The next commit populates them.
Assisted-by: Opus 5.5
[mlir][acc] Reduce a complex accumulator componentwise (#234276)
`gpu.all_reduce` accepts only integer and float operands, including in
its
custom-region form. A thread-partitioned `acc.reduction_accumulate` or
`acc.reduction_accumulate_array` with a complex accumulator therefore
produced
IR that failed to verify:
```
error: 'gpu.all_reduce' op operand #0 must be Integer or Float, but got 'complex<f32>'
```
MLIR repro:
```mlir
// repro.mlir
func.func @complex_reduction(%slot: memref<complex<f32>>) {
%c128 = arith.constant 128 : index
[50 lines not shown]
[openmp][mlir] Expand use of atomicrmw for atomic update (#215654)
Use atomicrmw for more OpenMP atomic updates and captures, avoiding cmpxchg loops where possible.
This covers fadd, fsub, fmax, fmin, fmaximum, fminimum and xchg for single and double precision floating-point values, plus signed and unsigned integer min/max.
[ThinLTO] Record whether call edges come from indirect calls in the summary (#233924)
Add a `HasIndirectCall` flag to the summary call edge (`CalleeInfo`),
set by the summary analysis when recording indirect call edges (from
indirect call value profile targets, or from `!callees` metadata on
indirect calls that could not be promoted/devirtualized to direct
calls). If a function calls the same callee both directly and
indirectly, the merged edge is marked indirect.
This will be used by a follow-up MemProf ThinLTO change to distinguish
indirect call edges (which require importing the target at least as a
declaration for indirect call promotion in the backend when assigned to
a cloned cross-module callee) from direct call edges (where the backend
already has or can directly update the declaration).
The flag uses a previously unused bit of the existing `CalleeInfo`
bitfield (no in-memory size change), and is encoded as bit 4 of the
existing per-call-edge hotness/tail call flags operand in the per-module
and combined summaries. The encoded flags value is at most 31, which
[7 lines not shown]
[clang-format] Fix macro expansion crashes and raw string indentation (#233758)
Fix three issues with clang-format's macro expansion
(FormatStyle::Macros):
1. Guard MatchingOpeningBlockLineIndex / MatchingClosingBlockLineIndex
during macro expansion: When a macro expands to a multi-line block (such
as DECL_STRUCT(Name)=struct Name {}),
UnwrappedLineParser::addUnwrappedLine pushes the expanded lines into
CurrentExpandedLines rather than CurrentLines. However, parseBlock() and
parseEnum() still computed OpeningLineIndex from CurrentLines->size() -
1, recording an unrelated or out-of-bounds line index in
MatchingOpeningBlockLineIndex and MatchingClosingBlockLineIndex and
crashing DefinitionBlockSeparator / NamespaceEndCommentsFixer. Only
record block line indices when CurrentExpandedLines is empty and the
closing line is not part of a macro expansion.
2. Annotate and analyze each run immediately in
TokenAnalyzer::finishRun(): FormatToken objects in AllTokens are shared
[26 lines not shown]
[clang-format] Defer line merging to the unexpanded pass (#233944)
Defer line merging to the unexpanded pass when expanding macros.
When Configured Macro Expansion (Style.Macros) is used, clang-format
runs two formatting passes: Run 0 formats the macro-expanded
UnwrappedLines (and finalizes all non-macro-expanded lines and macro
argument tokens), and Run 1 formats the reconstructed unexpanded
UnwrappedLines.
Previously, LineJoiner ran in both Run 0 and Run 1, and Run 0 finalized
the first token of every top-level UnwrappedLine. This caused several
bugs:
1. If a macro expanded to multiple UnwrappedLines whose first line could
merge with a preceding header in Run 0 (e.g. `void f() {
IF_ERROR_RETURN(x); }` where `IF_ERROR_RETURN(x)` expands to `if (x)\n
return x;` with `AllowShortIfStatementsOnASingleLine: Never` and
`AllowShortFunctionsOnASingleLine: All`, or `FN=class C { int f` in
`void f() { FN(a *b); }; }`), Run 0 merged the first expanded line onto
[24 lines not shown]
[CIR][OpenMP] Specify x86 host triple in target-parallel test (#234314)
The host RUN line inherits the compiler default triple even though the
checks describe an x86 host with an AMDGPU offload target. Clang rejects
the incompatible host and device pointer sizes on platforms like ARM32.
Assisted-by: Codex
[CIR] Reject language address spaces in DirectToLLVM pointer conversion (#224239)
Reject unlowered language address spaces in pointer types when bypassing
TargetLowering. Guard pointer-producing lowerings, including generated
patterns, so failed conversions report legalization failures instead of
silently selecting address space zero or constructing invalid LLVM
operations.
Assisted-by: Codex / GPT-6
[BoundsSafety] Create incomplete counted_by types and wire up the refill
Activate late parsing for the counted_by family (counted_by / sized_by and
their _or_null variants) in type-attribute position, under
-fexperimental-late-parse-attributes, on top of the type-attribute handling,
the validation helper and the refill machinery added in the previous commits.
When such an attribute is seen during type construction and its argument
can't be resolved yet, build the CountAttributedType immediately with
getIncompleteCountAttributedType and record it against the enclosing record;
its count expression is filled in at the closing brace via the refill logic.
Because enclosing types refer to the node by pointer, completing it in place
leaves the type chain untouched.
[BoundsSafety][test] Add late-parsed counted_by type-attribute coverage
New tests exercising the late-parse fill-in mechanism:
- Sema/attr-counted-by-weird-type-positions{,-late-parsed}.c: counted_by
in assorted type positions, nested pointers, and rejection cases.
- Sema/attr-bounds-safety-function-ptr-param.c: attributes on
function-pointer-typed members.
- Modules/ and PCH/ bounds-safety-attributed-type-late-parsed: the
resolved type round-trips through serialization.
- Sema/attr-counted-by-late-parsed-regressions.c: guards against the
double-free on a nested-record decl-spec attribute and the null-count
escape on a free-function parameter.
[BoundsSafety] Address review feedback on late-parsed counted_by types
Fixes for late-parsed counted_by-family type attributes:
- A block-pointer member hands its late attributes to the block-pointer chunk
instead of asserting, so Sema rejects them like a non-pointer type.
- Late-parse type attributes only in member declarators. Function-pointer
parameters, type names in `sizeof`, and other abstract declarators nested in a
member are parsed eagerly. They used to be resolved in struct scope, and a
paren that turned out to be a parameter list asserted.
- An unnamed struct hands its attributes to the enclosing record only when it's
declared directly in a record, not when it's in a statement expression.
- In declaration-specifier position, only type attributes are late-parsed.
Declaration attributes such as guarded_by are parsed eagerly again, so they
apply to every declarator.
- Reject an attribute on a function return type in the late path too.
- Complete a node whose argument fails to parse with a RecoveryExpr and mark the
fields invalid, rather than leave a CountAttributedType without a count.
- Report a rejected declaration-specifier attribute once rather than once per
[7 lines not shown]
[BoundsSafety] Don't orphan a shared counted_by node when one declarator nests it
A late-parsed counted_by-family attribute in declaration-specifier position is
shared by every declarator in the declaration, so they share one incomplete
CountAttributedType. When one declarator nests the node, as `*b` does in
`IP __counted_by(n) a, *b;`, it is rejected and the node is marked rejected.
The completion pass then skipped the node for every declarator, so `a` kept a
CountAttributedType without a count and crashed on use in
FieldDecl::findCountedByField.
Make the rejection apply to the declarator only. The parser checks and clears
the mark after each declarator, and doesn't pair a rejected declarator's field
with the attribute. The completion pass skips an attribute with no fields left,
still without parsing its argument.
Assisted-by: Opus 5.5
[BoundsSafety] Reject a second bounds attribute on the same pointer
A pointer with two counted_by-family attributes, as in
`int *__counted_by(n) __sized_by(m) p;`, got one CountAttributedType stacked on
another. Reject the second attribute with
err_counted_by_on_bounds_attributed_type, which names both attributes.
Assisted-by: Opus 5.5
[BoundsSafety] Handle the counted_by family as a type attribute
counted_by / sized_by (and their _or_null variants) were handled as a
declaration-position attribute through handleCountedByAttrField.
Build the type during type construction instead and properly handle as a
type-position attribute. Building the node in type position also allows
the new way of late-parsing for type attributes: creates a type node
in place and fills it in once late parsing is done, which will be
enabled in the follow-up commits.
Assisted-by: Opus 5.5
[BoundsSafety][NFC] Add late-parsed type attribute lists to declarators
This is groundwork for late-parsing type attributes in every type
position where an ordinary type attribute can appear. Ordinary type
attributes are kept on the DeclSpec, on each DeclaratorChunk and on the
Declarator. Give late-parsed type attributes the same three homes, with
nothing producing or consuming them yet:
- Move CachedTokens and LateParsedAttrList earlier in DeclSpec.h so
that DeclSpec, Declarator and DeclaratorChunk can hold one. Add
LateParsedAttrList::forTypeAttrs() to create those lists.
- Give DeclSpec, Declarator and DeclaratorChunk a LateParsedAttrList,
and let Declarator::AddTypeInfo carry one onto the chunk it appends.
- Give ParseSpecifierQualifierList and ParseTypeQualifierListOpt an
optional LateParsedAttrList parameter. The former passes it to
ParseDeclarationSpecifiers, the latter to ParseGNUAttributes.
No functional change: no caller passes a list yet, so the lists stay
empty. The next commit populates them.
[BoundsSafety][NFC] Build an incomplete CountAttributedType for a late-parsed attribute (#224558)
This is part of supporting late parsing of counted_by as a type
attribute, following the direction set in
https://github.com/llvm/llvm-project/pull/223267, which allows a
CountAttributedType's count to be filled in later.
Add Sema::ProcessLateParsedTypeAttr. It validates a late-parsed
counted_by-family attribute in type position and wraps the type in a
CountAttributedType whose count is filled in once the enclosing record
is complete.
LateParsedTypeAttribute is owned by the Parser, which Sema cannot depend
on. Sema therefore reads the attribute's kind, location and type slot
through a callback.
No functional change: nothing creates late-parsed type attributes yet,
so ProcessLateParsedTypeAttr is never invoked. The next commit wires it
up.
Assisted-by: Opus 5.5
[LegacyPM] Remove addPostFastRegAllocRewrite hook (#234298)
The NewPM doesn't use this given it's only on x86 and easy to implement
with existing hooks. Match the NewPM for consistency.