Add new section to Building.md
Removed the now-ignored option from the bootstrap-build config example.
Created a new section dedicated to omptest and how to make it
installable.
[OpenMP][omptest] Do not install an ompTest that embeds LLVM's GoogleTest
The GTest-based ompTest embeds LLVM's vendored GoogleTest objects, but LLVM
installs no GoogleTest headers, and the installed OmptTesterGoogleTest.h
includes "gtest/gtest.h". Users of the installed package therefore compile
against whichever GoogleTest their system provides, which need not declare the
testing::internal API the library exports. That API carries no compatibility
promise -- MakeAndRegisterTestInfo() takes its test suite name as const char *
in the copy LLVM vendors and as std::string in later releases -- so the
mismatch surfaces as an undefined symbol when the user links, far from its
cause. The package config cannot express the requirement, because it is not a
version but the exact API generation vendored when the library was built.
Decline to install that configuration and say why. The standalone and
system-GoogleTest builds carry no vendored GoogleTest and remain installable.
Warn rather than error, for now. A build that asks for an installed ompTest
and gets a GoogleTest-based one is asking for something undeliverable, which
would justify a hard failure, but erroring immediately breaks every such build
[8 lines not shown]
[OpenMP][omptest] Add LIBOMPTEST_USE_SYSTEM_GTEST (#242312)
omptest can be built to use GoogleTest. For consumers that are only
inside the LLVM / runtimes build tree there is no problem right now
AFAIK
However, if an outside consumer wants to use omptest from an
installation, the problem is that LLVM vendors its own gTest headers and
those cannot be installed or are almost always unusable.
This change adds the possibility to not use he vendored ones but instead
search on the system for an installed gTest and rely on that instead.
This is a follow-up to the stack in
https://github.com/llvm/llvm-project/pull/237201
Assisted-by: Claude Opus 5 <noreply at anthropic.com>
[wasm] Swift async ABI p3: Lower llvm.swift.async.context.addr to local 0 (#236133)
(see https://github.com/swiftlang/swift/pull/93554)
This intrinsic describes the location of the async context.
[libFuzzer] Fix stale reduced seeds and a fork-mode crash
Seeds are loaded with MayDeleteFile=false. When libFuzzer reduces a
seed, Corpus::Replace keeps the original file and the reduced unit is
written to the output corpus. The flag stays false, so when the same
input is reduced again, the previous reduced unit is not deleted either,
and every intermediate reduction of a seed stays in the output corpus.
In a fork-mode job, the feature file of such a unit has been renamed to
the hash of the newer unit. The parent reads an empty feature set for
the unit and calls memcpy with null pointers. glibc declares them
nonnull, and with _FORTIFY_SOURCE the optimizer removes the zero-size
path of the vector. The parent then writes out of bounds and crashes.
Mark a replaced unit as deletable, since libFuzzer wrote the
replacement itself. Skip the copy when there are no features, and copy
only whole features, so that a missing or truncated feature file from
any other cause does not crash the parent either.
[4 lines not shown]
[Mips] Select constrained FP arithmetic on microMIPS (#246060)
STRICT_FADD, STRICT_FSUB, STRICT_FMUL, STRICT_FDIV and STRICT_FSQRT are
Legal for all hard-float subtargets, but only the standard encoding
patterns were changed to match them. On microMIPS any constrained
arithmetic operation failed instruction selection.
Use the any_* fragments in the microMIPS and microMIPS R6 patterns as
well.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[Mips] Use libcalls for constrained f16 conversions (#246063)
STRICT_FP16_TO_FP and STRICT_FP_TO_FP16 are not covered by the default
Expand action for constrained operations, so they were Legal and any
constrained conversion to or from half failed instruction selection.
Mark them LibCall like their non-strict counterparts, extending to f64
through f32. Also drop the STRICT_ cases from the MSA custom lowering of
these nodes: they were unreachable, and would have used the chain as the
value operand.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[clang] Clean up the Clang export annotations (#239750)
This shuffles `clang/Support/Compiler.h` to more closely match
`llvm/Support/Compiler.h`. In particular, this adds a `clang-config.h`
header defining `CLANG_ENABLE_CLANG_EXPORT_ANNOTATIONS` to simplify the
`CLANG_ABI` and friends definitions.
This also narrows down the compile definitions to the MSVC/clang-cl
clang-cpp dylib build. Since this configuration is still a work in
progress tracked in #238871, this makes `CLANG_ABI` and friends expand
to nothing outside of an MSVC `CLANG_LINK_CLANG_DYLIB` build. As a side
effect, this removes many PCH-related warnings concerning these compile
definitions.
This also removes the `CLANG_BUILD_STATIC` override. Once the work is
done to annotate libclang-cpp, it should no longer be necessary. Right
now, the annotated build does not work so it is useless anyway.
LLM-aided with Claude Code.
[MemoryBuiltins] Infer allockind for strdup (#246479)
Infer `allockind("alloc")` for strdup/strndup, and treat __strdup the
same as strdup.
This allows us to remove the TLI dependency from more MemoryBuiltins
helpers. The remaining ones are related to allocation size (where strdup
is special).
[AArch64] Implement ACLE intrinsics for FPv2 SVE min/max instructions
ACLE PR: https://github.com/ARM-software/acle/pull/480
Implements the following intrinsics:
- svmaxmg / svminmg
- svmaxinm / svmininm
- svmaxmginm / svminmginm
Includes f16, f32, and f64 types, _m, _z, and _x predication and _n variants
AI assistance: Codex used for generating test cases
[mlir][reducer] Delete the temp files of failure-test.sh (#246243)
`mlir/test/mlir-reduce/script/failure-test.sh` says its temp files are
"automatically deleted after the script's execution", but nothing
deletes them. Every run leaves `/tmp/stdout.XXXXXX` and
`/tmp/stderr.XXXXXX` behind. The reducer calls this script once per
reduction so the leak adds up quickly.
This PR adds a `trap ... EXIT` right after `mktemp` calls so both files
are removed however the script exits (exit 0 or exit 1). The script's
logic is unchanged.
[mlir][vector] Prove all-false masks with value bounds (#243127)
This PR extends the all-true handling in `eliminate-vector-masks` to
masks that can be proven all-false.
This was found while compiling a
[FlagGems](https://github.com/flagos-ai/FlagGems) batched matmul for
SME. A 4x4 output tile was lowered to four column subtiles, with 12 of
16 FMOPA instructions in each peeled K block fully masked off. The mask
bounds included expressions such as `4 - 4*vscale`, which the pass did
not resolve, so more instructions were emitted than necessary.
For example, given `empty-mask.mlir`:
```mlir
func.func @empty_mask() -> vector<[4]xi1> {
%c4 = arith.constant 4 : index
%vscale = vector.vscale
%width = arith.muli %vscale, %c4 : index
%bound = arith.subi %c4, %width : index
[29 lines not shown]
[AArch64] Implement ACLE intrinsics for FPv2 SVE min/max instructions
ACLE PR: https://github.com/ARM-software/acle/pull/480
Implements the following intrinsics:
- svmaxmg / svminmg
- svmaxinm / svmininm
- svmaxmginm / svminmginm
Includes f16, f32, and f64 types, _m, _z, and _x predication and _n variants
AI assistance: Codex used for generating test cases
[clang] Add codegen regression test for friend function template (#231022)
The reproducer from #89400 crashed in IR generation because the friend
template definition was instantiated in the wrong template context,
leaving `foo<U>{}` dependent. #125266 fixed this but the case was not
covered by a test.
The test is in CodeGenCXX because clang 19 accepts the reproducer with
`-fsyntax-only` and only crashes when emitting IR.
Fixes #89400
[CIR][AMDGPU] Add support for __builtin_amdgcn_log_clampf (#244000)
Adds CIRGen support for `__builtin_amdgcn_log_clampf`, also adds CIR and
LLVM IR test coverage in
`clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip`.
Part of #241525
Signed-off-by: Harshit Jha <harshitiszz23 at gmail.com>
Co-authored-by: Ayokunle Amodu <ayokunle321 at gmail.com>
Add new section to Building.md
Removed the now-ignored option from the bootstrap-build config example.
Created a new section dedicated to omptest and how to make it
installable.
[OpenMP][omptest] Do not install an ompTest that embeds LLVM's GoogleTest
The GTest-based ompTest embeds LLVM's vendored GoogleTest objects, but LLVM
installs no GoogleTest headers, and the installed OmptTesterGoogleTest.h
includes "gtest/gtest.h". Users of the installed package therefore compile
against whichever GoogleTest their system provides, which need not declare the
testing::internal API the library exports. That API carries no compatibility
promise -- MakeAndRegisterTestInfo() takes its test suite name as const char *
in the copy LLVM vendors and as std::string in later releases -- so the
mismatch surfaces as an undefined symbol when the user links, far from its
cause. The package config cannot express the requirement, because it is not a
version but the exact API generation vendored when the library was built.
Decline to install that configuration and say why. The standalone and
system-GoogleTest builds carry no vendored GoogleTest and remain installable.
Warn rather than error, for now. A build that asks for an installed ompTest
and gets a GoogleTest-based one is asking for something undeliverable, which
would justify a hard failure, but erroring immediately breaks every such build
[8 lines not shown]
[OpenMP][omptest] Add LIBOMPTEST_USE_SYSTEM_GTEST
The GTest-based ompTest embeds LLVM's vendored GoogleTest, whose headers LLVM
does not install. A consumer of the installed package therefore compiles
against whichever GoogleTest it has, which need not declare the same
testing::internal API the library exports, and the package config has no way to
state the requirement.
Add an option to build against the system GoogleTest instead. Library and
consumer then resolve the same gtest/gtest.h, so the dependency becomes an
ordinary one: GTest::gtest is linked PUBLIC and omptest-config.cmake calls
find_dependency() with the version the library was built against.
Note the resulting asymmetry. The vendored build embeds GoogleTest
unconditionally and exports its symbols, so consumers get GoogleTest for free;
a system-GoogleTest build embeds nothing and consumers link it themselves.
Only valid where the system GoogleTest matches this build's C++ standard
library and RTTI setting, since LLVM compiles the vendored copy with
[8 lines not shown]
[CIR] Mark LoweringPrepare init functions strictfp
Classic codegen's StartFunction makes a function that has no
FunctionDecl `strictfp` when the TU-wide default FP environment is
constrained: FP exceptions are not ignored or the rounding mode is
dynamic. Of those functions ClangIR creates `_GLOBAL__sub_I_*`,
`_GLOBAL__I_*`, the C++20 module initializer, `__cxx_global_var_init*`,
`__cxx_global_array_dtor*` and `__tls_init`. It marked only
`__cxx_global_var_init*`, through a `strictfp` attribute on `cir.global`,
so the other functions and the calls in them were not `strictfp`.
Classic also marks the `__dtor_*` stubs, `_GLOBAL__D_a` and
`__GLOBAL_cleanup_*`, which ClangIR does not emit.
LoweringPrepare creates these functions after CIRGen, so it reads the
TU-wide default from `#cir.lowering_options`. `no_trapping_math` already
records whether FP exceptions are ignored, and the new `rounding_math`
field mirrors `LangOptions::RoundingMath`. It is omitted when false, so
the module attribute prints as before without `-frounding-math`.
`buildRuntimeFunction` adds `strictfp` together with the other TU-wide
[8 lines not shown]
[CIR][AMDGPU] Implement __builtin_amdgcn_ds_append and __builtin_amdgcn_ds_consume (#244656)
Adds CIRGen support for `__builtin_amdgcn_ds_append` and
`__builtin_amdgcn_ds_consume`. Adds CIR and LLVM IR test coverage in
`clang/test/CIR/CodeGenHIP/builtins-amdgcn.hip`.
Part of #241525
[Mips] Use libcalls for constrained FP arithmetic on R5900 (#246083)
The R5900 FPU does not implement NaN and infinity, so FADD, FSUB, FMUL,
FDIV and FSQRT only use it when fast-math flags rule those out and are
libcalls otherwise. Their constrained counterparts were Legal for all
hard-float subtargets though, so constrained arithmetic on the R5900
went to the FPU unconditionally.
Make them libcalls on the R5900. The FPU also always rounds toward zero,
so it cannot follow the rounding mode that constrained operations use,
even with fast-math flags.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
[wasm] Swift async ABI p3: Lower llvm.swift.async.context.addr to local 0
In functions with a swiftasync argument, the async context is in local 0.
Loads and stores through llvm.swift.async.context.addr become local.get 0
and local.set 0. In functions without a swiftasync argument, the intrinsic
returns the address of a stack slot, as on X86 without an extended frame.
The swiftasync argument also arrives in local 0, so a store through the
intrinsic would also change the argument. Await resume funclets store their
own context through the intrinsic and can then read the argument, which is
the callee's context. To keep the argument intact, WebAssemblyExplicitLocals
copies it to another local in functions that use the intrinsic.
[CIR] Mark calls in strictfp functions strictfp
LangRef requires every call in a function that uses constrained FP
intrinsics to be `strictfp`, at the call site or on the callee, and
LLVM checks the call, not its caller, before it folds or simplifies a
libcall. Classic codegen gets the attribute from IRBuilder's
constrained mode. ClangIR marked only the function, so at -O1 LLVM
folded `erf(1.0)` to a constant under `FENV_ACCESS ON`.
The lowering now maps the CIR `strictfp` function attribute to the
`strictfp` attribute of `llvm.func` instead of a `passthrough` entry.
After the conversion to the LLVM dialect, it sets `strictfp` on every
`llvm.call`, `llvm.invoke`, `llvm.inline_asm` and `llvm.call_intrinsic`
in a `strictfp` function. That covers direct and indirect calls,
invokes, inline assembly, constrained intrinsics, and the calls that
LoweringPrepare and EH lowering create. CIR does not change, `strictfp`
stays a function attribute. The marks are part of the LLVM dialect, so
they survive any route to LLVM IR.
[11 lines not shown]
[mlir][ExecutionEngine] Move the OpenMP translation dependency to the C API (#246443)
`MLIRExecutionEngine` linked `MLIROpenMPToLLVMIRTranslation` although
the execution engine never uses OpenMP. Every C++ JIT user therefore
pulled in the OpenMP dialect.
The only user of the translation is the C API, which registers it since
db7cc0348c9a.
Link it from `MLIRCAPIExecutionEngine` instead.
Co-authored-by: Claude <noreply at anthropic.com>
[mlir][LLVM] Add strictfp to llvm.func and the call ops (#246250)
In a function that uses constrained floating-point intrinsics, LLVM
requires every call to be `strictfp`, at the call site or on the callee,
and its folders check the call before they fold or simplify a libcall.
The LLVM dialect could mark only the function, through `passthrough`, so
a frontend lowering to it had no way to mark its calls.
This adds a `strictfp` unit attribute to `llvm.func`, `llvm.call`,
`llvm.invoke`, `llvm.inline_asm` and `llvm.call_intrinsic`, the way the
dialect already models `convergent`, `no_unwind` and `will_return`.
Export turns it into the LLVM `strictfp` attribute and import reads it
back, so a `strictfp` function no longer lands in `passthrough`; the
tests cover round-trip, export and import for each op. Calls of the
constrained intrinsic ops already get the attribute from IRBuilder.
Other named intrinsic ops have no call-site attributes.
The inliner now refuses a callee marked `strictfp` and no longer looks
for `strictfp` in `passthrough`.
Assisted-by: Claude Code (Opus 5.5).
[libc] Implement getifaddrs for link-level (AF_PACKET) entries (#246355)
This is the first part of the real getifaddrs implementation. It dumps
the network interfaces (RTM_GETLINK) using the netlink code shared with
if_nameindex, and creates an AF_PACKET entry for each of them. The
entries contain the interface name and flags, and the hardware and
broadcast addresses (as struct sockaddr_ll). IPv4 and IPv6 addresses and
ifa_data will come in follow-up patches.
Like in if_nameindex, the entries are collected in a BlockStore while we
parse the messages, and then copied into a single allocation, which also
holds the names and addresses they point to. This makes freeifaddrs a
single delete[] (glibc does the same thing). Unlike if_nameindex, we
report allocation failures as ENOMEM, as that's what other getifaddrs
implementations do.
struct sockaddr_ll only has room for 8 bytes of hardware address, which
is not enough for e.g. InfiniBand (20 bytes). Like glibc and musl, I'm
using a version of the struct with a larger (MAX_ADDR_LEN = 32 byte)
[5 lines not shown]
[llvm][TableGen] Resolve intra-record field references to `?`
An inconsistency existed in TableGen prior to this PR:
* Referencing a template argument whose value was `?` resolved to and propagated `?`
* Referencing a record whose field is `?` resolved and propagated `?`
However, referencing a field of the record being built remained unresolved, even in the final resolution pass.
This meant that code like:
```tablegen
class Self {
string str = ?;
assert !if(!initialized(str), !ne(str, ""), 1), "str must not be empty";
}
def : Self;
```
would fail to compile as `!initialized(str)` was left unfolded, and `!if` never received a bit value: https://godbolt.org/z/oGh1PzP88
Similar issues arose with other code such as with `!dump` etc.
This PR fixes that issue by resolving a record field to `?` if the record is complete and this is the final resolve pass. As a follow-on effect, some places that previously relied on being kept unresolved now resolve to `?` which required implementing semantics for `?.field` accesses (instead of the current crash using `llvm_unreachable`). This PR therefore also defines `?.field` as resolving to `?`, similar to `?{0}` or `!cast`.