[flang] Mark visible Cray pointer associations as aliasing (#221350)
A visible Cray pointer association (ptr = loc(x) in the same procedure)
can alias x and the pointee. Flang treated them as no-alias and
miscompiled some codes at -O2.
-funsafe-cray-pointers is too broad. Instead, lowering now marks x as
TARGET for that procedure so later FIR passes (including TBAA) see the
aliasing. Default behavior: no-alias is unchanged.
[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] 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 -- no rebuild, no TypeLoc re-emission.
- Sema::ActOnLateParsedTypeAttr builds the incomplete node; the parser
callback stores it on the LateParsedTypeAttribute and records the
attribute in the record currently being parsed.
Parser::CompleteLateParsedTypeAttributes drains that list at the closing
brace; a nested anonymous record hands its pending attributes up to the
[9 lines not shown]
[BoundsSafety] Handle the counted_by family as a type attribute
counted_by / sized_by (and their _or_null variants) were handled in only one
way: a declaration-position attribute went through handleCountedByAttrField,
which validated it and then patched the field afterwards with
FieldDecl::setType. There was no type-position handling at all.
Build the type during type construction instead, from a single handler that
serves both positions:
- Add HandleCountedByAttrOnType and dispatch the counted_by family to it
from processTypeAttrs, going through the shared
validateBoundsAttrTypeForTypePosition leaf.
- Remove handleCountedByAttrField. Its FieldDecl-based type-shape checks in
Sema::CheckCountedByAttrOnField are superseded by
Sema::ValidateBoundsAttrTypeShape, added in the previous commit and now
reached from the type path, and are deleted; no diagnostic is dropped. The
checks that genuinely need the FieldDecl (union member, non-flexible
array, cross-struct count) stay in CheckCountedByAttrOnField and run from
[11 lines not shown]
[BoundsSafety][NFC] Thread a late-parsed attribute list through declarators
A late-parsed type attribute is written in the middle of a declarator, so the
list it lands in has to travel with the declarator pieces until the enclosing
record can supply its argument. Add that storage and plumbing, with nothing
producing or consuming it yet:
- Move CachedTokens and LateParsedAttrList earlier in DeclSpec.h so DeclSpec,
Declarator and DeclaratorChunk can hold one.
- 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, passed down to ParseDeclarationSpecifiers.
No functional change: the lists stay empty and no caller passes one. The next
commit populates them.
[BoundsSafety][NFC] Add the Sema/Parser bridge for late-parsed type attributes
A late-parsed bounds attribute has to build its type when the attribute is
seen, but its argument isn't parseable until the enclosing record is complete.
Building that type needs the Parser (which owns the cached tokens) and Sema
(which owns type construction) to meet:
- Sema::ActOnLateParsedTypeAttr validates a counted_by-family attribute for
the type position and, if valid, wraps the type in a CountAttributedType
whose count is not yet known, handing the node back for completion.
- Parser::ProcessLateParsedTypeAttrCallback is the Parser-side entry point,
registered on Sema so Sema can call back without including Parser.h (the
same pattern as LateTemplateParserCallback). It reuses an already-built
node so several declarators sharing one attribute share one type.
No functional change: nothing records late-parsed type attributes yet, so the
callback is never invoked. The next commit wires it up.
[BoundsSafety][NFC] Add counted_by type-shape validation helper
Introduce the single "is this type valid for a counted_by-family attribute in
type position" leaf that both the eager type-attribute path and the
late-parsed path will call:
- Sema::ValidateBoundsAttrTypeShape holds the type-shape checks -- pointer
or flexible array member, void and function pointee, pointee that is a
struct with a flexible array member -- and their diagnostics.
- validateBoundsAttrTypeForTypePosition wraps it for type position and adds
the nested-pointer rejection, reported with the new
err_counted_by_on_nested_pointer diagnostic.
Supporting pieces: Sema::BoundsAttrFlags and Sema::getBoundsAttrKind,
getCountAttrKind, getPointerNestLevel, the CountedByInvalidPointeeTypeKind
enum, and LangOptions::hasBoundsSafetyAttributes(), a stub returning false so
the shared leaf can gate its -fbounds-safety-only branches with the same
predicate used downstream.
[2 lines not shown]
[X86] Fix `FastISel` crash on `GEP` with a constant index wider than `64` bits (#223432)
Fixes #220954
When FastISel folds a GEP into an X86 addressing mode, it reads each
constant index with `getSExtValue()` and adds it to the displacement.
That call asserts if the constant has more than 64 significant bits, so
a `getelementptr` with an `i128` index of `2^64` feeding a legal-typed
load crashes at `-O0`. The LangRef says a GEP index is sign-extended or
truncated to the pointer width, and both generic FastISel and
SelectionDAGBuilder already do exactly that (added in 2015 for this same
assertion). The X86 address folder was the one GEP lowering that never
got the same treatment.
The index is now truncated to 64 bits before it is folded, mirroring
`FastISel::selectGetElementPtr`. For the reproducer the index becomes
zero and the load addresses the alloca directly, which is also what
SelectionDAG produces for the same IR. The other integer conversions in
`X86SelectAddress` are already safe: struct indices are
verifier-enforced `i32`, and the folded-add and `Add` paths only match
values whose type already equals the pointer width.
[CIR] Give up when we hit a global-view in dense-element-attr lowering (#224379)
A ptr-to-int conversion can't be converted to an APInt/APFloat, so this
ends up not being able to produce a valid dense element attr. This patch
makes us 'fall back' to the insert-value version of any potential
dense-elements lowering if there is a global view as one of the values.
[CIR] Correctly pass func self-comdat & alignment (#223773)
Classic codegen does these, and it is important for when these end up
being stored as function pointers, as we discovered on a benchmark.
This patch does 2 things:
1- Properly passes the 'self' 'comdat' feature (that is, when the symbol
reference is 'self', not when it is a different name, which isn't
implemented anywhere). This mirrors what was done for GlobalOp.
2- Properly calculate and pass the 'alignment'/'preferred alignment' for
a function. Only the 'alignment' is passed to LLVM-IR, as the dialect
doesn't support preferred alignment, so a 'missing feature' is left in
place. That functionality isn't important to this patch, but was 'next
to' the alignment work in CodeGenModule.cpp, so it seemed like something
we should handle if at all possible.
[x86][CostModel] A runtime stride should cost one ADD on AVX2+ (#219903)
Runtime stride should cost one ADD per iteration. Only when the loop has
no fixed step do we need the AVX2 cut-off.
Closes #217019.
[offload-arch] Report gfx1250-strict to match rocminfo (#224480)
## Motivation
offload-arch would print gfx1250, but rocminfo reports gfx1250-strict on
revision 0s. We want to print the gfx1250-strict too.
Note: This is based off a [similar PR in
rocm-systems](https://github.com/ROCm/rocm-systems/pull/11639).
## Required Changes
* llvm already can parse the gfx1250 -strict target, so no changes
necessary there.
* offload-arch already printed gfx1250, so just needed to get the ASIC
Revision, which is in bits 25:22 in the capability property.
* If ASIC Revision is 0 and gfx_target_version is gfx1250, then report
"gfx1250-strict"
[5 lines not shown]
[MLIR][Parser] Fix result numbers not being allowed in switch statements (#224581)
PR #87658 fixed this for the `case` branch for `cf.switch`, but not the
`default` case. Moreover, `llvm.switch` has the same problem. This PR
fixes them.
[lldb][Fortran] Added support for base types to DWARFASTParserFortran, tests for DWARFASTParserFortran and a method to get the parser from TypeSystemFortran
[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] 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 -- no rebuild, no TypeLoc re-emission.
- Sema::ActOnLateParsedTypeAttr builds the incomplete node; the parser
callback stores it on the LateParsedTypeAttribute and records the
attribute in the record currently being parsed.
Parser::CompleteLateParsedTypeAttributes drains that list at the closing
brace; a nested anonymous record hands its pending attributes up to the
[9 lines not shown]
[BoundsSafety] Handle the counted_by family as a type attribute
counted_by / sized_by (and their _or_null variants) were handled in only one
way: a declaration-position attribute went through handleCountedByAttrField,
which validated it and then patched the field afterwards with
FieldDecl::setType. There was no type-position handling at all.
Build the type during type construction instead, from a single handler that
serves both positions:
- Add HandleCountedByAttrOnType and dispatch the counted_by family to it
from processTypeAttrs, going through the shared
validateBoundsAttrTypeForTypePosition leaf.
- Remove handleCountedByAttrField. Its FieldDecl-based type-shape checks in
Sema::CheckCountedByAttrOnField are superseded by
Sema::ValidateBoundsAttrTypeShape, added in the previous commit and now
reached from the type path, and are deleted; no diagnostic is dropped. The
checks that genuinely need the FieldDecl (union member, non-flexible
array, cross-struct count) stay in CheckCountedByAttrOnField and run from
[11 lines not shown]
[BoundsSafety][NFC] Thread a late-parsed attribute list through declarators
A late-parsed type attribute is written in the middle of a declarator, so the
list it lands in has to travel with the declarator pieces until the enclosing
record can supply its argument. Add that storage and plumbing, with nothing
producing or consuming it yet:
- Move CachedTokens and LateParsedAttrList earlier in DeclSpec.h so DeclSpec,
Declarator and DeclaratorChunk can hold one.
- 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, passed down to ParseDeclarationSpecifiers.
No functional change: the lists stay empty and no caller passes one. The next
commit populates them.
[BoundsSafety][NFC] Add the Sema/Parser bridge for late-parsed type attributes
A late-parsed bounds attribute has to build its type when the attribute is
seen, but its argument isn't parseable until the enclosing record is complete.
Building that type needs the Parser (which owns the cached tokens) and Sema
(which owns type construction) to meet:
- Sema::ActOnLateParsedTypeAttr validates a counted_by-family attribute for
the type position and, if valid, wraps the type in a CountAttributedType
whose count is not yet known, handing the node back for completion.
- Parser::ProcessLateParsedTypeAttrCallback is the Parser-side entry point,
registered on Sema so Sema can call back without including Parser.h (the
same pattern as LateTemplateParserCallback). It reuses an already-built
node so several declarators sharing one attribute share one type.
No functional change: nothing records late-parsed type attributes yet, so the
callback is never invoked. The next commit wires it up.
[DAG] Don't constant fold opaque constants in visitMULO (#224494)
Opaque constants (created for constants hoisted by ConstantHoisting) are
deliberately not folded by FoldConstantArithmetic for binary operations,
so that the hoisted constant is not rematerialized in each user. The MULO
fold in DAGCombiner did not check for this.
The second test reveals a second opaque constant problem - apparently
our constant RHS canonicalization isn't properly handling opaque
constants. (This change is about three split attempts off of something that
was supposed to be fairly trivial. I decided to stop here.)
Assisted-by: Claude Fable 5.1
[BoundsSafety][NFC] Add counted_by type-shape validation helper
Introduce validateCountedByAttrType and its supporting helpers
(getCountAttrKind, getPointerNestLevel, the CountedByInvalidPointeeTypeKind
enum) plus the err_counted_by_on_nested_pointer diagnostic. This is the
single "is this type valid for a counted_by-family attribute" leaf that both
the eager type-attribute path and the late-parsed path will call.
Unused at this point -- nothing invokes it yet -- so this is NFC. The callers
are added in the following commits.
Reapply [Support] ToolSession for in-process tool invocation (#224515)
This PR Relands #221996, which was approved and merged but reverted in
#224368 after failures in the Fuchsia builders.
This PR contains two commits:
1. The original approved commit, reapplied without changes.
2. A small follow-up fixing the reported failures.
The problem was that a direct Clang invocation was incorrectly marked as
needing a prepended tool name. When Clang launched cc1 out of process,
we produced:
clang clang -cc1 ...
instead of:
clang -cc1 ...
[11 lines not shown]
[clang-tidy] Skip `decltype(auto)` variables in misc-const-correctness (#224465)
Since #157319 the check analyzes `auto` variables, which also pulled in
`decltype(auto)`. Its fix-it inserts `const`, but `decltype(auto)`
cannot be combined with other type specifiers, so the fix does not
compile:
```cpp
decltype(auto) x = get_ref();
decltype(auto) const x = get_ref(); // error
```
Exclude such variables from the analysis, as no `const` can be added.
Fixes #223940
[Loads] Fix incorrect replacement of pointers with different provenance (#224281)
isPointerAlwaysReplaceable() uses getUnderlyingObject() to check whether
the two pointers have the same provenance, because in that case the
replacement is always legal. However, getUnderlyingObject() does not
actually guarantee that the provenance is the same: In particular, it
can look through some intrinsics like strip.invariant.group and
launder.invariant.group, which do change the provenance of the pointer.
And replacing the result of those intrinsics with their argument is
indeed incorrect.
Fix this by adding a MustPreserveProvenance argument to the relevant
APIs, and enable it in isPointerAlwaysReplaceable().
Noticed while working on
https://github.com/llvm/llvm-project/pull/224222.
[libc++] Locate libstdc++ by querying GCC in the libstdc++ test configuration (#224335)
Instead of hardcoding various paths to locate libstdc++ artifacts, just
provide the compiler and derive all paths from that. This makes it
simpler to run against a pre-installed libstdc++.
[libc++] Allow specifying a configuration in test-at-commit (#224381)
test-at-commit always generated its own Lit configuration pointing at
the libc++ installation given with --libcxx-installation, which meant it
could only ever test libc++. This patch generalizes this to allow
support passing a custom Lit config, which allows using the script for a
wider array of use cases.
Reapply "[Clang] Fix a number of issues involving expansion statements" (#220375) (#223005)
This reverts 7c44c505cd7688a8994779f1751e0f9b4b95ab4c and relands
#217110.
There were two tests that needed updating: one because a warning that
had previously been erroneously suppressed (because we thought we
weren’t in a function) now works properly, and another because it
crashes due to an unrelated bug. I’ve filed #223003 for the latter and
moved the crash into a separate XFAIL test so it can be reenabled when
the bug is fixed.
The plan was to backport this to the 23 release branch, so still no
release note.
[flang-rt] Compile ShallowCopyModifiedSuffix for the device (#224485)
#222101 introduced `ShallowCopyModifiedSuffix` as the callee of
`CopyOutAssign` and deliberately left it outside the offload API group,
with a comment claiming its only caller is host-only. This fix moves the
`ShallowCopyModifiedSuffix` family into the offload API group and marks
it `RT_API_ATTRS`, exactly like the `ShallowCopy` family it mirrors.
Also resolved the merge conflict with #224570 (the reland of #224063):
the new CopyOutAssignDirect entry point needed the same treatment.
Assisted-by: AI