[Sema] Skip expansion statements when determing local extern context (#210512)
This bug showed up as a failed assertion that was asserting that if
not in a function or method context we should be in the global/file
context.
The root cause is that when determining the linkage context for a
decl we were failing to account for the existence of expansion
contexts. Ignoring the assertion failure, the functional effect of
this is that we would fail to detect incorrect local extern
declarations inside expansion contexts. The fix here is to make
sure that we use `getEnclosingNonExpansionStatementContext()` to
find the true DeclContext for the current scope.
The initial report only identified local extern function declarations
but the same bug occurred with extern var decls, but the path did
not lead to an assertion firing, just incorrect behaviour.
Thanks to Sirraide for explaining why this was going wrong, and
[3 lines not shown]
[libc][cpp::string] Do not include null terminator in capacity()
Currently, `capacity()` includes the null terminator of the backing buffer, which does not align with C++20's `std::string`. That is, `s.reserve(s.capacity())` should be a no-op. While there's no requirement these be in-sync, it is less surprising to align its behavior.
Also, this fixes the case where `reserve()` is called on an empty string, where previously the null terminator was not set.
[BOLT] Release pseudo-probe decoder after emit
Summary:
PseudoProbeRewriter builds sizable data structures and then
hold onto them after they are needed.
PseudoProbeRewriter::postEmitFinalizer() parses the input
.pseudo_probe sections into an MCPseudoProbeDecoder whose
address-to-probe and GUID-to-function-desc maps can be very large
(tens of GiB on big binaries with many probes). This is not used again
once probes have been updated, yet they survive into the memory-heavy
DWARF rewrite (updateDebugInfo), directly inflating BOLT's peak RSS at
the worst possible time.
This frees them at the end of the postEmitFinalizer() calls, before
updateDebugInfo runs.
[ProfileData] Split EagerSampleProfileNameTable by key type (NFC) (#211126)
This patch splits EagerSampleProfileNameTable into two separate
classes, EagerStringSampleProfileNameTable and
EagerMD5SampleProfileNameTable. This patch is meant to be a
preparation patch for centralizing and speeding up symbol membership
queries like "is this symbol in the name table?".
Currently, we have two problems with these membership queries:
- Customers build their own data structures like DenseSet<uint64_t> of
MD5 values and StringSet<> to serve those queries. That is, the
sample profile loader does not directly serve those queries.
- There are two places, namely SampleProfileLoader::doInitialization
and SampleProfileNameSet, where we build identical StringSet<> of the
name table entries, costing compilation time at both construction and
destruction time.
[17 lines not shown]
[Sema] Skip expansion statements when determing local extern context (#210512) (#211745)
This bug showed up as a failed assertion that was asserting that if
not in a function or method context we should be in the global/file
context.
The root cause is that when determining the linkage context for a
decl we were failing to account for the existence of expansion
contexts. Ignoring the assertion failure, the functional effect of
this is that we would fail to detect incorrect local extern
declarations inside expansion contexts. The fix here is to make
sure that we use `getEnclosingNonExpansionStatementContext()` to
find the true DeclContext for the current scope.
The initial report only identified local extern function declarations
but the same bug occurred with extern var decls, but the path did
not lead to an assertion firing, just incorrect behaviour.
Thanks to Sirraide for explaining why this was going wrong, and
[2 lines not shown]
[LifetimeSafety] Support field-sensitivity in lifetime tracking
This patch enables field-sensitivity when tracking lifetimes of nested objects.
- FactsGenerator now generates `PathElement::getField` for `MemberExpr` accesses, mapping fields to loans.
- LoanPropagation now propagates field paths along flow facts, appending fields to base loans.
- Removes false-positive warnings in `invalidations.cpp` where modifications to one field were incorrectly reported as invalidating iterators/pointers to another field.
- Adds comprehensive unit tests checking nested field access and placeholder fields.
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
[LifetimeSafety] Support container interior paths and invalidations
This patch completes the implementation of path-sensitive lifetime tracking by supporting container interior paths (`.*`) and deep-nested invalidation.
- Enables `PathElement::getInterior` generation in `FactsGenerator` for GSL Owners and Views (e.g. member functions, function parameters, lambda captures).
- Removes bypass checks in `FactsGenerator::handleInvalidatingCall` to track container invalidation on fields.
- Updates `Checker` to use strict prefix comparison (`isStrictPrefixOf`) for container invalidations, ensuring invalidation of container contents (interior) correctly invalidates iterators but not other sibling fields.
- Reorganizes tests in `invalidations.cpp` by resolving duplicates and distributing them logically.
- Updates unit tests and sema tests with correct expectations for interior paths.
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
[LifetimeSafety] Support field-sensitivity in lifetime tracking
This patch enables field-sensitivity when tracking lifetimes of nested objects.
- FactsGenerator now generates `PathElement::getField` for `MemberExpr` accesses, mapping fields to loans.
- LoanPropagation now propagates field paths along flow facts, appending fields to base loans.
- Removes false-positive warnings in `invalidations.cpp` where modifications to one field were incorrectly reported as invalidating iterators/pointers to another field.
- Adds comprehensive unit tests checking nested field access and placeholder fields.
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
[LifetimeSafety] Support container interior paths and invalidations
This patch completes the implementation of path-sensitive lifetime tracking by supporting container interior paths (`.*`) and deep-nested invalidation.
- Enables `PathElement::getInterior` generation in `FactsGenerator` for GSL Owners and Views (e.g. member functions, function parameters, lambda captures).
- Removes bypass checks in `FactsGenerator::handleInvalidatingCall` to track container invalidation on fields.
- Updates `Checker` to use strict prefix comparison (`isStrictPrefixOf`) for container invalidations, ensuring invalidation of container contents (interior) correctly invalidates iterators but not other sibling fields.
- Reorganizes tests in `invalidations.cpp` by resolving duplicates and distributing them logically.
- Updates unit tests and sema tests with correct expectations for interior paths.
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
[LifetimeSafety][NFC] Update Checker to use prefix comparison interfaces
This patch switches the Checker's expiry and invalidation checks to use `AccessPath::isPrefixOf` instead of equality (`==`).
Since all generated access paths are currently empty, `isPrefixOf` is behaviorally identical to `==` (NFC). This prepares the checker to handle nested paths (fields and container interiors) in subsequent commits.
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
[LifetimeSafety][NFC] Refactor AccessPath and Loan representations
This patch refactors the internal representations of `AccessPath` and `Loan` to support path elements, preparing for field-sensitive and interior-sensitive lifetime tracking.
- Introduces `PathElement` representing a field or interior dereference.
- Refactors `AccessPath` to contain a base and a list of `PathElement`s.
- Updates `Loan` and `LoanManager` to use the new `AccessPath` structure.
- Refactors debug dump formatting to output path elements if present.
- Updates Checker and FactsGenerator to compile with the new interfaces, keeping logic behaviorally identical (NFC).
TAG=agy
CONV=2cfd8d00-18d7-4a03-8d78-2aba2f9a8f23
Revert "[lldb] Remove ConstString from FileSpec" (#211927)
Reverts llvm/llvm-project#211394 as this introduces use-after-frees in
LLDB because we expect the underlying filename and directory to outlive
the FileSpec.
[flang-rt][cuda] Keep device-context cleanup probe from leaking a last-error (#211910)
The CUDA device runtime probes primary-context state during scope-exit
cleanup via a one-time
cudaGetDriverEntryPoint(`cuDevicePrimaryCtxGetState`) lookup. On some
runtime/driver combinations (e.g. a CUDA runtime newer than the
installed driver) that lookup fails and leaves a sticky error in the
thread's last-error slot. Since the probe runs between user kernel
launches, the user's next `cudaGetLastError()` misattributes the
leftover error to the launch, causing a spurious `invalid argument`
failure.
Fix: snapshot the last-error on entry and consume an error only if the
slot started clean, so the probe never leaks its own error and never
discards a pre-existing one.
Reproducer: a local device variable forces the guarded scope-exit device
cleanup on every call, so the probe's one-time lookup runs between the
two launches; the second `cudaGetLastError()` then observes the stale
[38 lines not shown]
[libc][cpp::string] Do not include null terminator in capacity()
Currently, `capacity()` includes the null terminator of the backing buffer, which does not align with C++20's `std::string`. That is, `s.reserve(s.capacity())` should be a no-op. While there's no requirement these be in-sync, it is less surprising to align its behavior.
Also, this fixes the case where `reserve()` is called on an empty string, where previously the null terminator was not set.
Fix clang-doc crash when comment contains invalid UTF-8 bytes (#210886)
When a source file comment contains non-UTF-8 bytes (e.g., byte 0x97),
clang-doc's JSONGenerator would crash with an assertion failure:
Assertion `false && "Invalid UTF-8 in value used as JSON"' failed.
This happens because json::Value(StringRef) asserts on invalid UTF-8
input in debug builds. While the release-build path calls fixUTF8()
automatically, the assertion crash affects developers and fuzzer runs.
Fix by following the same pattern used elsewhere in LLVM (lldb, clangd):
check isUTF8() before constructing a json::Value, and call fixUTF8() to
sanitize the string if invalid bytes are detected. This avoids an
unnecessary copy for the common case of valid UTF-8.
The fix covers all paths in serializeComment() where user-written text
from source comments enters JSON objects:
- CK_TextComment (I.Text)
[15 lines not shown]
[libunwind][arm64e] Mach-O Support unwinding PAuth_LR frames (#202772)
Under PAuth_LR, compact unwind entries marked UNWIND_ARM64_MODE_FRAME_PAUTH_LR are signed with the PC of the pacibsppc at the start of the range. The compiler may emit those entries with UNWIND_IS_NOT_FUNCTION_START when the pacibsppc is not the first instruction in the function; the unwinder must scan backwards past such entries to find the actual function start (and its LSDA pointer).
When unwinding a PAuth_LR frame, authenticate and re-sign using setIPPAuthLR(), which calls __builtin_ptrauth_auth_with_pc_and_resign when available, falling back to inline asm (autib171615 + pacib) for compilers that lack the builtin.
To reduce the size of Compact Unwind entries for shrinkwrapped frames, new offset bits encode the distance in multiples of 4 bytes from the range start to the pacibsppc. The compiler emits paired FRAMELESS/FRAMELESS+PAUTH_LR entries that the linker merges into a single FRAME_PAUTH_LR | (offset/4) << 12 encoding.
rdar://161907302&169746432&171118419
clang/AMDGPU: Migrate cc1 tests to subarch triples (8)
Rewrite SemaHIP cc1 test RUN lines to the new subarch triple form,
dropping the redundant -target-cpu.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
clang/AMDGPU: Migrate cc1 tests to subarch triples (7)
Rewrite the remaining small test directories (CodeGenCXX, Misc, Sema,
SemaCUDA, SemaCXX) cc1 RUN lines to the new subarch triple form, dropping
the redundant -target-cpu.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
clang/AMDGPU: Migrate cc1 tests to subarch triples (6)
Rewrite CIR/CodeGenHIP cc1 test RUN lines to the new subarch triple form,
dropping the redundant -target-cpu, and regenerate autogenerated CHECK
lines.
Co-authored-by: Claude (Opus 4.8) <noreply at anthropic.com>
[tsan][ppc64] Fix copy-paste bug in __sigsetjmp OPD TOC loading (#210589)
In `__sigsetjmp`'s big-endian OPD path, the TOC was loaded from
`_setjmp`'s OPD entry instead of `__sigsetjmp`'s own entry, due to a
copy-paste error.
```diff
- addis r2,r2,_setjmp-1b at ha
- addi r2,r2,_setjmp-1b at l
+ addis r2,r2,__sigsetjmp-1b at ha
+ addi r2,r2,__sigsetjmp-1b at l
```
This caused an incorrect TOC pointer to be loaded on big-endian PPC64
when `__sigsetjmp`/sigsetjmp was intercepted by TSan. The corresponding
`_setjmp` path (which uses label `0b`) correctly references its own
symbol for the OPD lookup.
Co-authored-by: pmr <prabhas at pmrs-MacBook.local>
[libc] Small correctness tweaks to GPU allocator (#211610)
Summary:
Small bugs, like more strict C++ lifetime ordering for the header and
fixing a bug in alignment sizing.
[Sema] Skip expansion statements when determing local extern context (#210512)
This bug showed up as a failed assertion that was asserting that if
not in a function or method context we should be in the global/file
context.
The root cause is that when determining the linkage context for a
decl we were failing to account for the existence of expansion
contexts. Ignoring the assertion failure, the functional effect of
this is that we would fail to detect incorrect local extern
declarations inside expansion contexts. The fix here is to make
sure that we use `getEnclosingNonExpansionStatementContext()` to
find the true DeclContext for the current scope.
The initial report only identified local extern function declarations
but the same bug occurred with extern var decls, but the path did
not lead to an assertion firing, just incorrect behaviour.
Thanks to Sirraide for explaining why this was going wrong, and
[3 lines not shown]
[Sema] Skip expansion statements when determing local extern context (#210512)
This bug showed up as a failed assertion that was asserting that if
not in a function or method context we should be in the global/file
context.
The root cause is that when determining the linkage context for a
decl we were failing to account for the existence of expansion
contexts. Ignoring the assertion failure, the functional effect of
this is that we would fail to detect incorrect local extern
declarations inside expansion contexts. The fix here is to make
sure that we use `getEnclosingNonExpansionStatementContext()` to
find the true DeclContext for the current scope.
The initial report only identified local extern function declarations
but the same bug occurred with extern var decls, but the path did
not lead to an assertion firing, just incorrect behaviour.
Thanks to Sirraide for explaining why this was going wrong, and
[6 lines not shown]
[libc] Add missing standard and Linux header macros (#211862)
Add missing header macro constants:
* endian-macros.h: __BYTE_ORDER, __LITTLE_ENDIAN, and __BIG_ENDIAN
* sys-stat-macros.h: S_IREAD, S_IWRITE, S_IEXEC, and ACCESSPERMS
* limits-macros.h: _POSIX_HOST_NAME_MAX and HOST_NAME_MAX
* unistd-macros.h: TEMP_FAILURE_RETRY
POSIX.1-2017 specifies _POSIX_HOST_NAME_MAX as 255. The Linux
gethostname(2) man page specifies HOST_NAME_MAX as 64. The
double-underscore byte order macros and TEMP_FAILURE_RETRY macro follow
the Linux and GNU C library conventions.
Assisted-by: Automated tooling, human reviewed.