[clang-tidy] Fix crash in bugprone-misplaced-pointer-arithmetic-in-alloc (#224509)
This commit checks for an empty constructor argument list before
accessing its last element.
Reproducer at: https://godbolt.org/z/Tfvnbhx19
AI Usage: the issue was found by Grok 4.6. Although IMO this is a pretty
uncommon/rare case, less crash-on-valid is always better.
[llvm-pdbutil] Print error on invalid YAML (#207528)
From
https://github.com/llvm/llvm-project/pull/207058#discussion_r3522204565:
We should print out an error if we encounter invalid YAML.
With this PR, the error is printed. I included the diagnostics here,
because they provide better error messages and allow you to locate the
error easier.
[LV] Fold invariant reduction phis to their start value. (#223279)
A reduction phi whose backedge value is the phi itself is invariant and
equal to its start value. This can happen when the reduction operation
folds away, e.g. `or X, 0`, `and X, -1`, `add X, 0` or `mul X, 1`.
Clean up such trivial non-reductions early.
PR: https://github.com/llvm/llvm-project/pull/223279
[flang][cuda] Record implicit managed attribution in module files
An attribute the compiler applied under -gpu=mem:managed is written into the
module file the same way a user-written one is, so a reader cannot tell them
apart. It then treats the attribute as a user requirement: allocating such a
component in a DEVICE object is rejected, and the memory space the user did
ask for on the object no longer wins.
Spell the distinction in the module file as MANAGED(IMPLICIT), modelled on
INTENT(IN): CUDA-data-attr gains an optional parenthesized qualifier, carried
by a new CUDADataAttrSpec parse-tree node in AttrSpec and ComponentAttrSpec.
ATTRIBUTES(...) keeps the bare attribute, so the qualifier cannot be written
there.
The attribute itself is still written out, so a component keeps the same
memory space no matter which options a consumer is compiled with.
Also stop an implicitly applied attribute from making a module a definer of
CUDA symbols. Without this, adding -gpu=mem:managed to a module's build
rejects its OpenACC-only consumers over an attribute the user never wrote.
[flang][cuda] Implicitly attribute ALLOCATABLE/POINTER components as managed
Under -gpu=mem:managed, resolve-names implicitly attributes allocatables and
pointers declared in an ordinary scope as managed.
Apply the same attribution to components in Post(ComponentDecl). An explicitly
attributed component keeps its own attribute, and a translation unit without
CUDA Fortran enabled is left alone.
Record the attribution in ObjectEntityDetails::cudaDataAttrIsImplicit, since
an attribute the compiler applied is not a user requirement: a memory space
the user did ask for on an enclosing object takes precedence over it.
[AArch64][NeoverseV1/V2] Fix extended/shifted-register scheduling for ADD[S]/SUB[S]/AND[S]/BIC[S] (#220920)
Verified with llvm-exegesis on Neoverse V1 and V2 hardwares.
Opcodes | Before | After
-----------------------|---------------------|------------------------------
ADDWrx/SUBWrx | 2c (SchedAlias) | IsRealArithExtendW: 1c or 2c
ADDSWrx/SUBSWrx | IsCheapLSL | IsRealArithExtendW: 1c or 2c
ADDSXrx/SUBSXrx | IsCheapLSL | static 2c (always real extend)
ADDSXrx64/SUBSXrx64 | IsCheapLSL | static 1c (always passthrough)
ANDS/BICS Wrs,Xrs | static 2c | NeoverseShift0: 1c or 2c
IsCheapLSL checks the shift *amount* (<=4), which is the wrong axis for
the extend-register forms (need the extend *type* instead) and does not
apply to ANDS/BICS (no amount threshold, just shift-present-or-not).
NeoverseNoLSL becomes NeoverseShift0: adding LSR, ASR and ROR in
addition to LSL. Does not apply it on NeoverseV3 and others as it is not
validated using llvm-exegesis on these hardwares.
llvm-c: Compute the DataLayout from the triple and ABI
Drop a use of createDataLayout
Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
[clang-tidy] Fix false positive in readability-non-const-parameter for atomic builtins (#221951)
Atomic builtins are represented in the AST by `AtomicExpr` rather than
`CallExpr`, so `readability-non-const-parameter` never analysed their
operands and assumed the pointed-to data was only read. It then
suggested making those pointer parameters point to const, and applying
the fix-it produced code that no longer compiles.
The most visible case is the `expected` operand of a compare-exchange,
which per the C standard must be a pointer to non-const because it
receives the old value when the exchange fails:
https://godbolt.org/z/sovKf3G3c
Before this change the check reported `expected` as a candidate for
pointer-to-const. The GNU builtins are affected the same way, and there
the address operand `obj` was reported too, as were the destination
operand of `__atomic_load()` and the old-value operand of
`__atomic_exchange()`.
[5 lines not shown]
llc: Compute the DataLayout from the triple and ABI
This is the minimum change to avoid createDataLayout. Future work
will be needed here to really drop use of the ABIName field.
[libc] Add getgrent, setgrent, and endgrent entrypoints (#224372)
Implement the POSIX group database iteration entrypoints getgrent,
setgrent, and endgrent on top of grp_utils and FlatFileDatabase.
Non-reentrant calls read into a process-global DynamicBuffer that grows
to the high-water mark of the largest group record seen. endgrent closes
the file stream without freeing the buffer so pointers returned prior to
endgrent remain valid until the next non-reentrant call.
* Add getgrent, setgrent, and endgrent entrypoints
* Define getgrent, setgrent, and endgrent in include/grp.yaml
* Expose entrypoints across Linux target architectures
* Add hermetic integration tests in test/src/grp/getgrent_test.cpp
Assisted-by: Automated tooling, human reviewed.
Reland [flang][HLFIR] make copyin/copyout allocation inline (#224063) (#224570)
This patch moves most allocations of copyin/copyout to the compiler so
that small buffers can be stack allocated, even when the loops are not
inlined. The main motivation is to allow better memory management when
the code ends-up in device region, but this also benefits CPU by giving
more control over allocations.
In the future, we may just consider inlining everything including
copyout, but very early attempts to do so showed that this increased WRF
compile times significantly at O2 for no benefits and the copyout runtime
was just modified to do "copy on change" so I do not want to inline it
until more this new approached is tested more broadly.
Hence this patch just moves to use `ShallowCopyDirect` for the copy-in
and a new `CopyOutAssignDirect` for the copy-out (so that the new copy
on change policy can be integrated) for non assumed-rank non polymorphic
copy-in/copy-out, and does the allocation inline for the buffer
following the same rules as in `inlineHLFIRCopyin` (i.e. small buffers
[9 lines not shown]
[CMake] Do not use llvm-rc without Clang in external projects (#224505)
On Windows, configuring LLVM without Clang but with external projects
i.e.
```
-DLLVM_ENABLE_PROJECTS=
-DLLVM_ENABLE_RUNTIMES=orc-rt
```
llvm-rc is selected as the rc compiler but requires clang for
pre-processing. Only select llvm-rc for external projects when Clang is
also part of the toolchain, otherwise CMake uses the host rc compiler.
[MemoryDependenceAnalysis] Migrate `isStorePreservingMemoryLocation` to Loads (NFC) (#223700)
Minor opportunity to expose the helper and move it out of MDA.
[AMDGPU][CodeGen] Replace non-existent opcodes in gfx1250 test (#223767)
`IMAGE_LOAD_V5_V1` and `IMAGE_SAMPLE_C_CL_O_V4_V8` don't exist on
gfx1250. This keeps the tests' intent without relying on them.
[llvm] Adjust LLVM_ABI annotations (#224293)
The automatic LLVM_ABI annotations script has been broken since #208780.
PR #223354 restores its functionality. In the meantime, some API
annotations regressed. This PR aims to fix all of these regressions.
This was applied by calling the updated ids-check-helper.py from #223354
on the public LLVM headers on a macOS host and clang-formatting the
results.
The effort to build LLVM as a dylib is tracked in #109483.
[ELF,test] Reorganize ICF tests by the property they exercise (#224567)
icf-merge.s now covers relocations into SHF_MERGE sections, adding
section symbol addends at and past the end of the section.
icf-reference-graph.s collects reference shapes: the cycle from icf2.s
and icf3.s, a section referencing itself, and chains that differ only
beyond the initial hash's reach. Only the cycle was covered before.
[AMDGPU] Remove `hasSideEffects` from `SI_IF`, `SI_ELSE` and `SI_LOOP` (#224007)
An arbitrary side-effect flag blocks sinking of memory operations due to
the unmodelled-side-effect check returning true. This change has no
effect on other transformations as modeled side effects (EXEC and SCC
defs) are still accounted for and sufficient to gate unsound code
motion. All three instructions are still rejected by `isSafeToMove` as
they carry the terminator flag.
This commit is part of the effort to enhance `MachineSink` on the AMDGPU
target. By itself itself it does not unblock more code motion
opportunities but it is a prerequisite to do so.
Revert "[WebKit checkers] Treat the return value of an instance method as an unsafe pointer origin (llvm#160569)" (#224479)
This reverts commmit d08a2a43abd91865002a42938b60f172527defa3 as it
introduced too many new warnings.
[ORC][Mips] Fix calling convention handling for lazy calls (#223830)
Move the resolved address into $t9 before jumping to it, as jumping
target is evaluated before delay slot execution.
Correct the o32 stub size to 16 bytes and reserve the required argument
save area around the reentry call for saved registers.
Update resolver sizes to match the emitted instructions.
Validated with existing tests on Mips Linux for both o32 and n64.