[llvm] [AArch64] Check Subtarget via STI in getInstSizeInBytes (PR #192089)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 14 10:10:51 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Zachary Yedidia (zyedidia)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/192089.diff


1 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.cpp (+2-2) 


``````````diff
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;

``````````

</details>


https://github.com/llvm/llvm-project/pull/192089


More information about the llvm-commits mailing list