[lldb] Remove ConstString from DynamicRegisterInfo (#243644)
RegisterInfo and RegisterSet both have `const char *` values. In many
cases, they are backed by static data and so their lifetime is
guaranteed. The one case where this is not true is DynamicRegisterInfo.
DynamicRegisterInfo produces RegisterInfo and RegisterSet objects for
register information that lldb is not aware of ahead of time. Currently
it stores strings in the ConstString pool to guarantee their lifetimes
for the remainder of lldb's run time. As a part of removing ConstString
from LLDB in general, this change ties those strings to the lifetime of
the DynamicRegisterInfo itself.
There are a few cases where RegisterInfo objects are pulled out of
DynamicRegisterInfo or a DynamicRegisterInfo object is copied. Those
cases are handled carefully, sometimes with ConstString, to make sure we
are not producing dangling pointers. Future changes will fix them.
[libLTO] Apply late -mllvm options to the target options (#244090)
lto_codegen_debug_options and lto_codegen_debug_options_array only
record the options. They are parsed when the first output is produced,
but the target options, including the MC options, are read from the
library options when the generator is created. Options that ld64 passes
with -mllvm, such as -macho-relocatable-dwarf or
-nozero-initialized-in-bss, were parsed and then ignored.
Read the target options again after the late options are parsed.
lto_set_debug_options and thinlto_debug_options parse before the
generator is created and are unchanged.
[InstCombine] Check the select type in the usub.sat sign mask fold
`foldICmpUSubSatWithAndForMostSignificantBitCmp` replaces a select with an
`and` that has the type of the `usub.sat` operands. When the select has a
different type, the replacement hits the assertion "replaceAllUses of value
with new value of different type!".
This PR skips the fold in that case.
This PR was assisted by AI but I reviewed all the changes.
[VPlan] Remove ExtractLastPart when unrolling with UF 1. (NFC) (#244304)
ExtractLastPart is meant to be removed by unrolling, but with UF 1
unrollByUF returned early and left it in place; simplifyRecipe folded it
later, after replicateByVF. Remove it in unrollByUF's cleanup for any UF
instead. Nothing creates ExtractLastPart after unrolling since the
previous commit, so the fold in simplifyRecipe is no longer needed.
This is needed to lower lane extracts of replicated values directly in
replicateByVF in a follow-up. The generated IR does not change.
PR: https://github.com/llvm/llvm-project/pull/244304
[NFC] Use std::optional<uint64_t> for AAMDNodes::extendTo (#244301)
Non-functional change to simplify the helper functions for AA metadata
extension to different sizes.
This was requested in review of #240267.
Assisted by Claude
[lldb] Define SB API special members out of line (#241980)
When liblldb is built with clang-cl and `/Zc:dllexportInlines-`, inline
members are not exported from liblldb.dll. A client compiled without the
flag then fails to link.
This changes the SB API to declare and define out of line copy
constructors, copy assignment and destructors, following the guidance in
`docs/resources/sbapi.md`:
> All the SB API classes are non-virtual, single inheritance classes.
> They should only include SBDefines.h or other SB headers as needed.
> There should be no inlined method implementations in the header
> files, they should all be in the implementation files. And there
> should be no direct ivar access.
The effort to build LLVM as a dylib is tracked in #109483.
[CIR] Add handling for base subobject alignment (#244018)
While working on a previous update to CIR's record alignment handling, I
came across a corner case where we weren't recording user-specified
alignment for a base subobject and also didn't have enough information
to reconstruct the alignment during calling convention lowering. This
change fixes that problem.
Assisted-by: Cursor / Grok 4.7
[Clang][Sema] Add fortify warnings for memccpy, memset_explicit, and explicit_bzero (#243629)
Teach `-Wfortify-source` in `Sema::checkFortifiedBuiltinMemoryFunction`
to diagnose destination buffer overflows/size mismatches for:
- `memccpy` (`warn_fortify_source_size_mismatch`, since copying stops if
the stop byte is found in the source buffer before reaching `n`,
analogous to `strncpy`/`stpncpy`/`strlcpy`)
- `memset_explicit` (`LibBuiltin<"string.h">` from C23,
`warn_fortify_source_overflow`)
- `explicit_bzero` (`GNULibBuiltin<"string.h">`,
`warn_fortify_source_overflow`)
Also pass explicit builtin parameter indices rather than
`TheCall->getNumArgs() - 1` to
`Checker.ComputeExplicitObjectSizeArgument` so
`__attribute__((diagnose_as_builtin(...)))` wrappers with extra
parameters translate the size argument index properly.
Part of #142230
Assisted-by: Gemini
EliminateAvailableExternally: Preserve the function analysis manager proxy (#244023)
Previously all cached function analyses were cleared When only
deleting function bodies, clear the analyses of those functions and
preserve the proxy.
CTMark instructions:u geomean: O3 -0.02% (kimwitu++ -0.12%, tramp3d-v4
-0.12%), ThinLTO -0.01%.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[CIR] Rerun the CIR pipeline on ClangIR input and add -emit-cir=pristine (#243679)
This follows the RFC accepted by the Clang Area Team as `-cc1
-emit-cir=keyword`:
https://discourse.llvm.org/t/rfc-clangir-making-cir-pipeline-boundaries-first-class-driver-artifacts/90998
So far, `.cir` input to cc1 skipped the CIR-to-CIR pipeline, because the
lowering passes were not safe to rerun. With #237433, #237395, #237376,
#237413 and #239847 merged (it is likely that I am forgetting some
here). Rerunning them on their own output now leaves it unchanged, so
ClangIR input runs the full pipeline like source input.
The trade-off here is compilation time, you may end up running the
pipeline twice. I personally am ok with that as any user of
this option is responsible to set their policy.
`-emit-cir=pristine` emits CIRGen's output before any ClangIR pass runs,
which is the point before target lowering that the RFC asked for.
[16 lines not shown]
[Clang][OpenMP] Fix crash on an `omp allocate` local in unreachable code (#242302)
Fixes #140336
CodeGen visits declarations even after the insertion point has been
cleared, but the `omp allocate` path still emitted the `__kmpc_alloc`
call there. For a declaration nothing can reach, such as a `switch` body
before its first `case`, the call ended up outside any basic block and
the verifier rejected the module.
Both allocation hooks now return early when there is no insertion point
and the variable keeps its plain alloca. Jumping into the scope of such
a variable is now an error, as for `__attribute__((cleanup))` and as GCC
does (Here I follow the GCC behavior, if you prefer we could change the
approach in that case): the allocation would be skipped but the
`__kmpc_free` at scope exit would still run.
AI assisted!
[AMDGPU][AsmParser] Require a comma between dfmt and nfmt (#241328)
PR46403 says that the MTBUF syntax expects dfmt and nfmt to be separated
by a comma. Nothing required supporting the comma as optional: dfmt and
nfmt were always ordinary operands. They were separate operands before
35484c9d5024, and the printer has always printed them as 'dfmt:N,
nfmt:M'.
Another step towards checks for correct use of commas between operands.
Assisted-By: Claude
[mlir][affine][NFC] Avoid copying relations in checkAccessDependence (#243286)
checkAccessDependence takes the source and destination access relations
by value because it composes them in place, and its only caller,
checkMemrefAccessDependence, does not use its relations afterwards.
Moving them into the call would not help: IntegerRelation declares a
virtual destructor and no move operations, so a move still copies the
constraint matrices. Take the relations by rvalue reference instead. A
caller that still needs a relation after the check has to pass a copy
explicitly.
It also copied the dependence polyhedron into a local
FlatAffineValueConstraints before checking whether the caller wants it.
Build it only when the caller does; most callers of
checkMemrefAccessDependence pass no dependenceConstraints.
Fixes static analyzer complaints about using copy vs move and passing by
value.
Assisted-by: Cursor
[llvm-profgen] Fix dereference of empty function range when --disassemble-functions for symbols with no range (#219117)
When `--show-disassembly-only` is combined with
`--disassemble-functions`, `decodePseudoProbe()` looks up each requested
function's start address. If the start address has no entry in
`StartAddrToFuncRangeMap`, `[]` operator returns an empty function range
which causes crash when `getFuncName()` dereferences it. Look the range
up instead of creating one, and fall back to the symbol's own GUID when
there is none, so the requested function is still decoded.
Also fix a typo in `--disassemble-functions` help text.
`SymbolStartAddrs` is keyed by the GUID of the raw symbol name, so
mangled names are what actually resolve.
[lldb] Fix SBTypeCategory::GetFilterAtIndex returning no filter (#244308)
GetFilterAtIndex read the category's synthetics instead of its filters.
Assisted-by: Claude
[clang] Fix -chain-include with relative or non-canonical paths (#244269)
ChainedIncludesSource registers each intermediate PCH in the in-memory
module cache under "<include>.pch<N>", spelled exactly as on the command
line. But the PCH that imports it records the import's file name as an
absolute, canonical path (ASTWriter::PreparePathForOutput()), so the
final reader looks for a different name and fails with "PCH file '...'
not found" when the include path is relative, contains "." components,
or (on Windows) has mixed separators.
Register the buffer under the absolute, canonical name instead.
[NFC][AMDGPU] Add a test for casts of known non-null pointers at -O0
At -O0, SelectionDAG checks for null when it casts an alloca or an LDS global
to flat, but GlobalISel does not.
This PR was assisted by AI but I reviewed all the changes.
[AMDGPU] Pass the cast source to isKnownNonNull in lowerADDRSPACECAST
`lowerADDRSPACECAST` passes the cast node instead of its source to
`isKnownNonNull`. The cast node is never a frame index, a global address, or a
constant, so the check never succeeds, and SelectionDAG checks for null when it
casts an alloca or a global. At -O2 the `nonnull` flag that IR passes set on the
cast hides this, but at -O0 every such cast gets a compare and two selects. The
GlobalISel path already passes the source.
This PR was assisted by AI but I reviewed all the changes.
[Hexagon] Stable instruction itinerary names (#239302)
Currently, changes in instruction itineraries ("itins") produce a large
number of changes in td files. Moreover, changes in the td descriptions
cause original lines to get deleted and new ones added in a different
location in the file. This happens because the itin names use a hash of
their content to make them shorter and the definitions are sorted by
name. Another difficulty is that original itin content is not preserved,
which makes it impossible to know how the name was produced.
Instead, use the tag of one of the instructions that use the itin
as the itin's name. This will avoid most of the changes in td files
when itineraries change.
The resulting itin list was regenerated. This exposed a number of
inconsistencies that accumulated over time when manually updating itins
without a clear understanding of their content.
Below is the analysis of changes in itineraries. There were 345
[82 lines not shown]
[libc++][Android] Clean up pre-API-23 carveouts and document LIBCXX-ANDROID-FIXMEs
Due to updating the Android sysroot and compiler in previous upgrades, certain test configurations can be updated by switching them from `UNSUPPORTED` to `XFAIL` and dropping obsolete API carveouts. In addition, document root cause and resolutions for other `LIBCXX-ANDROID-FIXME`.
Assisted-by: Gemini
[Clang][AllocToken] Address post-merge review of placement-new inference (#243991)
Follow-up to #241548:
- Skip collecting placement news in C, which has none. Otherwise every
function with an untyped allocation call (`malloc(n)`) had its body
traversed for nothing.
- Drop the look-through of trivial copy/move constructors in a
variable's initializer. With guaranteed copy elision the initializer is
the call itself, so this only affected class-typed results before C++17,
and it was not tested.
- Test reassignment of a class-typed variable (an operator call), and
drop the compound assignment, increment and constructor-argument cases,
which add no coverage.
RuntimeLibcalls: Mark noreturn and pure helper libcalls
Mark the functions which never return as noreturn. Add some nounwind
and cold, mostly following inferLibFuncAttributes. Mark
misc. functions as pure.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>