[clang][CFG] Fix range-for iterator initialization order (#234467)
The CFG builder adds statements in reverse execution order. Add the
range-for end declaration before the begin declaration so that the
resulting CFG initializes begin before end.
This bug was introduced in **Clang 3.9.0**. Correcting the
initialization order also restores CFGScopeBegin markers for the hidden
range and begin variables. All three hidden variables now have matching
scope-begin and scope-end markers, with scopes ending in reverse order
in the loop’s scope-exit block.
Add a regression covering distinct iterator and sentinel types with
non-trivial destructors, checking initialization and reverse destruction
order with rich constructors both enabled and disabled. Update the
affected CFG dump expectations and lifetime-safety diagnostic
expectations.
Validation: all 28 selected CFG and range-for Analysis tests and all 24
[3 lines not shown]
[CIR][AArch64] Use CIR float types in getSVEType
getSVEType built the bf16 and f32 vectors from mlir::Builder's
getBF16Type() and getF32Type(), which return builtin MLIR types.
!cir.vector only accepts CIR element types, so an assertions build
aborts in VectorType::get and a release build creates an invalid type.
Use getBfloat16Ty() and getSingleTy(), as the f16 and f64 cases do.
No SVE builtin reaches these cases yet, so a lit test can't cover them.
Instead, CIRBaseBuilderTy now deletes mlir::Builder's builtin float
getters, so this mistake fails to compile.
Assisted-by: Claude Code (Claude Opus 5.5)
[LAA] Keep known dependences on retry with runtime checks (#231454)
Retrying with runtime checks cleared all recorded dependences, including
known dependences whose accesses are not checked against each other.
Interleaved access analysis could then reorder those accesses and hoist
a strided load across a store it depends on.
Drop only unknown dependences, which the runtime checks cover, and keep
known dependences to constrain reordering. This also keeps the ordering
for safe pairs that #232530 stops checking within erased classes.
The new case in `interleaved-accesses-retry-runtime-checks.ll` has an
interleave group that hoists the load of `A[2i]` above the previous
iteration's store to it; the existing case is fixed too. The LAA print
tests now list the kept dependences.
Assisted-by: Claude Code, Codex
[CIR] Restrict union tail padding to integers (#233897)
CIRGen pads a union's tail with !u8i or !cir.array<!u8i x N>, but the
verifier accepted any padding type. Other types broke consumers that
size the union: incomplete-record padding asserted in
computeStructSize, and scalable-vector padding made CallConvLowering
emit a byval of meaningless size.
The verifier now requires the padding to be an integer or an array of
integers. This also covers the earlier void-padding check.
Assisted-by: Claude Code (Claude Opus 5.5)
Reland "[mlir] Fix false positive loops in RegionBranchOpInterface::hasLoop"
Relands #233784, reverted in #234573 because it broke two CIR unit
tests.
Those tests expected hasLoop() to be true for cir.await and
cir.coroutine, although neither has a cycle: resume is reachable from
ready both directly and through suspend, and the coroutine reaches exit
and destroy along several paths. That was the false positive this change
fixes. The relanded change updates both expectations to false.
Original description:
`RegionBranchOpInterface::hasLoop` reported a loop whenever its
traversal popped a region it had already visited. The worklist gets one
entry per successor of each terminator, so a region reachable along two
paths was popped twice even without a cycle, for example when two
terminators of a region branch to the same successor region.
[8 lines not shown]
[X86] Expand f32-to-bf16 conversions without libcalls (#221225)
This adds a libcall-free fallback for f32-to-bf16 conversions when
native bf16 instructions are unavailable. It was split from #221052 so
it can be reviewed independently of the denormal-mode policy discussed
there.
X86 currently lowers these conversions to `__truncsfbf2`. Vector
conversions may be scalarized into one call per lane:
```asm
callq __truncsfbf2 at PLT
callq __truncsfbf2 at PLT
; ...
```
This change reuses the generic round-to-nearest-even `expandFP_ROUND`
implementation, producing ordinary integer operations instead:
[22 lines not shown]
[BOLT] Hand over test infra maintainer duties (#234103)
Former maintainer Paschalis Mpeis has handed over test infra maintainer
duties to Asher Dobrescu.
[llvm-c][IRBuilder] Restore LLVMBuilderRef unwrap (#234902)
This restores the public export of `unwrap(LLVMBuilderRef)` removed in
https://github.com/llvm/llvm-project/pull/234620. Rust uses it to extend
the C API with additional functions, which seems like a reasonable
enough use-case to support.
[clang][SPIR-V] Treat AMDGCN builtin pointers in AS 0 as generic (#234504)
In AMDGCN builtins AS 0 means flat, but SPIR-V reads it as Function
This broke flat atomics such as __builtin_amdgcn_flat_atomic_fadd_v2f16
[libc] Enable baremetal Armv7-M pre-merge tests
The tests are run using QEMU system emulation on AArch64 GitHub runners.
No strong reason to use AArch64 instead of x86_64 as it is via emulation
anyway. But AArch64 runners are cheaper, so that might prove beneficial.
[libc] Application and testing support in baremetal Armv7-M CMake cache file
This patch adds support for linking and running applications, including
tests, targeting baremetal Armv7-M to the corresponding CMake cache
file.
The cache file takes into consideration if compiler-rt is enabled or
not. If it is, then linking applications is possible, and the relevant
CMake variables are set to enable test runs. If not, then only the libc
build is possible and enabled.
Particular libc configuration options, memory mappings, and QEMU options
are based on what Arm Toolchain for Embedded uses in its fully working
downstream testing.
[InstCombine] Simplify select arms using the select condition (#232738)
Extend the select-arm simplification in visitSelectInst() to selects of
any type, rather than only integers. If an arm uses an inner select with
the same condition, it can be resolved while simplifying the arm. For
pointers, this enables the existing fold of a select of two GEPs with a
common base:
%base = select i1 %c, ptr %p, ptr null
%left = getelementptr i8, ptr %base, i64 48
%right = getelementptr i8, ptr %p, i64 40
%result = select i1 %c, ptr %left, ptr %right
-->
%result = getelementptr i8, ptr %p, i64 (select i1 %c, i64 48, i64 40)
This occurs in clang's CodeGenFunction::EmitCXXConstructorCall
(llvm-opt-benchmark CGClass.bc).
Fixes https://github.com/llvm/llvm-project/issues/232620
[libcxx] [ci] Update the Windows llvm-mingw compiler (#234632)
Update to llvm-mingw release 20261020, which contains LLVM 23.1.4.
The previous version was based on LLVM 21.1.x. In 22.1.0 there was an
important fix for the code generation for generated calls to atomics
helper functions on x86_64 (#136428, #181356).
Also, use 7z instead of powershell Expand-Archive for unpacking
llvm-mingw. The powershell Expand-Archive command can be notably slow,
see https://github.com/PowerShell/PowerShell/issues/3355.
7z is included in the list of officially supported/included applications
on the Github Actions Windows images, so we can rely on it.
[DSE] Bail out if Size + Offset wraps index width. (#229760)
sOverwrite compares the constant offsets of both accesses as int64_t,
but ignores that Offset + Size may wrap the index width. Add a
bail-out to fix miscompile.
PR: https://github.com/llvm/llvm-project/pull/229760
[LV] Support pointer inductions in outer-loop path (#231921)
Accept outer-loop header phis that are pointer inductions in addition to
integer inductions.
As in the inner-loop path, pointer inductions with a non-constant step
are only accepted with -lv-strided-pointer-ivs. Move that check to a
helper shared by both paths.
[SLP][NFC] Collect demotion operand entries by the actual operand count (#234511)
collectValuesToDemote() hard-codes two operand entries for the shift and
unsigned division cases, while the binary-operator case already maps
over getNumOperands() because a flattened (reassociated) node has one
entry per column. Hoist that mapping into a GetOperandEntries() helper
and use it for all of them. The shift and division nodes are never
flattened, so they keep their two operands and the behavior is
unchanged.
Co-authored-by: Balakrishna Bandlapalli <bbandlap at gmail.com>
Co-authored-by: Cursor <cursoragent at cursor.com>
[lldb] Make GetDeviceSupportDirectoryForOSVersion thread-safe (#234132)
This change fixes an active crash/memory corruption in LLDB.
Target::RebuildModuleListWithExecutable loads the dependent modules of
an executable in parallel on the debugger's thread pool. On a device
platform such as remote-ios, each of them goes through
PlatformRemoteDarwinDevice::GetSharedModule and
GetSharedModuleWithLocalCache, which call
PlatformDarwinDevice::GetDeviceSupportDirectoryForOSVersion. That
function fills m_device_support_directory_for_os_version lazily and
without a lock, so the first callers can assign the same std::string at
the same time. DeviceSupport paths are too long for the small string
buffer, so this can free the same buffer twice or otherwise corrupt the
heap. Depending on the allocator, that goes unnoticed or crashes lldb,
either right there or later in unrelated code. Setting
target.parallel-module-load to false doesn't help, because it doesn't
apply to loading dependent modules.
[14 lines not shown]
[SelectionDAG] Convert f16 to wide integers without a libcall (#230779)
Finite `f16` values are below 2^16 in magnitude, so any `f16` to integer
result fits in `i64`. Currently when the result type must be expanded
(e.g., `f16` -> `i128` on 64-bit targets), `ExpandIntRes_FP_TO_XINT`
always emit libcall. Some of these libcalls do not exist on some targets
(#231121), and on Win64 with AVX512-FP16 the X86 lowering of f16 to i128
is wrong.
Convert to the half-width type and fill the high half with the sign bit
or zero, adds the missing i64 check on the 32-bit path on X86. On Win64,
X86 now leaves f16 to this generic expansion.
Fixes #230703
Assisted-by: Claude Opus 5.5
[mlir][gpu] Split target-specific passes out of MLIRGPUTransforms
MLIRGPUTransforms linked every GPU target: the AMDGPU, LLVM, ROCDL and
XeVM dialects, plus MLIRNVVMTarget, MLIRROCDLTarget, MLIRSPIRVTarget
and MLIRExecutionEngineUtils. So any user of any target-specific or
target-independent GPU pass also pulled in every target's dialect
and serialization library.
Move the target-specific passes and patterns into one library per
target. Each has its own Passes.td and Passes.h and links only its
own target dialect.
MLIRGPUTransforms no longer has any target dependencies at all.
Co-authored-by: Claude <noreply at anthropic.com>