[mlir][SparseTensor] Fix crash demapping alloc_tensor with a copy operand (#219319)
`TensorAllocDemapper` reconstructs demapped level sizes for a
`bufferization.alloc_tensor`/`tensor.empty` by pairing each dynamic
result
dimension with an entry from the op's `dynamic_sizes` operand list,
popping via
`ValueRange::front()`.
When an `alloc_tensor` has a `copy` operand instead of explicit dynamic
sizes,
`dynamic_sizes` is legitimately empty — the op's own verifier requires
that the
sizes are implied by the copy operand and must not be specified — so
`front()`
was called on an empty range and asserted:
```
llvm/include/llvm/ADT/STLExtras.h:1253: Assertion `!empty() && "expected non-empty range"' failed.
[20 lines not shown]
[VPlan] Compute SCEV for SDiv with non-negative operands. (#219715)
If both operands of an SDiv are known non-negative, it is equivalent to
an UDiv, mirroring ScalarEvolution's handling in createSCEV.
Adds m_SDiv to VPlanPatternMatch.
Alive2 Proof: https://alive2.llvm.org/ce/z/NYa6Vd
[LLVM][NFC] Make metadata-number checks robust (#219610)
These checks care about the metadata attached to an instruction or
reported in a diagnostic, not the incidental numeric slot assigned while
printing. Match metadata slot numbers with FileCheck patterns so
numbering changes do not require unrelated test updates.
[SLP]Recognize interchangeable cmp predicates with boundary constants
Treat boundary comparisons canonicalized to eq/ne (e.g. x <u 1 became
x == 0) as interchangeable with the rest of the bundle by adjusting
the compared constant, emitting a single vector compare.
Fixes #190505
Reviewers: RKSimon, bababuck
Pull Request: https://github.com/llvm/llvm-project/pull/218237
[clang-tools-extra] Add separate CLANG_TOOLS_EXTRA_INCLUDE_TESTS option (#215761)
clang-tools-extra tests depend on the llvm-bcanalyzer CMake target,
which exists in LLVM's CMake project but is not visible when Clang is
built separately from LLVM. This causes CMake errors when
CLANG_INCLUDE_TESTS is ON but the LLVM tools are not available.
This patch introduces CLANG_TOOLS_EXTRA_INCLUDE_TESTS as a separate
CMake option to control clang-tools-extra tests independently, allowing
users to build Clang with tests enabled (CLANG_INCLUDE_TESTS=ON) while
disabling clang-tools-extra tests (CLANG_TOOLS_EXTRA_INCLUDE_TESTS=OFF)
when building Clang separately from LLVM.
For backwards compatibility, CLANG_INCLUDE_TESTS=OFF continues
to turn off clang-tools-extra tests as well.
[analyzer] Fix handling of zero-sized elements in ArrayBound (#218712)
Previously the `security.ArrayBound` checker mishandled the following C
code under non-windows platforms where `sizeof(struct Empty) == 0`:
```c
struct Empty {};
struct Empty Array[10];
struct Empty foo(void) { return Array[5]; }
```
Here the checker produced a false positive with explanation "Access of
'Array' at byte offset 0, while it holds only 0 byte" -- that is, the
checker said that this accesses the past-the-end pointer, which is
usually invalid.
This commit suppresses this false positive by saying that accessing a
zero-sized object starting at the past-the-end pointer is valid.
This is implemented by adding an `AlsoAcceptEquality` flag for
`checkBounds`. This flag will also be useful for implementing checkers
[4 lines not shown]
[lld][WebAssembly] Do not coalesce segments with differing flags in -r (#219606)
In PR #210747 (commit 162d9f09299d), `addInputSegment` was changed to
union segment linking flags (`linkingFlags |= inSeg->flags`) so that
flags like `RETAIN` and `STRINGS` are preserved in `--relocatable`
output.
However, coalescing segments with differing linking flags by name alone
forces one chunk's semantics onto another:
- Clang emits ordinary string literals (`STRINGS`) and string literals
containing embedded null characters (non-`STRINGS`) into sections
named `.rodata..L.str`. When coalesced, non-mergeable segments
received the `STRINGS` flag, causing downstream links to split and
corrupt them.
- Similarly, coalescing a chunk with `RETAIN` and a chunk without
`RETAIN` forces the un-retained chunk to inherit `RETAIN`, preventing
`--gc-sections` from discarding it if it is unused.
Fix this by distinguishing segments by their linking flags in
[3 lines not shown]
[clang][Parse] Stop parsing declarator chunks after a parenthesized structured binding (#219270)
Fixes #218144
Fixes #193687
`ParseDirectDeclarator` stops right after a structured binding like `[a,
b]`, since nothing can follow it — but that check only covers the
unparenthesized form. For `([a, b])`, the binding gets parsed inside
`ParseParenDeclarator`, and the outer `ParseDirectDeclarator` doesn't
notice — it carries on into its suffix loop and parses a trailing `()`
as a function declarator. `([a, b])() {}` then looks like a function
definition, so `ActOnStartOfFunctionDef` gets handed a
`DecompositionDecl` where it expects a `FunctionDecl`:
`cast<FunctionDecl>` asserts, or segfaults later without assertions —
that's #193687. (The `b;` in the report is noise; `([a])() {}` alone
crashes.)
This patch makes `ParseDirectDeclarator` stop as well when the
parenthesized declarator turns out to be a structured binding, so
[8 lines not shown]
[SLP]Fix undef/poison matching in TreeEntry::isSame
Undef no longer matches poison mask elements (poison is stronger than
undef and its lane is unrecoverable); poison matches any lane.
Fixes #219631
Reviewers:
Pull Request: https://github.com/llvm/llvm-project/pull/219704
[IR] Add helpers to AllocaInst to avoid getAllocatedType(). (#219594)
Add AllocaInst::getAllocationBaseSize() and AllocaInst::isScalable(),
which represent common patterns for uses which only need the size of an
alloca, but can't use getAllocationSize().
This only replaces uses which are equivalent. (There are a couple of
places in DebugInfo which getTypeSizeInBits(), which is not equivalent,
so this patch doesn't touch them for now.)
[libc] Disable float16 on 32-bit x86 without SSE2 (#219675)
Fixes #219668
Building llvm 23.1.0 (and current main) for 32-bit x86 without SSE2
fails since APFloat.cpp started including libc's shared/math.h. All the
errors come from the float16 headers:
```
libc/src/__support/FPUtil/BasicOperations.h:63:67: error: SSE register return with SSE2 disabled
libc/src/__support/math/acosf16.h:73:14: error: invalid conversion from type '_Float16' without option '-msse2'
```
The float16 detection in float16-macros.h checks __FLT16_MANT_DIG__.
Since GCC 14 that macro is defined on ia32 even without SSE2, where
_Float16 is storage-only and any arithmetic or returning by value is an
error.
The GCC 14 release notes say to check __SSE2__ for arithmetic support
instead: https://gcc.gnu.org/gcc-14/changes.html
[9 lines not shown]
[X86] Fold ADC(SHL(X, 1), 0, Carry) to ADC(X, X, Carry) (#219512)
During DAG optimization, expressions like `a + a` are canonicalized to
`a << 1` (`ISD::SHL X, 1`).
We need to undo that if we can use adc x, x.
[InstCombine] Avoid creating redundant and in foldSelectICmpAndBinOp (#219676)
when the created shl shifts out all but one bit the and with one is not needed.
proof: https://alive2.llvm.org/ce/z/MQYp6f
[CIR][OpenCL] Lower OpenCL language version metadata to LLVM dialect
Propagate CIR OpenCL language version module attributes as LLVM dialect named metadata before LLVM IR translation.
Assisted-by: Codex / GPT-5.6 Sol
[CIR][OpenCL] Emit OpenCL language version metadata in CIR
Emit OpenCL and C++ for OpenCL language version attributes from CIRGen. Preserve the compatible OpenCL version and the C++ for OpenCL version separately so later lowering does not infer one from the other.
Assisted-by: Codex / GPT-5.6 Sol
[CIR][OpenCL] Add OpenCL language version module attributes
Add structured CIR module attributes for OpenCL and C++ for OpenCL language versions. Verify their module-level placement and version components so lowering can consume explicit source-language version state.
Assisted-by: Codex / GPT-5.6 Sol
[CIR][OpenCL][NFC] Add language address-space preservation coverage (#219678)
Expand coverage for preserving OpenCL language address spaces across CIR
textual representation and source emission before target lowering.
Assisted-by: Codex / GPT-5.6 Sol
[DAGCombiner] Make sure VT > SrcVT before doing ANY_EXTEND (#219674)
This happens when we have i1 (bitcast (v1i1 (scalar_to_vector i1))).
Fixes: #219637
Assisted-by: Claude Opus 4.8
[orc-rt] Add context to detectPageSize's sysconf error. (#219670)
It only reported the strerror text without context, so failure would
surface as a bare "Invalid argument" with nothing to say what failed.