[OpenMP] Preview of auto-generating OpenMP definitions
The components of this commit:
1. Definitions of descriptors that will hold relevant data in LLVM
and declarations of associated functions.
2. "Auto-generated" enum definitions and descriptor data
3. Changes to flang's modifier verification to use the new data
instead of the previously hand-coded modifier information.
This does not contain the actual auto-generation infrastructure.
The included descriptors were generated directly from JSON files by
a custom python script.
[LifetimeSafety] Suppress dangling field warnings for RAII resetters in permissive mode
(#214212)
In `-Wlifetime-safety-permissive` mode, suppress dangling field warnings
(`-Wlifetime-safety-dangling-field`) when `this` or the escaping field
declaration is captured by a lambda within the function. This accounts
for common RAII field resetters that clean up dangling pointers on scope
exit.
### Motivating Example
Dangling field analysis can report false positives when an RAII field
resetter (such as `absl::MakeCleanup` or `absl::Cleanup`) captures
`this` or the field to reset the pointer before function exit:
```cpp
struct TimeServerInstance {
Handler* handler_;
void init() {
[8 lines not shown]
[OpenMP] Preview of auto-generating OpenMP definitions
The components of this commit:
1. Definitions of descriptors that will hold relevant data in LLVM
and declarations of associated functions.
2. "Auto-generated" enum definitions and descriptor data
3. Changes to flang's modifier verification to use the new data
instead of the previously hand-coded modifier information.
This does not contain the actual auto-generation infrastructure.
The included descriptors were generated directly from JSON files by
a custom python script.
[Sparc][clang] make `_Complex` ABI GCC-compatible (#212340)
Modify the ABI of `_Complex` so that it matches GCC for all types,
specifically:
- On SPARC, a `_Complex` value with an integer element type is now
passed and
returned packed into the one or two integer registers it fits in,
matching GCC.
Clang previously passed such a value indirectly and returned it with one
part
per register.
`-fclang-abi-compat=23` restores the previous behavior.
- On SPARC64, a `_Complex char` or `_Complex short` is now
right-justified in its slot in the parameter array, like every other
scalar
narrower than a slot, rather than left-justified the way a small struct
is.
[14 lines not shown]
[CIR]/[OGCG] Fix handling of bool-backed-scoped-enums (#214084)
This patch primarily fixes the case of a scoped enum with a boolean type
in CIR, which we assume is an 'int' type, whereas this one case, that is
not true. Rather than change the Dialect for what amounts to a very rare
case, we've instead opted to just coerce the bool type into a 1 bit int
type, so that all our passes will consider it the same as the rest of
the switches, and not have to special-case the 'bool' types.
AS A DRIVE-BY: I discovered that classic-codegen manages to assert on
llvm::isUIntN in the case where the storage of a range for
GNU-range-switch is less than 7 bits, so bit-int could possibly hit this
too with gnu-range. This patch would fix any case (as the test for the
'shortcut' is for <64).
[clang][LifetimeSafety] Drop block-local origins at block exit (#213530)
Block-local origins were only discarded in `join`, which the dataflow
driver skips when a successor's in-state is seen for the first time, and
therefore always skips for a block with a single predecessor. In
straight-line code the block-local map was inherited down the whole
chain and never cleared, so it accumulated every expression origin in
the region.
Drop them in a new `exitBlock` hook instead, which runs on every edge.
This also keeps in-states canonical, so state comparison no longer sees
a spurious difference between a first-visit in-state and a joined one.
The per-program-point states the checker queries are unaffected; only
the state propagated across block boundaries changes.
LoanPropagation time below, median of 5-7 interleaved runs of a baseline
and a patched binary. Synthetic cases are from
clang/test/Analysis/LifetimeSafety/benchmark.py:
[26 lines not shown]
[CIR] Verify record_align is a non-zero power of two (#214074)
`#cir.record_layout` carries `record_align`, which CIRGen fills from
`ASTRecordLayout::getAlignment()` and consumers read as an
`llvm::Align`. That constructor asserts the value is a non-zero power of
two, so hand-written CIR naming any other alignment aborted the tool
rather than reporting a parse error. A zero tripped the non-zero assert
and a 3 tripped the power-of-two one, both inside `llvm::Align` with no
indication of which attribute was at fault.
Verify the field where it is parsed. Values CIRGen emits are already
well-formed, so this only affects hand-written input.
Assisted-by: Cursor / claude-opus-5
[analyzer] Discard stack frames that are not on the current live stack (#213779)
When a source's stack frame is not live on the current stack the
`UseAfterLifetimeEnd` checker emitted a false positive. Such sources
outlive the returned value, so they are not dangling stack sources. This
led to multiple false positives when I ran the `UseAfterLifetimeEnd`
checker on the LLVM project.
---------
Co-authored-by: isuckatcs <65320245+isuckatcs at users.noreply.github.com>
[clang][Sema] Handle alloc_align on all HasFunctionProto declarations (#210871)
Fixes #122058.
## Overview
Attribute `alloc_align`'s TableGen subject accepts any declaration
satisfying `HasFunctionProto`, but `AddAllocAlignAttr` unconditionally
casts the declaration to `FunctionDecl` (in
`Sema::AddAllocAlignAttr()`). Since there exist `Decl`'s that have an
underlying `FunctionProtoType` but are not `FunctionDecl` (e.g. function
pointer variables and parameters), the unconditional
`cast<FunctionDecl>` is too narrow and leads to a crash for `Decl`s that
are meant to be compatible with the `alloc_align` attribute.
For example, trying to compile `C` file
```
void *(*allocator)(unsigned long long) __attribute__((alloc_align(1)));
[125 lines not shown]
[flang][MIF] Fix undef reference to a coarray_handle in mif.dealloc_coarray #193157 (#213890)
This PR fixes the behavior reported in issue #193157. The coarray_handle
was only defined if a call to mif.alloc_coarray was present.
If a call to mif.dealloc_coarray was encountered without a prior call to
mif.alloc_coarray, then the coarray_handle was missing, and therefore
llvm.address_of pointed to a non-existent address, which is not allowed.
We now define a coarray_handle that has not been allocated by PRIF for
each coarray variables.
[flang][OpenMP] Use 'present-modifier' instead of 'expectation' in 5.1 (#214083)
The 5.1 spec lists PRESENT as an alternative in a 'motion-modifier'. The
other alternatives are mapper and iterator. These already exist as
separate modifiers, so 'motion-modifier' would best be expressed as a
modifier group. While modifier groups are not implemented yet, borrow
'present-modifier' from the 6.0 spec.
The 'expectation' modifier only existed in 5.2, it was replaced by
'present-modifier' in 6.0.
[InstCombine][AArch64] Combine ORRs with logical umin ops (#213651)
Combine:
orr(umin(A, 1), umin(B, 1)) -> umin(orr(A, B), 1)
To remove a redundant UMin. This pattern has been observed with
reduction chains of multiple ORRs of UMin(x, 1), where only one final
UMin(x, 1) is necessary for truncation.
[SPIR-V] Fix OpGroupAsyncCopy null event substitution (#212754)
Only replace the event operand with OpConstantNull when it is actually a
null constant
This complies with spirv-val expectations
[llvm-profgen] Harden perf script invocation (#212253)
Harden ``llvm-profgen``'s ``perf script`` invocation for ``--perfdata``:
report launch/exit failures, and clear redirect files between the two
invocations so stale stdout/stderr cannot leak. Cover both with lit
tests that inject a mock ``perf`` via ``PATH``.
Assisted by GPT-5
[LV] Fix unintended SCEV cache population when querying UnrollVectorizedLoop (#208500)
LoopVectorize queried getUnrollingPreferences after VPlan execution,
when the vector loop had already been created. If the target hook
queries ScalarEvolution, this populates the SCEV caches with expressions
for the new loop and changes which existing values SCEVExpander reuses
later.
This is exposed by #205102, where the new AArch64 unrolling preferences
cause unrelated LoopVectorize tests to produce different IR.
UnrollVectorizedLoop is a target-wide preference. Query it on the
original loop before VPlan execution and before its SCEV information is
forgotten. This prevents the preference query from polluting subsequent
SCEV expansion.
[SPARC] use `divideCeil` to calculate register offset (#213739)
So that later arguments get the correct register alignment
https://godbolt.org/z/oaEf4Thvx
On current clang the aligned struct starts in `o1`, but with GCC it is
aligned and starts in `o2`. In practice I think only `float` could hit
this (not an int, not an aggregate, smaller than 64 bits).
[flang][flang-rt] Add -ffpe-trap= to set the initial FP exception halting mode (#208828)
Implement the gfortran-style `-ffpe-trap=<list>` option, which sets the
initial floating-point exception halting mode for the main program unit.
The Fortran 2023 standard (17.6) permits the initial halting mode to be
processor defined, so honoring this at program start is conforming.
`<list>` is a comma-separated set of exception mnemonics: `invalid`,
`zero`, `overflow`, `underflow`, and `inexact`, corresponding to the
IEEE_FLAG_TYPE values IEEE_INVALID, IEEE_DIVIDE_BY_ZERO, IEEE_OVERFLOW,
IEEE_UNDERFLOW, and IEEE_INEXACT. As a non-standard, gfortran-compatible
extension, `denormal` halts on the x86 denormal-operand exception. An
empty list or the value `none` disables halting, and the last
`-ffpe-trap=` on the command line wins (allowing an earlier request to
be overridden).
Changes by component:
- clang/Driver: give `-ffpe-trap=` FlangOption/FC1Option visibility and
a one-line HelpText plus a detailed DocBrief (moved into f_Group);
[28 lines not shown]
[SLP]Fix crash from runtime alias check reusing body scalars
Emit the check at the block's first insertion point instead of before
the terminator. SCEV expansion reuses any dominating instruction, so
at the terminator it could pick up body scalars that are later moved
into the vector block and deleted, causing a crash.
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/214211
[Analysis] Cache generation of SCEV expander overflow checks (#213013)
When creating SCEV checks as part of loop vectorisation we often
generate overflow checks, which leads to lots of duplicated calls to the
umul_with_overflow intrinsic. These calls should be cleaned up during
codegen. However, it is unfortunate that the current LLVM method of
calculating the cost of IR in a block involves looping over each
instruction and adding the costs individually with no thought to the
trivial CSE or DCE optimisations that would take place. In the absence
of a more sophisticated method of cost analysis, for now I've chosen to
explicitly CSE these overflow checks during SCEV expansion.