[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.
18475 in.ndpd could compute timeouts with a monotonic timer
Reviewed by: Trey Aspelund <t.k.aspelund at gmail.com>
Reviewed by: Kyle Simpson <kyle at oxide.computer>
Reviewed by: Andy Fiddaman <illumos at fiddaman.net>
Reviewed by: Toomas Soome <tsoome at me.com>
Approved by: Gordon Ross <gordon.w.ross at gmail.com>
[flang][OpenMP] Handle sections in target clause extraction (#232084)
Parallel sections nested in target left beginClauseList null and tripped
an assertion. Add OpenMPSectionsConstruct to the handled constructs.
Fixes #227190
Assisted-by: Copilot
Fix edge case defects and add test coverage
Disallow promotion to no-loop for kernels with non-contant or false
conditional clause that affects teams or thread number.
Add guard for 0 trip count for empty loops on host-compile and accept
oversubscription flags there so it applies, so that no-loop kernels are
correctly sized from the count and no longer result in large grid sizing
for zero extended negative iteration counts.
Add guard to write keep-alive list only on per module finalize, matching
offload entry per-module write, to avoid multiple lists with different
names, of which only the first protects its entries, leaving clang's own
list unprotected.
[clang][OpenMP] Add no-loop SPMD kernel promotion
A target teams distribute parallel for that is guaranteed a thread for
every iteration does not need the loop around its body. Flang already
drops it and runs the region as a no-loop kernel.
Enable the same optimization for Clang through mirroring Flang's MLIR
promotion using OpenMPIRBuilder. The kernel is tagged SPMD_NO_LOOP, so
the runtime sizes the grid to the iteration space, and the body is
emitted without a loop around it. The canonical loop it consumes is
reconstructed in the no-loop branch rather than taken from an
OMPCanonicalLoop node, so the promotion does not require
-fopenmp-enable-irbuilder.
Restrict offload entry creation to module level finalize, preventing
asserts on missing offload entries from nested CodeGenFunction
finalizing before module completion.
Share one no-loop eligibility check between exec mode and body
The kernel is tagged SPMD_NO_LOOP by a single check, and the body is
emitted loop-free exactly when the kernel carries that tag. Add tests
for the clauses that block promotion.