[libc++] Fix cfi-unrelated-cast failures in allocator, __new_at_least, and shared_ptr
Fix three `cfi-unrelated-cast` failures in libc++ headers discovered while bringing up a CFI CI job (https://github.com/llvm/llvm-project/issues/245696):
- Annotate `__operator_new_wrapper` in `__memory/allocator.h` with `_LIBCPP_NO_SANITIZE("cfi-unrelated-cast")`. Commit edad54e08d3b (https://github.com/llvm/llvm-project/pull/229771) replaced `__libcpp_allocate` (which had `_LIBCPP_NO_CFI`) with `__operator_new_wrapper`, so Clang's `matchesStlAllocatorFn` exemption no longer applies to its `static_cast<_Tp*>` on uninitialized memory.
- Annotate `__new_at_least<_Tp>` in `__new/new_at_least.h` with `_LIBCPP_NO_SANITIZE("cfi-unrelated-cast")`. Commit f59521e7ec81 (https://github.com/llvm/llvm-project/pull/215813) introduced a `static_cast<_Tp*>` on freshly allocated `void*` memory that breaks polymorphic `std::vector` allocations across standard modes.
- Construct `_ControlBlock` directly with placement `::new (static_cast<void*>(...))` in `__allocate_shared_unbounded_array` (`__memory/shared_ptr.h`), matching `__allocate_shared_impl`, instead of casting uninitialized storage to polymorphic `_ControlBlock*` before construction. (Bounded arrays already allocate `_ControlBlock` directly and do not trigger a cast check.)
Assisted-by: Gemini
[GVN] Process Foldable Terminator beforehead
GVN generates phi node to replace a load call. However, addDeadBlock
modify such phi so that any deadblock sucessor in a phi becomes
poison.
This causes disagreement on SSAUpdater as [%a, %b1] [poison, %b2] is
considered as different with [%a, %b1] [0, %b2] even if poison is
replace with 0.
As a result, we make processFoldableTerminator (which is the only
caller of addDeadBlock now) runs before processInstruction. This is
before what we have on phi node generation so that non of the mismatch
happens.
Asissted-by: Claude # Test
Revert "[libc++] Add __repeat_iterator and use it in the sequence containers (#240378)" (#248213)
This reverts commit 484552add0fb92195f2e3f70734adf4a57f8ebc0.
This breaks std::vector::insert(const_iterator, size_type, const_reference)
in C++23 (-std=c++23 -stdlib=libc++), leaving newly inserted elements appended
at the end of the vector instead of at pos when n > (end - pos) and
n <= __remaining_capacity(), which is actively breaking builds in our CI.
See https://github.com/llvm/llvm-project/pull/240378#issuecomment-7322947076
for the minimal C++23 reproducer and root-cause analysis:
1. __repeat_iterator lacks a default constructor, so it does not model
std::forward_iterator in C++20/23 (and lacks relational operators for
std::random_access_iterator).
2. In vector::__insert_with_size, the C++23 !forward_iterator path calls
std::rotate(__p, __old_last, __end) with a stale cached __end (== __old_last)
instead of __layout_.__end_ptr() (a latent regression from bd338806e423 /
#155330, which already has an open fix in #229763).
Verified that this clean revert builds libc++/libc++abi/libunwind and makes the
minimal C++23 reproducer pass (Result (5): 1 9 9 9 2).
[mlir][EmitC][MLGO] Emit reflectionSizeMap in mlgo-add-reflection-map (#242627)
Let callers check the byte size of a field before writing through
reflectionMap
User: In MLGO input shapes became runtime options since #224598, so a
compiled field can be smaller than the tensor, this PR is a prerequisite
for #242629
[SPIR-V] Restore image, sampler, event and queue types from MIR (#247729)
Without them, -start-after crashes when instruction selection looks up
these types
Signed images are recovered from their OpName
[analyzer][NFC] Out-line CheckerManager::CheckerTags accessors (#248205)
- `CheckerManager::getChecker` and `isRegisteredChecker` are templates
instantiated in every checker TU. Their inline `DenseMap<void *,
std::unique_ptr<CheckerBackend>>` lookup/insert code was therefore
re-instantiated and re-compiled in each of them.
- Route both through the new private out-of-line members
`getCheckerSlot` and `hasCheckerWithTag`, defined in
`CheckerManager.cpp`.
- `getChecker` runs only at checker registration, so there is no
analysis run-time cost.
Build-time impact (instructions retired, 196 `lib/StaticAnalyzer` TUs):
- Total: -0.77% median (-0.12..-0.88% over 5 paired sweeps, noise 0.2%).
Run-time impact (analyzer, 20 TUs of clang/lib/{AST,Sema,Parse,CodeGen},
elapsed cycles, 10 interleaved rounds per binary, before = merge base
a26d5a8):
- Result: no slowdown detected. Median of per-round totals -0.32%: no
[9 lines not shown]
[analyzer][NFC] Drop `SourceManager.h` from `CallEvent.h` (#248179)
- `CallEvent::isInSystemHeader` was the only user of `SourceManager` in
`CallEvent.h`, yet its inline body made every includer of the header
parse `clang/Basic/SourceManager.h`. Move the body into `CallEvent.cpp`
and drop the include.
- Include `clang/Basic/SourceManager.h` explicitly in
`ErrnoChecker.cpp`, `ErrnoModeling.cpp`, `LocalizationChecker.cpp`,
`NullabilityChecker.cpp`, `VirtualCallChecker.cpp` and
`ExprEngineCallAndReturn.cpp`, which relied on it transitively.
Build-time impact (instructions retired, 196 `lib/StaticAnalyzer` TUs):
- Total: -0.79% (5 paired sweeps, all faster; run-to-run noise 0.3%).
- 140 TUs change by more than 0.15%, by -1.07% over those (net,
including the TUs that regain the include).
Run-time impact (analyzer, 20 TUs of clang/lib/{AST,Sema,Parse,CodeGen},
elapsed cycles, 10 interleaved rounds per binary, before = merge base
a26d5a8):
[9 lines not shown]
[analyzer][NFC] Out-line `CheckerContext::addTransitionImpl` (#248181)
- `CheckerContext::addTransitionImpl` is reached from every
`addTransition` overload and instantiated `CoreEngine::makeNode` and the
`ExplodedNodeSet` calls in every checker TU. Move it into
`CheckerContext.cpp`.
Build-time impact (instructions retired, 196 `lib/StaticAnalyzer` TUs):
- Total: -1.23% (4 paired sweeps, all faster; run-to-run noise 0.2%).
- 97 TUs change by more than 0.15%, by -2.5% over those.
Run-time impact (analyzer, 20 TUs of clang/lib/{AST,Sema,Parse,CodeGen},
elapsed cycles, 10 interleaved rounds per binary, before = merge base
a26d5a8):
- Result: no slowdown detected. Median of per-round totals -0.12%: no
slowdown; total cycles are slightly lower (95% CI -0.21%..-0.08%
excludes zero).
- Total per round (%): -0.05, -0.12, -0.20, -0.11, -0.32, -0.02, -0.01,
-0.30, -0.10, -0.19.
[5 lines not shown]
[NVPTX] Fold predicate only when it has one user (#248159)
This is a perf fix for 9386502801a033a676d9dce8ca8482c0d50e4f43. Folding
the predicate is not beneficial if there are multiple users. In that
case the shared predicate can be kept in a register and we need a
shorter code sequence in the final codegen.
[mlir][python][dsl] Move the DSL to mlir/python/mlir/dsl
The package moves from mlir/tools/mlir-dsl to the root Python package and
its tests to mlir/test/python/dsl, so they use the lit configuration of the
Python bindings. The MLIR_ENABLE_PYTHON_DSL option and the check-mlir-dsl
target are removed: the DSL is built and tested with the bindings.
Co-Authored-By: Claude Fable 5.2 <noreply at anthropic.com>
[Attributor][NFC] Remove AAValueSimplify
Unused since bf789b1957ef replaced it with AAPotentialValues. Seed
AAPotentialValues instead in allow_list.ll.
Co-Authored-By: Claude Opus 5.5 <noreply at anthropic.com>
[ValueTracking] Fix arg conflation in ComputeMaxSignificantBits (#248129)
The function llvm::ComputeMaxSignificantBits passes a Depth integer in
place of the UseInstrInfo boolean to ComputeNumSignBits, which was
unflagged to date due to implicit conversions. Fix this.
Assisted-by: llm, for testing
[flang] Optionally warn when a structure constructor nulls a pointer subcomponent (#247865)
When a structure constructor omits a component whose type has default
initialization, that component gets the default initialization.
In the case where a pointer subcomponent has no initializer of its own,
the standard (F'2023 7.5.10 p3, 19.5.2.2 p1, 7.5.4.6 p7) specifies that
it is undefined. However, flang makes such a pointer subcomponent
NULL().
This PR adds a usage warning for it which is off by default. The
warning is enabled by -pedantic or -Wdefault-init-null-pointer.
The existing -Wdefault-struct-constructor-null-pointer warning catches
cases
where the pointer is omitted directly. This PR and
-Wdefault-init-null-pointer
cover a pointer nested inside an omitted component.
Follow-up to #247370.
Assisted-by: AI
[PowerPC] Enable SlotIndexes compaction by default
Greedy measures live ranges in slot indexes, and instructions erased
before allocation (by PHI elimination, two-address lowering and the
coalescer) leave entries behind that make ranges look longer than
they are. Opt PowerPC in to dropping them, as AMDGPU and ARM do, so
allocation works with real distances. Passing
-greedy-compact-slot-indexes=false restores the old behaviour.
On CTMark (pwr8, pwr10, AIX, ppc32), .text and llc compile time move
by less than 0.03% and evictions drop by 1.5-5.8%.
The test updates are register allocation changes; csr-split.ll gets
back the live range split it was written to check.
[RISCV] Fix RVV callee-saves in realigned frames
The prologue saves RVV callee-saved registers before it realigns SP
and sets up BP, but their slots were addressed from the realigned SP
or BP. The epilogue reloaded them from the wrong address, BP frames
stored them through the caller's s1, and their CFI was wrong.
Address these slots from FP, which does not move, and derive their
CFI from getFrameIndexReference so the two cannot diverge.
Fixes #244792
[RISCV] Add tests for RVV CSRs in realigned frames
Precommit the tests for #244792 so that its fix shows up as a diff.
The checks record the current, wrong output: the prologue saves the
vector callee-saved registers before it realigns the stack, and the
epilogue reloads them from a different address.
Don't treat distinct literal substrings as equal
Expression equality compares dummy arguments by position, as needed
when comparing interfaces (F2023 15.3.2.2). As a result, a host dummy
and an internal procedure dummy at the same position currently compare
equal, even though they are distinct entities (19.5.1.4).
This was not a problem before because literal substrings never compared
equal, so their bounds were never considered. Now that literal
substrings are compared by value, 'ab'(i:i) with host dummy i compares
equal to 'ab'(j:j) with internal dummy j. This can cause Semantics to
reject valid code, such as an ATOMIC READ of a(iachar('ab'(j:j))) into
a(iachar('ab'(i:i))).
For literal substring bounds, only match dummy arguments by position
when neither procedure is nested within the other.
Lowering's own expression equality compared literals by name(), which
is never set, so any two literals compared equal. Since Semantics now
[6 lines not shown]
[lldb] Publish the attaching state before sending the attach request (#245632)
When attaching to a process that was connected before the attach (e.g.
`process connect` followed by `process attach --waitfor`), the private
state thread is already running, so Process::Attach has to publish
eStateAttaching itself. It only did so after
DoAttachToProcessWithName/ID returned, but by then the attach request
may already be on its way to the server.
TestAttachWaitConnected.py shows the resulting race:
1. The test calls SBTarget::Attach with a wait-for attach info.
Process::Attach calls DoAttachToProcessWithName, which hands the
vAttachWait packet to the gdb-remote async thread and returns.
2. The mock server receives vAttachWait, and the test immediately calls
SBProcess::SendAsyncInterrupt to cancel the attach.
3. Process::SendAsyncInterrupt sends eBroadcastBitInterrupt to the
[14 lines not shown]
[lld][MachO] Stream FunctionStartsSection from laid-out code sections (#247021)
Currently, `FunctionStartsSection::finalizeContents()` scans every
`ObjFile`'s full symbol table, resolves `defined->getVA()` for each live
code symbol, and sorts all addresses with `llvm::sort`.
By the time `FunctionStartsSection::finalizeContents()` runs, output
segments, their sections, and each `ConcatOutputSection`'s inputs are
already laid out in ascending virtual address order, and each input
section's `symbols` list is kept sorted by offset. This PR walks those
laid-out code sections directly.
To avoid calling `isCodeSection()` on every subsection, we add an
`isCodeSection(const Section &)` overload and cache its result across
consecutive inputs sharing the same originating `Section`. This targets
the common case where most subsections remain in their original input
order (even under an order file, non-code sections and unprioritized
code sections stay grouped by `Section`).
[13 lines not shown]
[CIR] Emit the object of an inherited static call operator
Sema converts the object argument of an inherited static operator() or
operator[] to the base class with a CK_NoOp cast, not a derived-to-base
conversion. emitCastLValue rejects a CK_NoOp that changes the record
type and reports errorNYI.
emitCall now drops that cast before emitting the object as an ignored
expression. The object is never read, so the cast has no effect on the
IR. emitCastLValue still rejects every other record-changing CK_NoOp.
This change does not handle CK_AddressSpaceConversion, which Sema uses
when the object is in a different address space.
libc++'s ranges::begin, ranges::end and ranges::data now inherit a
static operator() from std::_CPO. Without this change, 860 libc++ std/
tests fail to compile under -fclangir.
Assisted-by: Cursor / Claude Opus 5.5