RuntimeLibcalls: Add signatures for the memcpy variants and __stack_smash_handler (#239367)
The XCore and Hexagon memcpy variants take the usual destination,
source and size, except hexagon_memcpy_forward_vp4cp4n2 which takes a
word count. __stack_smash_handler uses the OpenBSD prototype.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
IR: Implement Instruction::mayReadOrWriteMemory with a single switch (#239479)
Separately calling mayReadFromMemory and mayWriteToMemory performed 2
calls and was slower. This speeds up attributor-light pass up to 2.7%
(callgrind), and 0.2-5.8% faster with other pending Attributor
compile-time changes applied.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
RuntimeLibcalls: Add the MIPS16 hard float helpers to "compiler-rt" (#239405)
The __mips16_* hard float helpers were not in any library, so they
were never available. libgcc's mips16.S provides them for O32, but not
for R6. compiler-rt does not provide them, but we don't get try to
distinguish the 2.
Since these coexist with standard symbol names, this needs explicit
handling to prefer these implementations.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[Clang][OBT] Add overflow handler diagnostics
Add three warnings:
- -Woverflow-behavior-goto-no-effect (on): the operand of
__builtin_overflow_goto performs no checked operation. Not issued for
dependent operands or during template instantiation.
- -Woverflow-behavior-no-handler (off): an expression's checks trap
because no handler is visible. Projects that require a handler can
promote it to an error.
- -Woverflow-behavior-unreachable-handler (on): checks in a lambda or
block trap although the enclosing function has a handler, which they
cannot reach.
The last two report once per outermost unhandled expression. They are
emitted when the outermost function body is complete, so that labels
defined after a lambda are known, and per instantiation for templates.
The walk runs only when the function has a handler or the off-by-default
warning is enabled.
[2 lines not shown]
[Clang][OBT] Add __builtin_overflow_goto
__builtin_overflow_goto(expr, label) sends the failed trap overflow
behavior type checks of operations written in expr to label instead of
to the default __overflow handler. It yields the value of expr, which
must have integer or void type, and keeps its value category. A void
operand lets a GNU statement expression guard a whole block:
#define try(x, label) __builtin_overflow_goto(({ x; }), label)
try(a + 1, L); // yields a + 1
try({ a--; a += 2; }, L); // void
When builtins and GNU local handler labels nest, the innermost applies.
Effects before the failing check are kept. The builtin may not branch out
of code whose checks always trap, such as a constructor initializer or a
new-expression initializer; the jump scope checker rejects it, and runs for
every function that uses the builtin.
[12 lines not shown]
[Clang][OBT] Branch to the overflow handler on trap OBT conversion checks
Implicit and explicit integral conversions into or out of an __ob_trap
type check for truncation and sign change. Route a failed check to the
overflow handler label, when one is visible, the same way arithmetic
checks already do. Compound assignments check the conversion back to
the left-hand type even when the operator itself (for example <<=) is
not checked, so they count as checked operations too.
The shared predicate gains isOverflowHandlerCheckedConversion, which
mirrors the width and signedness rules CodeGen uses to decide whether a
check is emitted, and CodeGen asserts that the two agree. The jump scope
checker therefore diagnoses exactly the conversion branches CodeGen
emits.
Assisted-By: claude
Signed-off-by: Justin Stitt <justinstitt at google.com>
[Clang][OBT] Test cleanups on the path to the overflow handler
An overflow that branches out of a scope must run that scope's cleanups
before reaching the handler. Test that destructors of locals leaving
scope and of full-expression temporaries run first, that objects still
in scope at the handler are destroyed when it returns, and that pending
_Defer bodies run innermost first.
Assisted-By: claude
RuntimeLibcalls: Add signatures for the MIPS16 return helpers (#239404)
MIPS16 functions call these to move a floating point return value into
floating point registers. Each takes the value being returned, with
complex values as a pair of floats or doubles.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[lldb] Remove ConstString from CommandObjectType (#237416)
After removing ConstString from the DataFormatters library, I realized
that the CommandObject that most interacted with it was still producing
ConstStrings. These codepaths should be mostly free of ConstStrings now.
I also removed them from the unittests.
[debugserver] Add a gdb server subcommand to swift-debugserver (#239033)
This is further scaffolding for the project.
Notes:
- Command objects now have `Command` at the end of them. I will probably
create a GDBServer object later, and although the names conflicting
isn't inherently a problem, I think it's more readable this way.
- Subcommand is now a Protocol. I was going back and forth on this one,
but I think it brings some simplification to the driver. The size
increase is only ~1kB right now, so we can revisit this later if it
presents a problem later in the project.
- Right now, GDBServerCommand doesn't actually do anything. The parse
function processes 3 flags and options that lldb uses to spawn
debugserver on my local machine.
- The actual parsing is ad-hoc currently. When we add support for
platform mode, this logic should be broken out into a common library or
we should adopt a library that handles this for us.
Assisted-by: claude
[mlir][llvm] Update MemProf metadata when inlining calls (#239391)
Fix https://github.com/llvm/llvm-project/issues/239141
The MLIR inliner carried llvm.memprof and llvm.callsite over unchanged,
so contexts went stale across an MLIR-side inline. Handle them in
processInlinedCallBlocks, matching LLVM's propagateMemProfMetadata.
Unlike LLVM's call-stack trie rebuild, the kept subset is carried over
unchanged.
Attributor: Use an array indexed by opcode for OpcodeInstMap (#239454)
This avoids a DenseMap lookup for every instruction when building the
InformationCache, and for every opcode checked by
checkForAllInstructions.
CTMark instructions:u with -attributor-enable=light changes by O3
-0.04%,
ThinLTO -0.02%. The attributor-light pass itself is 0.2-2.5% faster
(callgrind), and 1.4-7.2% faster with the other pending Attributor
compile-time changes applied.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[SLP]Emit full byte reversal of extracted fields as bswap
Gathers of the fully reversed bytes of a scalar are emitted as a byte
swap instead of a bitcast plus reverse shuffle, if not more expensive.
The byte swaps of scalars extracted from the same vector are estimated
together with all their extractions, since the shuffle folds them.
Fixes #235677
Assisted-by: Cursor
Reviewers: RKSimon, bababuck
Pull Request: https://github.com/llvm/llvm-project/pull/235810
[Support][NFC] Initialize suffix tree metadata during construction (#232720)
Compute internal path lengths and leaf suffix starts during insertion to
eliminate the final `setSuffixIndices()` traversal.
This change preserves functional behavior while avoiding the final
metadata traversal.
SuffixTree construction CPU time against main `f14f34f217a9`:
Core i9-13900K, Linux x86_64, X86 `-Oz`, outlining always enabled,
leaf descendants enabled. Sum inputs per round; for each version, drop
the minimum and maximum of 10 rounds and average the remaining 8.
| Workload | Mode | Baseline (s) | Optimized (s) | CPU change |
| --- | --- | ---: | ---: | ---: |
| CTMark | NoLTO | 0.185136 | 0.174090 | -5.97% |
| CTMark | FullLTO | 0.086525 | 0.075911 | -12.27% |
| SPEC2017 C/C++ Rate | NoLTO | 1.232714 | 1.156888 | -6.15% |
| SPEC2017 C/C++ Rate | FullLTO | 0.570815 | 0.456092 | -20.10% |
[6 lines not shown]
[TableGen] Remove HwMode expansion from CodeGenDAGPatterns. (#238932)
GlobalISel and Selection both handle HwMode expansion during instruction
selection now.
The only remaining user is FastISel, but no in tree target uses FastISel
with HwModes. If it becomes necessary, I think it should be done at
selection time like SelectionDAG and GlobalISel. For now, FastISel will
skip patterns that use HwMode.
Assisted-by: Claude
DroppedVarStats: Count variables visible from inlined frames (#239280)
A dropped variable is only counted if an instruction remains from which
a debugger could observe it. The check needs to consider all inlined
frames to check if the variable is visible from one. The old code would
have false negatives as it wouldn't consider inlined scopes as visible
(see added tests inlined_code_in_scope and
nested_inlined_code_in_scope).
Also remove VisitedScope, which guarded against cycles, but cycles
cannot happen in scopes.
Assisted-by: Claude
[ARC] Declare command line options in TableGen (#239691)
Move the cl::opt options into ARCOptions.td. ARCTargetMachine holds
`const ARCOptions &CLOpts`, and ARCSubtarget copies it.
LLM-aided
[lldb] Don't restore registers saved under a different layout (#239445)
When g packets are avoided, WriteAllRegisterValues restores each
register by indexing the saved buffer with the current register offsets.
A reconfigure between save and restore, such as a change of the SVE
vector length, can move those offsets past the end of the buffer, in
which case lldb reads out of bounds and sends the bytes to the stub.
Fail the restore when the buffer size no longer matches the register
data size.
rdar://186993734
Assisted-by: Claude
[SystemZ][z/OS] Make symbols renameable
z/OS can rename symbols, but only if the symbol is marked as
renameable in the ESD record. Until now all symbols were emitted as
non-renameable. Mark them renameable by default, with these exceptions:
- CELQSTRT and CELQINPL stay non-renameable.
- CELQBST is renameable.
Section-level PR symbols are unchanged.
Add a renameable flag to MCSymbolGOFF and the ER attributes, and
update the affected tests.
Note that HLASM has no way to express this flag, so it is only
visible in the GOFF object output.
Assisted by: IBM Bob
[LifetimeSafety] Support allocating/freeing functions annotated `ownership_takes`/`ownership_returns` (#213439)
This PR extends LifetimeSafety to model allocating/freeing functions
annotated with `__attribute__((ownership_returns))` /
`__attribute__((ownership_takes))`.
# Contents
* Adds `handleAllocatingCall`, which treats the call result as a fresh
allocation and issues a new loan for it (mirroring `new`).
* Adds `handleFreeingCall`, which treats the annotated arguments as
freed and invalidates their origins (mirroring `delete`), enabling
use-after-free and escape-invalidation diagnostics.
* Extends the `AccessPath` base union to also accept allocating
`CallExpr`s, keeping the number of alternatives unchanged. (breaks build
on 32-bit systems if 1 more template parameter is added)
Completes part of #213435
Assisted-by: DeepSeek V4 for writing most of the code
[LifetimeSafety] Support allocating/freeing functions and builtins (#213443)
This extends LifetimeSafety to model allocating/freeing functions annotated with "ownership_returns" / "ownership_takes", as well as malloc-style builtins without requiring any attributes.
Contents
* Adds "handleAllocatingCall", which treats allocation results as fresh allocations and issues new loans (mirroring "new").
* Adds "handleFreeingCall", which invalidates the origins of freed arguments (mirroring "delete"), enabling use-after-free and escape-invalidation diagnostics.
* Extends the "AccessPath" base union to support allocating "CallExpr"s without increasing the number of alternatives.
* Adds support for "malloc"/"calloc"/"realloc"/"free" and their "__builtin_" spellings as allocating/freeing functions.
Closes #213435
Assisted-by: DeepSeek V4 for writing most of the code