[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
Sat Nov 7 00:54:58 PST 2026


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

x86_intrcc requires parameter 0 to be byval, and addX86InterruptAttrs uses the frame's type as the byval type. When that type is incomplete, as in GCC's documentation ("struct interrupt_frame;"), or a function type, it is unsized, so the module fails verification ("Attribute 'byval' does not support unsized types") or, without the verifier, instruction selection asserts when computing the type's size.

The backend places the frame at a fixed offset and uses the byval type only to size its fixed stack object, so fall back to i8, the type already used for "void *". Frame types that are complete when the handler is emitted are unaffected; one completed only later in the file, which used to keep its struct type, now also gets i8.

Resolve https://github.com/llvm/llvm-project/issues/237266

Assisted-by: Claude Opus 5.5 <noreply at anthropic.com>

>From 8199ef3372db97a7e05c74d57682b08e9cd8e271 Mon Sep 17 00:00:00 2001
From: "Zou, Feng" <feng.zou at intel.com>
Date: Mon, 26 Oct 2026 04:20:17 +0530
Subject: [PATCH] [clang][X86] Use a sized byval type for an incomplete
 interrupt frame

x86_intrcc requires parameter 0 to be byval, and addX86InterruptAttrs
uses the frame's type as the byval type. When that type is incomplete,
as in GCC's documentation ("struct interrupt_frame;"), or a function
type, it is unsized, so the module fails verification ("Attribute
'byval' does not support unsized types") or, without the verifier,
instruction selection asserts when computing the type's size.

The backend places the frame at a fixed offset and uses the byval type
only to size its fixed stack object, so fall back to i8, the type
already used for "void *". Frame types that are complete when the
handler is emitted are unaffected; one completed only later in the
file, which used to keep its struct type, now also gets i8.

Assisted-by: Claude Opus 5.5 <noreply at anthropic.com>
---
 clang/lib/CodeGen/Targets/X86.cpp             |  5 +++
 .../attr-x86-interrupt-incomplete-frame.c     | 45 +++++++++++++++++++
 2 files changed, 50 insertions(+)
 create mode 100644 clang/test/CodeGen/attr-x86-interrupt-incomplete-frame.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 5324c8d366b829..fc49756374fd80 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1234,6 +1234,11 @@ 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 needs a sized type, but the frame's type may be unsized, e.g. an
+  // incomplete struct ("struct interrupt_frame;" in GCC's documentation). The
+  // backend locates the frame itself, so use i8 as for "void *".
+  if (!ByValTy->isSized())
+    ByValTy = CGM.Int8Ty;
   llvm::Attribute NewAttr = llvm::Attribute::getWithByValType(
     Fn->getContext(), ByValTy);
   Fn->addParamAttr(0, NewAttr);
diff --git a/clang/test/CodeGen/attr-x86-interrupt-incomplete-frame.c b/clang/test/CodeGen/attr-x86-interrupt-incomplete-frame.c
new file mode 100644
index 00000000000000..f07c5307914834
--- /dev/null
+++ b/clang/test/CodeGen/attr-x86-interrupt-incomplete-frame.c
@@ -0,0 +1,45 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X86_64
+// RUN: %clang_cc1 -triple i386-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,X86
+
+// The interrupt frame's type may be unsized: an incomplete type, as in GCC's
+// documentation, or a function type. byval needs a sized type, so i8 is used,
+// as for "void *".
+
+#ifdef __x86_64__
+typedef __UINT64_TYPE__ uword;
+#else
+typedef __UINT32_TYPE__ uword;
+#endif
+
+struct interrupt_frame;
+union frame_union;
+typedef struct frame_tag frame_t;
+
+// CHECK: define{{.*}} x86_intrcc void @frame_void(ptr noundef byval(i8) %{{.+}})
+__attribute__((interrupt)) void frame_void(void *f) {}
+
+// CHECK: define{{.*}} x86_intrcc void @frame_struct(ptr noundef byval(i8) %{{.+}})
+__attribute__((interrupt)) void frame_struct(struct interrupt_frame *f) {}
+
+// X86_64: define{{.*}} x86_intrcc void @frame_struct_ec(ptr noundef byval(i8) %{{.+}}, i64 noundef %{{.+}})
+// X86: define{{.*}} x86_intrcc void @frame_struct_ec(ptr noundef byval(i8) %{{.+}}, i32 noundef %{{.+}})
+__attribute__((interrupt)) void frame_struct_ec(struct interrupt_frame *f,
+                                                uword ec) {}
+
+// CHECK: define{{.*}} x86_intrcc void @frame_union(ptr noundef byval(i8) %{{.+}})
+__attribute__((interrupt)) void frame_union(union frame_union *f) {}
+
+// CHECK: define{{.*}} x86_intrcc void @frame_typedef(ptr noundef byval(i8) %{{.+}})
+__attribute__((interrupt)) void frame_typedef(frame_t *f) {}
+
+// CHECK: define{{.*}} x86_intrcc void @frame_func(ptr noundef byval(i8) %{{.+}})
+__attribute__((interrupt)) void frame_func(void (*f)(void)) {}
+
+// A type completed after the handler is still incomplete where the handler is
+// emitted.
+struct frame_later;
+// CHECK: define{{.*}} x86_intrcc void @frame_later(ptr noundef byval(i8) %{{.+}})
+__attribute__((interrupt)) void frame_later(struct frame_later *f) {}
+struct frame_later {
+  uword ip;
+};



More information about the cfe-commits mailing list