RISCVISelDAGToDAG's lowering of RISCVISD::LPAD_CALL / LPAD_CALL_INDIRECT
to PseudoCALLLpadAlign / PseudoCALLIndirectLpadAlign (introduced in
#177515) only copied the callee, lpad label, chain, and glue operands,
dropping the argument-register and register-mask operands in between.
Without the register-mask operand, the register allocator treats these
calls as clobbering nothing but ra, so values live across the call are
not spilled/reloaded even though the callee is free to clobber
caller-saved registers. This caused a miscompile where a pointer held
live across a call to getcontext() (a returns_twice function) was
corrupted after the call returned, leading to a SIGSEGV in
llvm-test-suite's siod test.
Fix the operand copy to include the argument-register and register-mask
operands, matching the pseudo-instruction operands of a regular
PseudoCALL/PseudoCALLIndirect.
Signed-off-by: Jerry Zhang Jian <jerry.zhangjian@sifive.com>
The [DWARF language registry](https://dwarfstd.org/languages.html)
defines the default array lower bound for `DW_LANG_Fortran18` as one,
but LLVM records it as zero. Update the language table to match the
registry.
Introduce a new `PseudoProbeLinker` in `dsymutil` that collects
`__probes/__probe_descs` sections from the debug map objects and merges
the sections and places the probes metadata under
`Contents/Resources/Profiling/{pseudo_probes[-<arch>],pseudo_probe_descs[-<arch>]}`
respectively.
Update LLVM's DWARF language tables to match the current
[`DW_LANG_*`](https://dwarfstd.org/languages.html) and
[`DW_LNAME_*`](https://dwarfstd.org/languages-v6.html) registries.
Add the missing `DW_LANG_*` and `DW_LNAME_*` constants, update the
corresponding language-version mappings, and expose the new `DW_LANG_*`
codes through the LLVM C API.
`ACCRoutineLowering` generates device side specialized version of
routines that have the `acc.specialized_routine` attribute. Those are
expected to be offloaded and therefore are valid symbol uses.
Assisted-by: Claude Code
[Factored out of llvm/llvm-project#151062 by review request; AI
Disclosure: Done by Claude]
Split the per-use logic of isBlockInLCSSAForm into a separate helper
that answers whether a single use of a value defined in a loop is
contained within the loop for LCSSA purposes.
The pre-RA Zilsd optimizer allowed a pair when both stored values came
from the same virtual register if that virtual register was defined by a
copy from X0. This is only valid when the virtual register class can
actually contain X0.
Check the virtual register class before treating the value as `x0_pair`.
This prevents forming an invalid paired store for register classes such
as `GPRNoX0`.
Without this change we were hitting the following assertion in
`RISCVLoadStoreOptimizer`:
```
assert(
FirstReg != SecondReg &&
"First register and second register is impossible to be same register");
```
A controller call's on-complete handler may run managed code, so it must
be dispatched by the Session under a ManagedCodeTaskGroup token, not
invoked directly by the ControllerAccess (which previously held it as a
plain callable and called it itself -- untokened and undispatched).
Wrap it in an opaque ControllerAccess::OnControllerCallReturn that
implementations can hold but not call. They complete it via exactly one
of three Session-provided paths:
- handleControllerCallResult -- the controller returned a result;
dispatches the handler under a fresh token. Asserts the managed-code
group is still open (i.e. before notifyDisconnected).
- failPendingControllerCall -- an already-enqueued call is failed
because the connection dropped before a result arrived (the disconnect
drain); dispatches the handler under a token with a disconnect error.
- failControllerCallInline -- a call made from within callController
while already disconnecting, which can never be enqueued; runs the
handler inline with a disconnect error, where the caller (and its token)
is still on the stack.
Together these guarantee a controller call's handler always runs exactly
once, with a result or a disconnect error, and never runs managed code
without a token. Only the success path takes a result value; the two
failure paths produce the canonical disconnect error internally, so it
can't be gotten wrong. InProcessControllerAccess and the Session unit
tests are updated.
This patch disables emitting .ftz modifier for bf16 and bf16x2 type setp
and neg instructions, the PTX ISA does not specify this modifier for the
same. FNEG_H already correctly handles fneg for bf16, so remove the
redundant bf16 FNEG16 pattern.
`expandCCOpToCMov` was only accepting signed 5-bit immediates before
forming `Xqcicm` conditional-move pseudos. Valid `uimm5` operands for
unsigned compare forms such as `QC_MVGEUI` and `QC_MVLTUI` were not
being handled leading to a crash.
Track whether the selected conditional-move opcode expects a signed or
unsigned immediate, and validate the RHS against the matching range.
We have started to compile the binary in our base as PIE by defualt. It
makes sense to compile the binary to PIE by default in toolchain as
Linux now. Also, extended testcases to support default PIE and no-pie
parameter in freebsd.c and hip-fpie-option.hip.
std::uniform_int_distribution and std::shuffle are
implementation-defined, so binary built with libc++ and libstdc++ can
produce different fragment layouts when using SplitStrategy. In this
case, the FreeBSD build emits only one fragment instead of three.
The output geenrate by --bolt-seed should be deterministic for the same
binary regardless of the standard library implementation. Implement a
portable shuffle and uniform distribution to guarantee identical results
for a given seed.
After this change, we generate 1 fragment, which decrease the strength
of the testcase. As a result, we change the seed to different value to
allow it generate different number of fragments.
Also, replace in-place file modifcation with a write-and-replace
approach for better portability in sed.
Rename Session::CallViaSession to Session::ControllerCaller, and test
utility CallViaMockControllerAccess to CallFromController.
The old names described who was routing the calls, but this is implicit
at the call-site anyway (CallViaSession was a method on Session, and
CallViaMockControllerAccess took a MockControllerAccess argument). The
new names reflect the call destination, which is the thing clients care
about.
Fixes#210822
A `static` (or anonymous-namespace) function declared in the global
module fragment of the current TU is usable within the module unit
([module.global.frag]/p1), but `Sema::AddOverloadCandidate` dropped it
from the overload set when `Function->isInAnotherModuleUnit()` misfired
— which it does when the enclosing template is instantiated after the
GMF closes (pending instantiations run in
`ActOnEndOfTranslationUnitFragment`, before the named module is in
scope). The candidate was removed with the hidden
`ovl_fail_module_mismatched` kind, so the error had no candidate notes.
The existing carve-out (#104701) only exempted inline /
implicitly-instantiated GMF functions. This also exempts
internal-linkage functions from the current TU's GMF
(`isFromGlobalModule() && !isFromASTFile()`); genuinely imported
internal-linkage functions stay subject to the rule.
`clang/test/Modules` and `clang/test/CXX/module` show no new failures;
the `expose-static-inline-from-gmf-*` tests still pass. Adds a
regression test.
This change was developed with substantial assistance from an AI tool
(Claude Code). The AI carried out the investigation and root-cause
analysis, wrote the code change and the regression test, and drafted
this description.
Some systems may call other intercepted functions during the course of a
`malloc`. This would result in some error stack such as:
```
ERROR malloc
ERROR pthread_mutex_lock
ERROR pthread_mutex_unlock
ERROR free
ERROR pthread_mutex_lock
ERROR pthread_mutex_unlock
```
We support this as RTSan, but this test would be overly specific on
those platforms. As written, this requires "only malloc, then free
immediately after". The change makes this "at least malloc is called,
and then later at least free is called". This still keeps the spirit of
the check the same but allows for more (valid) interpretation in
between.
NOTE:
In the future, we may want to consider doing something similar here:
40c4fea67f/compiler-rt/test/rtsan/stack_suppressions.cpp (L65)
This specifies ONLY 7 suppressions should happen here which is extremely
specific. However I did not change this because it's a little trickier.
We don't really have a test for this stack suppressions method anywhere
else. We could do something like "at least 7 things should be
suppressed", but it's messier so I left that for a future exercise.
Add a legalizer rule that marks these legal at `sXLen` under `+a`
(selecting `amomax.w/d`, and `amomax.b/h` for sub-word under `+zabha`
via the existing widen-scalar-while-preserving-the-memoperand path), and
handle the `llvm.riscv.masked.atomicrmw.{max,min,umax,umin}` intrinsics
the same way as `add/sub/xchg` so sub-word values without `+zabha` use
the LR/SC masking pseudos. There is no `__atomic_fetch_max/min` libcall,
so unlike `add/and/or/xor` the rule does not libcall the no-A case; that
case is already lowered by an IR-level compare-exchange loop and never
reaches GlobalISel, so the rule marks it unsupported to keep the rule
set well-defined.
Updates `legalizer-info-validation.mir` for the newly defined rules and
adds `atomicrmw-max-min-umax-umin.ll`.
We want lit's test-execution engine on concurrent.futures.ProcessPoolExecutor
instead of multiprocessing.Pool as it fixes two latent bugs in the old wait
loop and is groundwork for a planned ThreadPoolExecutor/asyncio backend. It
landed as #202681 but was reverted in #206138. The reverted code deadlocks
due to two independent CPython bugs.
submit() blocks holding _shutdown_lock once the executor's wakeup pipe
fills past 16,384 undrained writes, since its own manager thread needs
that same lock to drain it (cpython gh-105829). Separately, shutdown(wait=True)
deadlocks on macOS because join_executor_internals() joins the call queue
before the workers, the reverse of the order macOS needs.
Fix: bound outstanding futures to SUBMISSION_WINDOW_PER_WORKER * workers
and submit one new test per completion instead of all up front, so the
pipe can never fill (LIT_SUBMISSION_WINDOW=0 restores the old behavior for
debugging). cancel_join_thread() before shutdown(wait=True) fixes the
macOS ordering. Also reap SIGKILL'd workers after abort instead of
leaving zombies.
---------
Signed-off-by: Prasoon Kumar <prasoonkumar054@gmail.com>
This patch adds BOLT support for the RISC-V TLS global-dynamic
relocation `R_RISCV_TLS_GD_HI20`. Classifying it as both a **TLS
relocation** and a **GOT-style relocation** allows BOLT to preserve the
relocation, recover the actual GOT entry address from the linked
instructions, and symbolize the instruction pair.
The RISC-V TLS relocation test is extended to cover a global-dynamic
sequence and verify that BOLT reconstructs the `AUIPC`/`PCREL_LO12` pair
correctly.
No need to be a ConstString, Mach-O segment names are always 16 bytes
long. Because this struct is shared for both segment_command and
segment_command_64, I opted to keep the definition instead of replacing
it with one of llvm's MachO structs.
I chose a 17-byte character array so that whatever goes into it can
always be treated as a null-terminated C string.
This is a resubmit of the original patch: 6344e3aa81:
Make result variables obey their dynamic values in subsequent
expressions (#168611)
When I originally submitted this, it caused intermittent flakey failures
on systems I didn't have access to, and I didn't have time to sort them
out, so I reverted the patch. I'm resubmitting this so I can run the
bots on it a few rounds to see if I can reproduce and diagnose those
intermittent failures.
Here's the commit log from the original submission describing the
change:
When you run an expression and the result has a dynamic type that is
different from the expression's static result type, we print the result
variable using the dynamic type, but at present when you use the result
variable in an expression later on, we only give you access to the
static type. For instance:
```
(lldb) expr MakeADerivedReportABase()
(Derived *) $0 = 0x00000001007e93e0
(lldb) expr $0->method_from_derived()
^
error: no member named 'method_from_derived' in 'Base'
(lldb)
```
The static return type of that function is `Base *`, but we printed that
the result was a `Derived *` and then only used the `Base *` part of it
in subsequent expressions. That's not very helpful, and forces you to
guess and then cast the result types to their dynamic type in order to
be able to access the full type you were returned, which is
inconvenient.
This patch makes lldb retain the dynamic type of the result variable
(and ditto for persistent result variables).
It also adds more testing of expression result variables with various
types of dynamic values, to ensure we can access both the ivars and
methods of the type we print the result as.
If we have a BB that has a single conditional branch instruction it that
is identical to the previous block's branch instruction, we can delete
the BB as it is redundant.
This doesn't directly impact performance as such instructions are never
executed, but this can help decrease code size which can help with
overall icache pressure (though likely only slightly). The biggest
impact would probably be fitting more instructions into a single cache
line. This is probably almost a no-op with PLO but definitely doesn't
hurt.
Fixes#202763.
Reviewers: RKSimon, arsenm, krzysz00, topperc, lei137
Pull Request: https://github.com/llvm/llvm-project/pull/203110
getLastArgValue() only returned the final --ocloc-options= occurrence,
silently dropping earlier ones when the option is passed multiple
times (one token per occurrence). Use getAllArgValues() so every
occurrence is forwarded to ocloc.
The x86_64 aggregate calling-convention bridge rejects a zero-field
record as NYI, even though the SysV classifier already treats an empty
record as NoClass/NoClass (so it returns Ignore) and the rewriter
already drops arguments and returns classified Ignore.
Dropping the zero-field reject in `isSupportedType` lets a C empty
struct classify as Ignore: the argument slot is removed, the remaining
arguments shift down, and an empty-record return lowers to void.
The C++ empty class stays NYI. CIRGen lays it out as a single padded
byte, which the padded reject still catches. Unions, packed, and
all-float aggregates remain NYI as before.
---------
Co-authored-by: Andy Kaylor <akaylor@nvidia.com>
A defaulted union copy or move assignment operator has an empty synthesized
body because Sema skips union fields, leaving no AST expression for the
implied whole-object copy. CIRGen emitted that empty body and silently
dropped the assignment.
Report NYI for defaulted union assignment instead. Struct and array
assignments are unaffected because their synthesized bodies contain the
memberwise copies needed by the existing body-emission path.
It is not expensive to do, and doing it unconditionally avoids edge
cases like the one in the added test case.
Reviewers: arsenm, mtrofin
Pull Request: https://github.com/llvm/llvm-project/pull/208966
Otherwise we run into crashes when loading BC that has a module summary. This is a no-op if we load existing GUIDs, so probably makes sense to run regardless.
Reviewers: mtrofin
Pull Request: https://github.com/llvm/llvm-project/pull/208965
The LLVM offload test suite is current failing layout keyword
orientation tests. While initially appearing to be a layout problem in
the SPIR-V legalizer caused by matrix vector sizes exceeding 4, the root
cause is actually persistent dead function definitions in the SPIR-V
backend.
This behavior is standard for OpenCL, which relies on a linker to clean
up unused definitions; however, since shaders lack a linker and require
full inlining, we must handle this in a special shader only pass.
This change adds SPIRVFinalizeShaderLinkage (a shader-only analogue of
DXILFinalizeLinkage): internalize non-entry, non-exported helpers and
erase the dead ones. Globals are left alone since unreferenced externals
become interface OpVariables.
Fixes#201712
Assisted with Claude Opus 4.8
Module flags `sign-return-address-buildattr` and
`tag-stack-memory-buildattr` are never exercised elsewhere by existing
tests or code across the whole LLVM source tree, and there are no known
cases of them being used.
Moreover, the `sign-return-address-buildattr` flag emission was gated by
`ptrauth` target feature which does not actually exist: see
`AArch64TargetInfo::computeFeatureLookup()` and
`ARMTargetInfo::hasFeature(StringRef Feature)`. So, it was never
emitted.
This patch removes code responsible for these stale module flags
emission.
Note: the flags was previously introduced in
https://reviews.llvm.org/D112421
In order to eliminate TargetOptions ABI fields the front and
middle end need to know what value the backend is going to choose
for the ABI properties. This is similar to how we have
getDefaultExceptionHandling and getDefaultWCharSize.
The clang driver seems to have a different notion of which targets
are default soft. This followed ARMTargetMachine as the authority.
Co-authored-by: Claude (Claude-Opus-4.8) <noreply@anthropic.com>
This change adds support for CFG flattening of loop operations with
cleanup regions.
Rather than re-invent the entire branch through cleanup mechanism, I am
first rewriting the loop by sinking the condition into the body (as a
test + break-if-false) and hoisting the step into the body, and
surrounding the entire body with a cir.cleanup.scope op. Then the greedy
flattening algorithm runs the newly formed loop through the existing
flattening mechanisms so that the loop cleanup handling ends up being
done by the same code that flattens other cleanup scopes.
Assisted-by: Cursor / various models
Reverts llvm/llvm-project#192515
We have addressed the CFI related workflow by introducing a new
MD_callgraph and by disambiguating it from MD_type used for CFI.
The code will be updated and used for wide character printf functions
implemented in wchar/, so __support/ is a more consistent shared
location.
Assisted-by: Automated tooling, human reviewed.
Let's back this out in favor of emitting pseudoprobe data in favor of
emitting in the __LLVM segment, and let dsymutil collect the debug map
objects and merge them into the final sections.
This is to prevent older ld toolchains that don't ignore the new
`__PSEUDO_PROBE` segments from accidentally leaking the probe metadata
into the final image.
fixes#191070
In the SPIR-V backend an optimization has widened a narrow cbuffer load
into a wider vector load that reads trailing padding (e.g. a <1 x float>
float1x4 column loaded as <4 x float>). loadVectorFromVector only
handled down-casts and asserts when the target has more elements than
the source.
We need to handle the widening case by loading the available lanes and
inserting them into a poison target vector, leaving the padding lanes as
poison.
Assisted by Claude Opus 4.8
The new CFI directive directly assigns an RA signing state to the RA_SIGN_STATE DWARF pseudo-register for use when unwinding, to indicate whether the value of PC has been used as a diversifier for return address signing. The new directive subsumes and replaces .cfi_negate_ra_state_with_pc, which was found to be unsuitable for descibing some block layouts [1], particularly in hot-cold-split functions.
1: https://github.com/ARM-software/abi-aa/pull/346
In DXC, when `/Qpdb_in_private` flag is specified, debug info PDB is
emitted into PRIV part of the output DXContainer (as well as into
separate PDB file, if its name is specified with `/Fd`).
This patch reimplements similar behavior in llc and Clang.
MC is modified to be able to emit PRIV part.
Depends on https://github.com/llvm/llvm-project/pull/204166.
This reverts commit bc3386c1b9.
Let's back this out in favor of emitting pseudoprobe data in favor of
emitting in the `__LLVM` segment, and let `dsymutil` collect the debug
map objects and merge them into the final sections.
The avx512vlbw-builtins.c test was using the now-nonexistant avx10.1-512
target feature in several of its run lines. Because the feature no
longer exists with that spelling it was being silently ignored.
Apparently it isn't needed for the test upstream because the test has
been passing, but I received reports from a downstream user that the
test was failing for them.
There was a recent change to more strictly enforce always-inlining if
target features didn't match. I suspect that this downstream project has
a different version of some intrinsic header files so that it requires
"avx10.1" (the correct spelling of the feature).
This change updates the test run lines to use the correct feature
spelling.