[lld][MachO] Avoid redundant work in Writer::scanRelocations()
During relocation scanning, `Writer::scanRelocations()` looks up
`target->getRelocAttrs(r.type)` up to three times per symbol relocation
(in `scanRelocations()`, `validateSymbolRelocation()`, and
`prepareSymbolRelocation()`), tests `r.referent` twice for symbol
referents, and makes an out-of-line call to `validateSymbolRelocation()`
on every symbol relocation even though it only rejects two rare
thread-local-variable cases.
Move `validateSymbolRelocation()` (whose only caller is
`Writer::scanRelocations()`) into `Writer.cpp`, split the rare TLV
validation logic into a `LLVM_ATTRIBUTE_NOINLINE` helper, and mark
`DylibSymbol` `final` so `dysym->isTlv()` avoids a virtual call on the
fast path. Fetch `RelocAttrs` once per relocation, pass it to
`validateSymbolRelocation()` and `prepareSymbolRelocation()`, hoist
loop-invariant `target->relocAttrs` and `config->emitChainedFixups`, and
dispatch on `r.referent` once for non-subtractor relocations.
[sanitizer] Ensure suppression files' buffer is null terminated. (#236826)
Function ReadFileToBuffer does not terminate string 'file_contents'.
SuppressionContext::Parse internal_strcspn expects a null-terminated
string.
The issue was found through static analysis.
[llvm] Remove unused forward declarations (NFC) (#246828)
This patch removes unused forward declarations of classes and structs
across llvm/ that are not referenced in the same file.
Assisted-by: Antigravity
[tsan] Intercept C11 mtx_* functions on glibc (#239670)
glibc implements the C11 mutex functions with its internal pthread_mutex
functions, so TSan doesn't see C11 mutexes being locked and unlocked and
reports false data races on the data they protect (#199585).
Intercept mtx_init, mtx_destroy, mtx_lock, mtx_trylock, mtx_timedlock
and mtx_unlock, forwarding to the real functions and doing what the
pthread_mutex interceptors do. mtx_recursive makes the mutex reentrant.
To avoid hardcoding C11 constants, forward mtx_plain, mtx_recursive and
mtx_timed enum values to sanitizer_platform_limits_posix.
Enable c11_mtx.c for TSan on glibc.
Assisted-by: Claude
[SanitizerCoverage] Use InstrumentationIRBuilder for gated callbacks (#244789)
Gated callback paths in InjectTraceForSwitch(), InjectTraceForCmp(), and
InjectCoverageAtBlock() used a plain IRBuilder instead of
InstrumentationIRBuilder, and InjectCoverageAtBlock() did not propagate
EntryLoc. When the split point has no debug location in a function with
a DISubprogram, the inserted runtime call lacked a !dbg location.
Assisted-by: Gemini
[LV] Expand runtime checks in SafeUDivMode. (#246863)
The SCEV predicate checks, memory runtime checks and alias-mask checks
are executed unconditionally before the vector loop, but may contain a
udiv that the original loop only evaluates in a predicated block, e.g.
for an address computed from a udiv under a condition that is never
true. Expanding it unguarded divides by zero or poison.
Expand them in SafeUDivMode, matching the expansion of
VPExpandSCEVRecipes. canExpandInIR no longer bails out in SafeUDivMode,
as it only accepts expressions that cannot cause UB, so hoisting of
memory checks out of outer loops is unchanged.
PR: https://github.com/llvm/llvm-project/pull/246863
[NFC][sanitizer_common] Flip the AIX build guard to positive (#246155)
https://github.com/llvm/llvm-project/pull/138606 added build guard
`SI_NOT_AIX`. It's a negative flag and easy to cause confusing on
double-negative.
This PR flips the flag to positive and updates all of the usages.
Assisted-by: Gemini
[Clang][CodeGen] Plumb SourceLocation to virtual dtor and thunk calls (#245522)
Forward the call or delete expression location through
EmitCXXDestructorCall
and EmitVirtualDestructorCall, and pass the method location from
getOrCreateVirtualFunctionPointerThunk to EmitCall.
Previously, these paths passed an empty SourceLocation to EmitCall,
causing
call-site diagnostics such as target-feature errors on virtual
destructors
(both Itanium and Microsoft ABIs) to be emitted without a file or line
number. This also prepares for passing call-site locations to UBSan kCFI
diagnostics in follow-up changes.
Assisted-by: Gemini
[CodeGen][MachineOutliner] Do not outline nomerge instructions (#245435)
Instructions carrying MachineInstr::NoMerge must retain distinct call or
trap addresses so crash reports and debuggers can attribute faults to
specific sites. Classify NoMerge instructions as Illegal in
TargetInstrInfo::getOutliningType so MachineOutliner does not merge them
into shared outlined functions.
Assisted-by: Gemini
[Attributor] Use call site values when the callee returns an argument
AAPotentialValuesCallSiteReturned takes the interprocedural values of a call
from the interprocedural return values of the callee. If the callee returns one
of its arguments, these values contain the arguments of all call sites, so each
call result also gets the values passed at all other call sites. This is not
necessary. If the callee has many call sites and the call results are passed to
other calls, the value sets also become very large.
If the callee returns only its arguments and constants, we just need to
translate these values to the call site for the interprocedural scope.
This PR was assisted by AI but I reviewed all the changes.
[test][SanitizerCoverage] Precommit gated-callbacks debug info test (#245528)
Add a gated-callbacks RUN line to missing_dbg.ll showing that gated
runtime calls currently drop !dbg locations in functions with debug
info.
Assisted-by: Gemini
[SystemZ] Lower llvm.clmul with VGFM
Mark ISD::CLMUL and ISD::CLMULH Custom for i32, i64, v16i8, v8i16,
v4i32 and v2i64 when the vector facility is available, and select them
with VGFM{B,H,F,G}. i8/i16 are promoted to i32 by the generic
legalizer. CLMULR is built from CLMUL and CLMULH by the generic
expansion.
VGFM XORs the products of each even/odd element pair, so a vector
multiply masks one operand to the even and odd elements, issues two
VGFMs, and permutes the requested half of each product into place.
Scalars use VGFMG on (x, 0) vectors.
llvm.clmul.i64 previously expanded to ~66 instructions and
<2 x i64> to ~380.
Multiplication by a mask of 2^N trailing ones is a prefix XOR and stays
on the generic GPR shift/XOR expansion. For i8/i16 this is decided in
ReplaceNodeResults, before promotion widens the mask. This keeps the
[3 lines not shown]
[test][msan] Add AVX512 origin test for PMOV mem intrinsics (#246150)
Add avx512-origins.ll for origin tracking corner cases of AVX512
intrinsics; shadow propagation stays in avx512*-intrinsics.ll.
Start with PMOV mem intrinsics, which are currently strictly handled:
each destination element width, a store smaller than an origin slot,
the widest store, and an aligned destination, so the upcoming handler
change shows the origin diff.
Needed by #240973.
Assisted-by: Gemini
[clang] Add IWYU export pragma to NestedNameSpecifier.h (NFC) (#246865)
This patch adds an IWYU export pragma for NestedNameSpecifierBase.h in
NestedNameSpecifier.h. Without this patch, clang-include-cleaner
treats transitive includes of NestedNameSpecifierBase.h as sufficient
for NestedNameSpecifier uses and flags NestedNameSpecifier.h as unused.
Note that #159154 already added the same pragma to Type.h for
TypeBase.h.
Assisted-by: Antigravity
[clang] Remove unused includes (NFC) (#246829)
This patch removes unused #include directives across .cpp files under
clang/. Identified by clang-include-cleaner and verified locally.
Assisted-by: Antigravity
[tsan] Intercept pthread_clockjoin_np on Linux (#240051)
glibc 2.31 introduced pthread_clockjoin_np. Without an interceptor,
joining a thread via pthread_clockjoin_np does not consume its user_id
from ThreadRegistry::live_. When glibc subsequently reuses the pthread_t
value for a new thread, ThreadCreate trips a CHECK-abort on the
duplicate user_id in live_.try_emplace.
Add TSAN_INTERCEPTOR for pthread_clockjoin_np on Linux, register glibc
2.31 in lit configuration, and add a regression test covering timeout,
synchronization, and thread reuse across clocks.
Fixes #239326
Assisted-by: Antigravity
[CMake] Enable -Werror=global-constructors for clang/lib (#246753)
Like #239678, enforce
llvm.org/docs/CodingStandards.html#do-not-use-static-constructors in
Clang builds for clang/lib source files.
List the libraries that still have C++ dynamic initializations so that
the others cannot gain new ones.
Examples: Remove cl::opt, make the constructor `constexpr` (#223903),
move globals with ctor/dtor out of headers, or into a function-local
static (#234442)
LLM-aided
[lldb] Declare darwin-log enable options in TableGen
The --filter option of `plugin structured-data darwin-log enable` took
eArgRawInput, which describes free-form text passed after ' -- ' and so
contradicts how the option works: each --filter takes one rule, which
must be quoted if it contains spaces, and the option may be repeated.
Replace it with the newly introduced eArgTypeDarwinLogFilter and declare
the options of the command in TableGen like the other commands.
This was the only use of eArgRawInput as an argument type. The
corresponding entry in the option argument table is kept so that
`help raw-input` still works.
The multi-line description of --filter contains manual formatting, but
apparently it has been broken since 23dffff4 (tracked by #246769).
Assisted-by: Claude
[lldb] Declare OptionGroupPlatform options in TableGen (NFC)
Add TargetOptions.td for the options of the option groups in
lldbTarget and move the options of RSync/Caching/SSH there.
Assisted-by: Claude
[lldb] Declare OptionGroupValueObjectDisplay options in TableGen
The --dynamic-type option is an enum, but it was declared without an
argument type, so `help` printed "-d <none>" and the option was not
described as an enumeration:
```
$ (lldb) help dwim-print
-d <none> ( --dynamic-type <none> )
Show the object as its full dynamic type, not its static
type, if available.
Values: no-dynamic-values | run-target | no-run-target
$ (lldb) help <dynamic-value-type>
error: '<dynamic-value-type>' is not a known command.
```
This is now fixed, as shown in the added test.
Assisted-by: Claude
[lldb] Declare OptionGroupWatchpoint options in TableGen
Add eArgTypeWatchType to the argument table so that `help watch-type`
can find it and print the valid values.
Assisted-by: Claude
[lldb] Declare OptionGroupVariable options in TableGen (NFC)
GetDefinitions() omits the four frame-only options by dropping the
leading definitions. Make sure TableGen emits them first by giving
their `def`s appropriate names.
--regex options takes no argument (it is a boolean flag) but was
declared with eArgTypeRegularExpression. It is eArgTypeNone now.
Assisted-by: Claude
[lldb] Declare OptionGroupFormat options in TableGen
Declare the options in alphabetical order and adjust C++ counterpart
accordingly, since it relies on the order of options to "hide" some of
them. Use named positions instead of the hardcoded 0...3.
Assisted-by: Claude