[PrologEpilogInserter] Don't preserve CFG in case of HIPE or segmented stack (#239704)
As in title. The CFG is not preserved in case of HIPE or segmented stack
since then we insert new basic-blocks. Add newpm run to affected tests.
The CFG is modified in AdjustForSegmentedStacks and AdjustForHiPEProlog
functions
[libc][stdfix] Implement mulifx functions (#235602)
This PR implements `mulifx` functions with unit tests.
```c
int mulir(int, fract);
long int mulilr(long int, long fract);
int mulik(int, accum);
long int mulilk(long int, long accum);
unsigned int muliur(unsigned int, unsigned fract);
unsigned long int muliulr(unsigned long int, unsigned long fract);
unsigned int muliuk(unsigned int, unsigned accum);
unsigned long int muliulk(unsigned long int, unsigned long accum);
```
Based on https://github.com/llvm/llvm-project/pull/206115.
Supersedes https://github.com/llvm/llvm-project/pull/138654.
Fixes https://github.com/llvm/llvm-project/issues/114503
[4 lines not shown]
X86: Keep the TargetMachine alive in TernlogTest
The TTI callback destroyed the TargetMachine it created before the
returned TTI was used, leaving it with dangling pointers. It just
happens this test never reads from these pointers today, so no
sanitizer reports this.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[ConstraintElim] Split signed min/max across their operands when checking a compare
The existing constraint systems only record the bounds that hold for both
operands of a min/max (smax(a, b) >= a and >= b, smin(a, b) <= a and <= b). The
other direction is a disjunction, which cannot be recorded as a fact. When a
compare of signed decompositions involves a min/max result, split it into its
operands: the decomposition is monotonic in that result, so it is the max or min
of its values on each side, and the relation holds for all or for either side
respectively.
https://alive2.llvm.org/ce/z/zsGkJ-
[ConstraintElim] A signed sum of operands with opposite signs cannot wrap
If one operand is known non-negative and the other non-positive, the signed
sum is between them, so it cannot overflow.
https://alive2.llvm.org/ce/z/ZF5Yqr
[ConstraintElim] Prove sadd/ssub.with.overflow cannot overflow from the exact sum
Decompose the operands and show that the sum lies in the range of the type. This
handles patterns like A + (B - A), as well as sums involving signed min/max
results, which are split across their respective operands using monotonicity
(for example start + smax(end - start - 1, 0) <= end).
https://alive2.llvm.org/ce/z/ze8LCk
[AMDGPU] Select unscaled `div.fmas` with shared patterns (#239680)
Select `amdgcn.div.fmas` with a constant-false scale operand as ordinary
FMA for f32 and f64 when the effective input-denormal mode is IEEE.
* The [AMD ISA specification, §12.11, `V_DIV_FMAS_F32` and
`V_DIV_FMAS_F64`](https://www.amd.com/content/dam/amd/en/documents/instinct-tech-docs/instruction-set-architectures/amd-instinct-mi300-cdna3-instruction-set-architecture.pdf#page=347)
defines both instructions as fused multiply-add with conditional scaling
controlled by VCC. When VCC is clear, the result is simply `fma(src0,
src1, src2)`. The specification also states that input denormals are
preserved while output flushing is allowed.
* Requiring IEEE input-denormal handling therefore makes ordinary FMA a
valid replacement. Output-only flushing remains eligible because both
instructions honor output-denormal handling.
* Share the TableGen patterns between SelectionDAG and GlobalISel.
Prefer FMAC when no source modifiers are needed, and select scalar FMAC
for uniform f32 operations on targets with scalar floating-point
support.
[SystemZ] Set source date epoch in clang lit tests for z/OS (#238545)
All of these tests run two compiles and then compare the output. The IR
for z/OS includes a timestamp. That can cause the compares to fail. Add
the source epoch option to ensure the compares don't fail because of the
time stamp.
[flang] Accept a BLOCK variable in a DO CONCURRENT locality-spec (#239371)
A variable declared in a `BLOCK` with a plain type declaration is
rejected when it appears in a locality-spec of a `DO CONCURRENT` inside
that `BLOCK`:
```fortran
subroutine s(n)
integer :: n, j
block
integer :: tmp
tmp = 0
do concurrent (j=1:n) reduce(max:tmp)
tmp = max(tmp, j)
end do
end block
end subroutine
```
[46 lines not shown]
[LifetimeSafety] Issue reference-to-pointer param placeholders at the pointee origin
A parameter of reference-to-pointer type (`T*&`) has a two-level origin list:
the outer (reference-binding) level and the inner (pointer-value) level.
Its placeholder loan was issued to the outer origin, but a read through the
reference (`T* x = p;`) peels to the inner origin.
The read carries no placeholder and lifetime-safety inference never observes
the pointer escaping.
For example, this code wouldn't get inferred lifetimebound:
```c++
T *fn(T*& slot, ...) {
//...
return slot;
}
```
Callers of this function would lose their borrows.
Issue the placeholder for a reference-to-pointer-like parameter at the inner
[5 lines not shown]
[LifetimeSafety] Flow pointee loan for lifetimebound reference-to-pointer params
At a call to a function with a `[[clang::lifetimebound]]` parameter, the result
origin was always tied to the argument's top-level (outer) origin
(FactsGenerator.cpp, the `ShouldTrackArg` branch). That is correct when the
argument and result have the same indirection shape, but wrong for a
reference-to-pointer parameter returned by value: an lvalue argument bound to a
`T*&` parameter has an extra storage level from the reference binding, so the
returned pointer was tied to the referent's *address* instead of the pointer
*value* read through the reference.
This is the shape of `T std::exchange(T& obj [[clang::lifetimebound]], U&& new)`
if `T=int*` for example.
It's pretty frequent that templated C++ takes generic types as lvalue or rvalue
references because it avoids copying potentially expensive types.
The particular case motivating this patch looked like this:
```c++
int local = 10;
[30 lines not shown]
[lldb-dap] Use target.disable-aslr when disableASLR is omitted (#239443)
`LaunchRequestArguments::disableASLR` was a `bool` defaulting to `true`
that was always applied to the launch flags. This overwrote the
`eLaunchFlagDisableASLR` value that `SBTarget::GetLaunchInfo()` derives
from the `target.disable-aslr` setting, so changing that setting (for
example in `~/.lldbinit` or through `initCommands`) had no effect on
lldb-dap launches.
This came up in containers that do not allow disabling ASLR. They
provision an lldbinit that sets `target.disable-aslr` to `false`, which
the lldb command line honors, but lldb-dap ignored it, so every launch
failed unless the client explicitly sent `"disableASLR": false`.
Make `disableASLR` a `std::optional<bool>` and only apply it when the
client provides it. When it is omitted, `target.disable-aslr` (which
defaults to `true`) decides, so the default behavior is unchanged and an
explicit `disableASLR` still takes precedence. The VS Code extension
only sends `disableASLR` when the `lldb-dap.disableASLR` setting differs
[7 lines not shown]
[libc][sys/shm] Implement shmat syscall wrapper on Linux. (#239428)
shmat is a POSIX function (see
[docs](https://pubs.opengroup.org/onlinepubs/9799919799/functions/shmat.html#))
that attaches the shared memory segment to the address space of a
calling process.
On Linux, it can be implemented as a simple wrapper around SYS_shmat
syscall.
Provide the implementation, and define related macro `SHMLBA` (used for
rounding) and `SHM_FAILED` (to signal failed operation) to the
`<sys/shm.h>` header.
[DAG] Preserve scalar flags when folding vector constants (#239632)
This patch forwards `SDNodeFlags` to `FoldConstantArithmetic` during
per-element constant folding with vector operations so that they are not
dropped from other (potentially unrelated) scalar operations through
CSE.
[AMDGPU][NFC] precommit test for StructurizeCFG hoist and replace else phi arm for non-diamond case. (#239681)
Moved to AMDGPU subdir
Addressed few concerns from
https://github.com/llvm/llvm-project/pull/239541
[SimpleLoopUnswitch] Check trivial unswitch candidate is conditional (#238519)
A conditional branch whose successors are both the loop latch is in fact unconditional.
However, we still attempt to unswitch it, which triggers an assertion in DTUpdater
because the branch-to-latch edge that we want to remove is not actually eliminated.
This fixes issue #238304.
Assisted by Claude Code.
[CIR] Mark the terminator synthesized for function fall-off as implicit (#238696)
First step towards issuing -Wreturn-type from ClangIR instead of Clang's
CFG.
When a body falls off its end, CIRGen emits a `cir.trap`,
`cir.unreachable` or `cir.return` that looks the same as a user's
`__builtin_trap()`, `__builtin_unreachable()` or `return`, so an
analysis over CIR cannot tell where a function falls off. Note that when
you call __builtin_trap(), __builtin_verbose_trap() or
__builtin_unreachable() directly, the op is never marked implicit.
Add an `implicit` unit attribute to `cir.return`, `cir.trap` and
`cir.unreachable`, set only on the terminator CIRGen synthesizes for
fall-off. Lowering is unchanged.
[asan][test] Pass --allow-shlib-undefined in global-overflow-bfd.cpp (#239748)
When ASan tests run with `--sysroot=${CMAKE_SYSROOT}` and
`-shared-libasan` (such as after #120798 / #239742), Clang links
`libclang_rt.asan.so` without passing `-lpthread`, `-lrt`, or `-ldl`
explicitly, and GNU `ld.bfd` ignores `-L` search paths when resolving
indirect `DT_NEEDED` libraries inside a multiarch sysroot. Pass
`-Wl,--allow-shlib-undefined` so `ld.bfd` does not fail on unresolved
indirect `libclang_rt.asan.so` dependencies.
Assisted-by: Gemini