[clang] [clang][X86] Use a sized byval type for an incomplete interrupt frame (PR #239937)

Feng Zou via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 26 18:42:09 PST 2026


================
@@ -1234,6 +1234,14 @@ static void addX86InterruptAttrs(const FunctionDecl *FD, llvm::GlobalValue *GV,
 
   const auto *PtrTy = FD->getParamDecl(0)->getType()->castAs<PointerType>();
   llvm::Type *ByValTy = CGM.getTypes().ConvertType(PtrTy->getPointeeType());
+  // byval marks parameter 0 as the address of the frame the processor pushed,
+  // which the backend models as five stack slots (CC_X86_Intr). The byval type
+  // must not claim less than that: optimizations treat accesses past its end
+  // as undefined. Use the five slots when the frame's type gives no size: void,
+  // or unsized, e.g. an incomplete struct ("struct interrupt_frame;" in GCC's
+  // documentation).
+  if (PtrTy->getPointeeType()->isVoidType() || !ByValTy->isSized())
+    ByValTy = llvm::ArrayType::get(CGM.IntPtrTy, 5);
   llvm::Attribute NewAttr = llvm::Attribute::getWithByValType(
     Fn->getContext(), ByValTy);
   Fn->addParamAttr(0, NewAttr);
----------------
fzou1 wrote:

Done.

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


More information about the cfe-commits mailing list