[clang] Sema: detect adjusted function prototypes to fix crash with __typeof + __asm + noreturn (#173598) (PR #174092)
Dhanashree Petare via cfe-commits
cfe-commits at lists.llvm.org
Wed Dec 31 13:31:39 PST 2025
https://github.com/DhanashreePetare updated https://github.com/llvm/llvm-project/pull/174092
>From 4eb5bb3b2bae22efc04e6f0edde649b1d797735b Mon Sep 17 00:00:00 2001
From: DhanashreePetare <dhanashreepetare8125 at gmail.com>
Date: Wed, 31 Dec 2025 19:05:59 +0530
Subject: [PATCH] Sema: handle adjusted function types;add regression test for
__typeof+__asm+noreturn(#173598)
Signed-off-by: DhanashreePetare <dhanashreepetare8125 at gmail.com>
---
clang/lib/Sema/SemaDecl.cpp | 17 ++++++++++++++---
clang/test/Sema/typeof-asm-noreturn.c | 10 ++++++++++
2 files changed, 24 insertions(+), 3 deletions(-)
create mode 100644 clang/test/Sema/typeof-asm-noreturn.c
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f636e8e35a3d5..0941e2e4a6bb0 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9529,12 +9529,23 @@ static FunctionDecl *CreateNewFunctionDecl(Sema &SemaRef, Declarator &D,
// declarator to still have a function type. e.g.,
// typedef void func(int a);
// __attribute__((noreturn)) func other_func; // This has a prototype
+ auto HasFunctionPrototype = [&](QualType T) -> bool {
+ if (T.isNull())
+ return false;
+ if (T->getAs<FunctionProtoType>())
+ return true;
+ if (const FunctionType *Adjusted = T->getAsAdjusted<FunctionType>())
+ return isa<FunctionProtoType>(Adjusted);
+ return false;
+ };
+
bool HasPrototype =
(D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
(D.getDeclSpec().isTypeRep() &&
- SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(), nullptr)
- ->isFunctionProtoType()) ||
- (!R->getAsAdjusted<FunctionType>() && R->isFunctionProtoType());
+ HasFunctionPrototype(
+ SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(),
+ nullptr))) ||
+ HasFunctionPrototype(R);
assert(
(HasPrototype || !SemaRef.getLangOpts().requiresStrictPrototypes()) &&
"Strict prototypes are required");
diff --git a/clang/test/Sema/typeof-asm-noreturn.c b/clang/test/Sema/typeof-asm-noreturn.c
new file mode 100644
index 0000000000000..c96d10b2ea6e6
--- /dev/null
+++ b/clang/test/Sema/typeof-asm-noreturn.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c2x -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+int memcmp(const void *, const void *, unsigned long);
+
+__typeof(memcmp) memcmp_alias __asm__("memory_compare") __attribute__((noreturn));
+
+void use(void) {
+ (void)memcmp_alias(0, 0, 0);
+}
More information about the cfe-commits
mailing list