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

via cfe-commits cfe-commits at lists.llvm.org
Sat Nov 7 00:55:33 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Feng Zou (fzou1)

<details>
<summary>Changes</summary>

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@<!-- -->anthropic.com>

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


2 Files Affected:

- (modified) clang/lib/CodeGen/Targets/X86.cpp (+5) 
- (added) clang/test/CodeGen/attr-x86-interrupt-incomplete-frame.c (+45) 


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

``````````

</details>


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


More information about the cfe-commits mailing list