[clang] [Clang] Fix crash with typedef pointer in x86 interrupt handlers (PR #230903)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 10 23:23:07 PDT 2026
https://github.com/keepyixiao updated https://github.com/llvm/llvm-project/pull/230903
>From f33990d269ed0abe6bbaa93bf7db6de4eadaa1bd Mon Sep 17 00:00:00 2001
From: nudt_yixiao <1272950933 at qq.com>
Date: Sun, 11 Oct 2026 12:35:24 +0800
Subject: [PATCH] [Clang] Fix crash with typedef pointer in x86 interrupt
handlers
The CodeGen cast fails when the interrupt handler's first parameter
is a typedef of a pointer type.
Use castAs<PointerType>() to handle typedef types correctly.
Add a regression test for typedef pointer parameters.
---
clang/docs/ReleaseNotes.md | 4 ++++
clang/lib/CodeGen/Targets/X86.cpp | 2 +-
clang/test/CodeGen/attr-x86-interrupt.c | 6 ++++++
clang/test/Sema/attr-x86-interrupt.c | 3 +++
4 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index 77a1e73bc8af6..8c70cf23ab3d1 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -728,6 +728,10 @@ features cannot lower the translation-unit ABI level;
`alias` are now correctly diagnosed as definitions when followed by an
out-of-line definition. (#GH204762)
+- Fixed an assertion failure when generating code for an x86 function with the
+ `interrupt` attribute whose first parameter uses a typedef for a pointer
+ type. (#GH204756)
+
#### Bug Fixes to C++ Support
- Fixed lambdas with specifiers or attributes after the capture list being
diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index c0947c481d2b0..f55ea6f0e662b 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1220,7 +1220,7 @@ static void addX86InterruptAttrs(const FunctionDecl *FD, llvm::GlobalValue *GV,
if (FD->getNumParams() == 0)
return;
- auto PtrTy = cast<PointerType>(FD->getParamDecl(0)->getType());
+ const auto *PtrTy = FD->getParamDecl(0)->getType()->castAs<PointerType>();
llvm::Type *ByValTy = CGM.getTypes().ConvertType(PtrTy->getPointeeType());
llvm::Attribute NewAttr = llvm::Attribute::getWithByValType(
Fn->getContext(), ByValTy);
diff --git a/clang/test/CodeGen/attr-x86-interrupt.c b/clang/test/CodeGen/attr-x86-interrupt.c
index 107a8fd316bcc..416c4ea9003b9 100644
--- a/clang/test/CodeGen/attr-x86-interrupt.c
+++ b/clang/test/CodeGen/attr-x86-interrupt.c
@@ -3,6 +3,7 @@
// RUN: %clang_cc1 -triple x86_64-pc-win32 %s -emit-llvm -o - | FileCheck %s --check-prefix=X86_64_WIN
// RUN: %clang_cc1 -triple i386-pc-win32 %s -emit-llvm -o - | FileCheck %s --check-prefix=X86_WIN
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnux32 %s -emit-llvm -o - | FileCheck %s --check-prefix=X86_64_LINUX
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -DTEST_TYPEDEF %s -emit-llvm -o - | FileCheck %s --check-prefix=TYPEDEF
#ifdef __x86_64__
typedef __UINT64_TYPE__ uword;
@@ -12,6 +13,11 @@ typedef __UINT32_TYPE__ uword;
__attribute__((interrupt)) void foo7(int *a, uword b) {}
__attribute__((interrupt)) void foo8(int *a) {}
+#ifdef TEST_TYPEDEF
+typedef int *int_ptr;
+__attribute__((interrupt)) void foo_typedef(int_ptr a) {}
+// TYPEDEF: define{{.*}} x86_intrcc void @foo_typedef(ptr noundef byval(i32) %{{.+}})
+#endif
// X86_64_LINUX: @llvm.compiler.used = appending global [2 x ptr] [ptr @foo7, ptr @foo8], section "llvm.metadata"
// X86_64_LINUX: define{{.*}} x86_intrcc void @foo7(ptr noundef byval(i32) %{{.+}}, i64 noundef %{{.+}})
// X86_64_LINUX: define{{.*}} x86_intrcc void @foo8(ptr noundef byval(i32) %{{.+}})
diff --git a/clang/test/Sema/attr-x86-interrupt.c b/clang/test/Sema/attr-x86-interrupt.c
index 84c60227135fe..ea05e873ffeaa 100644
--- a/clang/test/Sema/attr-x86-interrupt.c
+++ b/clang/test/Sema/attr-x86-interrupt.c
@@ -40,6 +40,9 @@ __attribute__((interrupt)) void foo6(float *a, int b) {}
__attribute__((interrupt)) void foo7(int *a, unsigned b) {}
__attribute__((interrupt)) void foo8(int *a) {}
+typedef *a; // expected-error {{type specifier missing}}
+__attribute__((interrupt)) void b(a) {} // expected-warning {{omitting the parameter name}}
+
void g(void (*fp)(int *));
int main(int argc, char **argv) {
void *ptr = (void *)&foo7;
More information about the cfe-commits
mailing list