clang: Construct toolchains with normalized triples (#201869)
Avoid littering calls to normalize around by ensuring toolchains
always use a normalized triple. The test changes are due to
inconsistencies in the behavior of the triple APIs. If the arch name
is empty, normalize leaves it unchanged. If the triple is archname--,
normalize will expand the empty groups to be unknown. setArchName
will introduce the empty groups, which occurs in some of the triple
modifying driver path (mostly the handling of the endianness -m flags).
Driver is still holding onto a raw, unnormalized string triple but
leave that for a later cleanup.
Co-authored-by: Claude Sonnet 4 <noreply at anthropic.com>
[clang] Fix -Wunused-template in AST and analysis helpers (NFC) (#202977)
Several function templates across clang's AST and analysis code trip
`-Wunused-template`. Three kinds of fix here:
- Header templates with internal linkage (`static`), which gives each TU
its own copy and a latent ODR hazard. Drop `static` in `InterpHelpers.h`
(`handleOverflow`), `Marshallers.h` (the `matcherMarshall*`,
`mergePolyMatchers`, and `outvalueToVariantMatcher` helpers), and
`LifetimeSafety/Utils.h` (`join`). Templates are implicitly inline, so
nothing else changes.
- Dead code: `castAttrAs` in `ASTImporter.cpp` has no callers, so it's
removed.
- Assert-only helpers compiled out in release builds, marked
`[[maybe_unused]]`: `getKeys` in `DataflowAnalysisContext.cpp` and the
`hasBodyOrInit` template in `CrossTranslationUnit.cpp`.
NFC.
Part of #202945.
[CIR] Fix namespace, naming, and assert in sret
Remove `using namespace mlir;` from CIRABIRewriteContext.cpp
and qualify all MLIR-namespaced types explicitly with `mlir::`.
Rename `sretOffset` to `hasSRetArg` (bool) -- the name now
reflects that the value is either 0 or 1 and acts as a
presence flag, not an arbitrary offset. Rename `rewriter` to
`builder` throughout for consistency with the rest of the
calling-convention lowering code.
Assert in `insertSRetStores` that every `cir.return` in an sret
function carries an operand. CIRGen guarantees the invariant
`cir.return (cir.load %__retval)` for all returns in an
aggregate-returning function; a bare return would indicate the
sret slot was never written, which is a bug. The previous
`continue` silently ignored that case.
Add an explanatory comment at the `replaceAllUsesWith` call so
it is clear why erasing the alloca immediately after is safe,
[3 lines not shown]
[CAS] Bypass IO sandbox in `OnDiskGraphDB::store()` (#202760)
The sandbox is currently only bypassed in
`OnDiskGraphDB::createStandaloneLeaf()`, but the calling function
`store()` may also initiate some IO by calling `MappedTempFile::keep()`
whose parent `TempFile::keep()` calls `sys::fs::closeFile()`. Let's move
the sandbox disablement to the caller to avoid violations.
rdar://177274700
[clang] Fix -Wunused-template in frontend helpers (NFC) (#202980)
Two frontend templates trip `-Wunused-template`.
In `ASTUnit.cpp`, `moveOnNoError` is an unused duplicate (the live copy
lives in `PrecompiledPreamble.cpp`), so it's removed.
In `CompilerInvocation.cpp`, `mergeMaskValue` and `extractMaskValue` are
the option-marshalling helpers that `OptParser.td` names for bitfield
options. No option currently uses that kind, so they never instantiate.
They're kept and marked `[[maybe_unused]]`, since deleting them would
break any future bitfield option.
NFC.
Part of #202945.
[OpenMP] Use ext linkage for kernels handles and globals handles keep… (#202827)
… linkage
Host handles are now emmitted with external linkage to clash if two
kernels with the same name are registered. This could have happen right
now and silently corrupt the program, but it can happen more easily once
we allow users to name their kernels.
In the same patch we make global variable handles retain the linkage of
the global variable, forcing clashes for external ones and continue to
support weak use cases. The exception is common linkage, which we
transform into weak for the entry as there is no zero initialization.
[lldb] Add more Mach-O export trie unit tests (NFC) (#202814)
Extend MachOTrieTest with cases that exercise ParseTrieEntries paths the
existing tests miss, all against the current parser with no functional
change. They cover well-formed edge cases (sibling breadth, empty and
single-character edge labels, large multi-byte addresses, ARM/Thumb and
stub-resolver handling, mixed exports and re-exports) and malformed
input that must be tolerated or rejected without crashing (a shared
subtree, an unterminated edge string, an excessive children count, a
truncated terminalSize, and an out-of-range start offset).
Assisted-by: Claude
[mlir][linalg] Add inverse triag, log to elementwise ops (#202786)
Follow up to #200950
Add acos, acosh, asin, asinh, atan, atanh, log10, log1p, log2 to
elementwise ops
These math operations are added as UnaryFn enum cases and supported
through linalg.elementwise only, with no named op definitions. The
specialize pass converts linalg.generic containing these math ops to
linalg.elementwise when emitting category ops
Co-authored-by: Vinit Deodhar <vinitdeodhar at users.noreply.github.com>
[CIR] Add custom assembly format for alloca op to fix flag parsing (#198962)
The previously used assembly format was generating code like:
```cpp
if (::mlir::succeeded(parser.parseOptionalComma())) {
props.init = parser.getBuilder().getUnitAttr();
if (parser.parseKeyword("init"))
return ::mlir::failure();
}
```
This means that upon seeing any comma, the parser would immediately set
the `init` attribute and then expect the keyword "init" to follow. So a
valid input like `["n", const]` would fail with:
```bash
error: expected 'init'
```
Update shells/bash to 5.3.15
Patch 13: Avoid (potential) UB comparing result from realloc with its arg
Patch 14: Improve the solution from patch 11
Patch 15: Avoid references to the byte before the input buffer used by read
And for completeness, for the patches from the previous update:
Patch 10: Fix problem with some EXIT traps calling wait
Patch 11: Fix possible ref to freed memory in mapfile
Patch 12: Fix issue with subshells, EXIT traps, and fatal signals
[asan] Fix asan_new_delete.cpp C++ header resolution under -nostdinc++ (#202816)
The COMPILER_RT_ASAN_ENABLE_EXCEPTIONS gate in asan/CMakeLists.txt
enables -fexceptions on the C++ slice (RTAsan_cxx /
RTAsan_dynamic_cxx — asan_new_delete.cpp) and tries to expose C++
standard headers to that TU (for forthcoming std::bad_alloc support)
by stripping -nostdinc++ from its cflags. The strip works for native
standalone builds but is wrong for cross builds: the host C++ headers
aren't valid for the target.
Split the C++-slice flag handling into two paths inside the existing
EXCEPTIONS gate:
* In-tree libc++ available (TARGET cxx-headers OR HAVE_LIBCXX):
keep -nostdinc++, append ${COMPILER_RT_CXX_CFLAGS} (a generator
expression that expands to "-isystem <prepared cxx-headers dir>"),
and add cxx-headers to DEPS so the header tree is staged before
the compile. Mirrors the pattern in orc / fuzzer / memprof /
tsan / xray.
[10 lines not shown]
[CIR] Fix inline asm operand-attr indexing (#202790)
Inline asm with a register operand ordered before a memory operand, e.g. `asm("" :: "r"(i), "m"(g))`, crashes CIRGen at the `"pointer type expected"` / `"element type differs from pointee type"` assertions in `emitAsmStmt`.
The element-type-attribute loop walks `argElemTypes` with a counter that only advances on entries that have an element type, but uses that counter to index the parallel `args` array. The two arrays are the same length (every operand pushes to both, and `assert(args.size() == operandAttrs.size())` enforces it), so the matching value for `argElemTypes[k]` is `args[k]`. As soon as a register operand (null element type) precedes a memory operand (non-null), the counter desyncs and reads the wrong operand — a non-pointer, or a pointer with the wrong pointee.
The fix indexes `args` positionally with `llvm::enumerate`, matching classic CodeGen in `CGStmt.cpp`, which iterates `llvm::enumerate(ArgElemTypes)` and attaches the element-type attribute at `Pair.index()`. New `t35` in `inline-asm.c` covers the register-before-memory ordering and checks the lowered IR against classic codegen.
[flang][OpenMP] Remove CheckSymbolName{,s}, NFC (#202811)
These functions checked if each OmpObject had a symbol, and emitted a
diagnostic if not. Name not having a symbol is an internal compiler
error (which will be detected separately), and not something actionable
for the user.
Remove these functions since they don't serve any purpose anymore.