[lldb] Fix misaligned pointer UB in DataExtractor::GetU16/U32/U64 array reads (#213038)
The multi-value overloads
`DataExtractor::GetU16`/`GetU32`/`GetU64(offset_ptr, dst, count)` extract `count` consecutive integers from the buffer. When the
data byte order differs from the host, they walked the source and destination
through typed pointers (`const uint16_t *`/`uint32_t *`/`uint64_t *`).
`GetData()` hands back a pointer to an arbitrary byte offset within the
underlying buffer, and the caller's destination is an arbitrary `void*`, so
neither is guaranteed to be aligned for the wider integer type. Casting
such a byte-offset pointer to a wider typed pointer, advancing it, and loading or
storing through it is undefined behavior even when the individual accesses go
through `memcpy`-based helpers, because the typed pointer itself is required to be aligned.
Compiling with UBSan's alignment check (`-fsanitize=alignment`) turns this UB
into a runtime diagnostic, for example:
```
runtime error: store to misaligned address 0x... for type 'uint16_t',
[9 lines not shown]
[AArch64] Use a frame record for non-leaf outlined functions on MachO (#213711)
A non-leaf outlined function saves LR. Saving it alone (str x30) can't
be described by MachO compact unwind, so the encoder falls back to a
larger DWARF FDE. Saving a full frame record (stp x29,x30 ; mov x29,sp)
with the matching CFI gets the small UNWIND_ARM64_MODE_FRAME encoding
instead, for one extra instruction (the mov). getOutliningCandidateInfo
accounts for it.
Only on MachO, where the ABI keeps x29 reserved as the frame pointer, so
setting it up here can't clobber a live value. Other targets keep the
str x30 save (DWARF describes it fine).
Size on a large iOS binary (~70 MiB of code): ~630 KiB smaller
uncompressed -- ~370 KiB less unwind info (compact FRAME instead of
DWARF FDEs) and ~260 KiB less .text. The .text win is a link-time
effect: with compact unwind the linker can ICF-fold identical outlined
functions; a per-function DWARF FDE (which points at its own function)
keeps them distinct and unfoldable.
Assisted-by: Claude Opus 4.8
Import ldis, a lua 5.4 and 5.5 disassembler, into the packages collection.
This is ldis, a disassembler for lua binary files. It works for
binaries compiled by the 5.4 and 5.5 branches of lua, discovering the
compiler used to compile into the opcodes, and delivers the assembly
opcodes and data in an easy to read form. It is similar to the output
produced by luac -l -l, but of course, does not need the lua source
code around to be able to recover the opcodes, constants, upvals and
local variables.
In general, there is little lua consistency between major lua releases.
Bytecodes are numbered differently, and so there is little
consistency, and compiled programs usually need to be recompiled.
This disassembler tries to bridge that gap, by being able to
disassemble both 5.4 and 5.5-compiled binaries.
[NVPTX] Remove addMachineSSAOptimization override (#215321)
This effectively reverts 6dca83987c838a.
In the 10 years since we forked addMachineSSAOptimization we have not
changed it at all and the only differences are from our version going a
little bit stale. This change will add a second run of
`DeadMachineInstructionElim` after `PeepholeOptimizerLegacy` since this
was added after we copied our version but I don't expect there to be
major behavior impacts.
[OpenMP][offload] Fix target reduction for narrow non-integer types (#215294)
Cast the result of the shuffle function back to the width that
corresponds to the integer that is used to hold the bits of the actual
type.
Prevents corresponding reductions from returning NaN or otherwise
incorrect results at higher optimization levels.
Claude assisted with this patch.
[Clang][CodeGen] Emit dereferenceable and nofree for indirect arguments (#213347)
Followup to https://github.com/llvm/llvm-project/pull/201999. Closes
https://github.com/llvm/llvm-project/issues/129337.
In the non-byval case we can't infer `dereferenceable` and `nofree`, so
we will need to add those attributes manually. Indirect arguments are
certainly `nofree` because function parameters have automatic storage
duration. Furthermore, the indirect pointer needs to always point to an
instance of the parameter's type, as function parameters need to be
initialized, so the indirect pointer must be `dereferenceable`.
[PAC][clang] Implement address/type discrimination for VTT vtable pointers (#205808)
Add support for address and type discrimination for vtable pointers
stored in VTTs under the `-fptrauth-vtt-vtable-pointer-discrimination`
option. This option is not enabled by default on any target and works in
combination with `-fptrauth-vtable-pointer-address-discrimination`
and/or `-fptrauth-vtable-pointer-type-discrimination`. Explicit user
control over the signing schema for VTT entries is not currently
supported.
For address discrimination, the address of the corresponding VTT entry
is used as the discriminator.
The type discriminator is computed similarly to the one used for vtable
pointers stored in objects, but is based on the vtable type rather than
its primary base. To distinguish VTT entries from object vtable
pointers, the discriminator is derived from the vtable mangling with an
appended `_VTT` suffix.
[clang] Fix crash in __builtin_stdc_bit_ceil for a 1-bit _BitInt (#214822)
The literal 2 as an ArgType constant requires at least 2 bits. For a
1-bit unsigned _BitInt, this triggers an assertion failure in APInt's
constructor (and silently computes a corrupted result in NDEBUG builds).
Compute the value via a shift of the always-valid constant 1 instead, so
it never depends on ArgType's width.
Fixes: #214478
ixgbe: Report the management packet drop counter
The management_pkts_drpd sysctl was wired to MNGPTC, making it an
alias of management_pkts_txd, instead of MNGPDC.
MFC after: 3 days
[analyzer] Fix -analyzer-output=html assert on reversed and macro ranges
HTMLDiagnostics::HighlightRange guarded against a reversed range by
comparing line numbers, so a same-line reversal - which is what the piece for
an implicit copy constructor carries - reached html::HighlightRange.
Its scan walks from begin to end, ran off the end of the buffer, and asserted:
https://godbolt.org/z/sTb5qfjjd
Invalid position to insert! (RewriteRope.h)
It also added the end token's length itself and then passed a token range to
html::HighlightRange, which measured the token again, this time from the
interior. For most tokens the two cancel, but where the tail re-lexes longer
the highlight reached past the end of the range, e.g. over a trailing ';'.
Use getExpansionRangeInFile(), which rejects reversed and cross-file ranges,
then convert once and tell html::HighlightRange the range is already
char-granular.
[4 lines not shown]
[analyzer] Fix -analyzer-output=sarif crash on macro-expanded ranges (#214462)
A path piece whose range ends inside a macro expansion aborted the whole
document: https://godbolt.org/z/61vWYcsWj
Cannot create a physicalLocation from invalid SourceRange!
convertTokenRangeToCharRange() built the end with
Lexer::getLocForEndOfToken(), which returns an invalid location for a
macro ID that is not at the end of its expansion, and used it unchecked.
The analyzer's own test corpus hits this in nine files; text and plist output
were unaffected because both already map such ranges to the expansion.
- Use getExpansionRangeInFile(), so the region covers the macro use like
the other two outputs.
- Fall back to a caret when the range is unusable. A thread flow needs a
location per piece, so dropping one would truncate the reported path.
This also stops reversed ranges producing regions with:
endColumn < startColumn.
[4 lines not shown]
ixgbe: Recognize production X550 PHY IDs
According to Linux 5f1c3589b0f0, the X550 PHY classifier still matches
an alpha silicon ID, while the shared definitions contain the two
production IDs. This can leave production hardware on the generic
probing path and issue unnecessary PHY queries.
MFC after: 2 weeks
[OpenMP] Fix a crash when a predefined allocator is not declared. (#215312)
`findOMPAllocatorHandleT()` records `omp_allocator_handle_t` before it
fills the table of predefined allocators, but that type is also what it
tests on entry to decide the table is already built. So when a
translation unit declares the type without declaring every predefined
allocator, the first call gives up partway through the table and reports
an error, while the next one takes the early exit and reports success.
`getAllocatorKind()` then walks the abandoned table and dereferences a
null allocator.
A single directive naming an allocator was therefore diagnosed, but a
second one crashed clang. Code that includes <omp.h> declares all of
them and never sees this.
Record the type once the table is known to be complete.
Fixes #157868 and #215277.
Co-authored-by: Cursor <cursoragent at cursor.com>
[AMDGPU] Improve handling of numRecords for make.buffer.rsrc (#213180)
1. Change make.buffer.rsrc to take an arbitrary-width integer for the
numRecords argument, allowing pre-gfx1250 targets to pass in an i32
(thus preventing truncations from mysteriously appearing in the
backend). To do this, document the semantics of make.buffer.rsrc to be
zero-extension if the number of records is too short.
2. Update MLIR to pass the correct (or near-correct) width of integer
depending on the target's features. Therefore, expose "having a 45-bit
num_records" to clang.
3. Per AI review, ensure that the numRecords field doesn't spill into
the flags fields by actively truncating to 45 bits.
4. While we're here, specify gfx13 as having a 45-bit num_records.
---------
Co-authored-by: Codex <codex at openai.com>
[AMDGPU] Preserve NaN payload in fcanonicalize constant fold. (#214608)
getCanonicalConstantFP was replacing all NaN inputs (SNaN and
non-default-payload QNaN) with the default-payload QNaN 0x7FC00000. This
does not match AMDGPU hardware behavior: v_max_f32(x, x) quiets an SNaN
by setting bit 22 only, preserving the rest of the payload, and passes
QNaN through unchanged.
Use APFloat::makeQuiet() for the SNaN case and let QNaN fall through
unmodified, matching what the hardware would produce.
Assisted-By: cursor (claude).
---------
Co-authored-by: Matt Arsenault <arsenm2 at gmail.com>
[lldb] Replace ConstString in Platform::GetFullNameForDylib (#214874)
Basename is read-only, so it can be a StringRef. Similarly, there's no
need to create a ConstString of a dylib name that may or may not exist.