[llvm] [AArch64] Check Subtarget via STI in getInstSizeInBytes (PR #192089)
Zachary Yedidia via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 10:10:13 PDT 2026
https://github.com/zyedidia created https://github.com/llvm/llvm-project/pull/192089
The InstSizes test (`llvm/unittests/Target/AArch64/InstSizes.cpp`) destroys the Subtarget field early (`ST` created on the stack in [`createInstrInfo`](https://github.com/llvm/llvm-project/blob/40a585e742ed6b28306d7511380079325ba1a003/llvm/unittests/Target/AArch64/InstSizes.cpp#L32)), causing a use-after-free if it is used in `getInstSizeInBytes`. This causes a failure when running the test with hwasan (reported by build bot). To fix this, this PR switches to using `STI` instead of `Subtarget` in `getInstSizeInBytes`, which survives for the lifetime of the test.
>From 33bffbb3bcd771af3ca8075574c1e417e006c591 Mon Sep 17 00:00:00 2001
From: Zachary Yedidia <zyedidia at gmail.com>
Date: Tue, 14 Apr 2026 12:12:08 -0400
Subject: [PATCH] [AArch64] Check Subtarget via STI in getInstSizeInBytes
The InstSizes test destroys the Subtarget field early, causing a
use-after-free if it is used in getInstSizeInBytes. Instead we should
use STI, which survives for the lifetime of the test.
---
llvm/lib/Target/AArch64/AArch64InstrInfo.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index 3ca851ef83d27..9d805dad07c1c 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -151,7 +151,8 @@ unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
const MCInstrDesc &Desc = MI.getDesc();
// LFI rewriter expansions that supersede normal sizing.
- if (Subtarget.isLFI())
+ const auto &STI = MF->getSubtarget<AArch64Subtarget>();
+ if (STI.isLFI())
if (auto Size = getLFIInstSizeInBytes(MI))
return *Size;
@@ -162,7 +163,6 @@ unsigned AArch64InstrInfo::getInstSizeInBytes(const MachineInstr &MI) const {
if (!MFI->shouldSignReturnAddress(*MF))
return NumBytes;
- const auto &STI = MF->getSubtarget<AArch64Subtarget>();
auto Method = STI.getAuthenticatedLRCheckMethod(*MF);
NumBytes += AArch64PAuth::getCheckerSizeInBytes(Method);
return NumBytes;
More information about the llvm-commits
mailing list