https://github.com/DhanashreePetare updated 
https://github.com/llvm/llvm-project/pull/174092

>From 6f757886d527af79081db408c818cce1b6c55311 Mon Sep 17 00:00:00 2001
From: DhanashreePetare <[email protected]>
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 <[email protected]>
---
 clang/docs/ReleaseNotes.rst           |  2 ++
 clang/lib/Sema/SemaDecl.cpp           | 28 +++++++++++++++++++++------
 clang/test/Sema/typeof-asm-noreturn.c | 10 ++++++++++
 3 files changed, 34 insertions(+), 6 deletions(-)
 create mode 100644 clang/test/Sema/typeof-asm-noreturn.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ecdbbc05cdef4..2887c05fec6e3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -506,6 +506,8 @@ Improvements to Coverage Mapping
 
 Bug Fixes in This Version
 -------------------------
+- Avoid crash when declaring functions with ``__typeof``, ``__asm__`` alias 
and ``__attribute__((noreturn))`` in C2X mode. (PR #174092)
+
 - Fix a crash when marco name is empty in ``#pragma push_macro("")`` or
   ``#pragma pop_macro("")``. (#GH149762).
 - Fix a crash in variable length array (e.g. ``int a[*]``) function parameter 
type
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index f636e8e35a3d5..aefb4c7dd476c 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -9529,12 +9529,28 @@ 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
-    bool HasPrototype =
-        (D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype) ||
-        (D.getDeclSpec().isTypeRep() &&
-         SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(), nullptr)
-             ->isFunctionProtoType()) ||
-        (!R->getAsAdjusted<FunctionType>() && R->isFunctionProtoType());
+    // Determine whether the function was written with a prototype. We
+    // consider several sources: an explicit prototype in the declarator,
+    // a typedef reference that resolves to a function prototype, or the
+    // result type `R` being a function prototype.
+    auto hasPrototype = [&]() -> bool {
+      if (D.isFunctionDeclarator() && D.getFunctionTypeInfo().hasPrototype)
+        return true;
+
+      if (D.getDeclSpec().isTypeRep()) {
+        QualType RepTy = 
SemaRef.GetTypeFromParser(D.getDeclSpec().getRepAsType(),
+                                                  nullptr);
+        if (!RepTy.isNull() && RepTy->getAs<FunctionProtoType>())
+          return true;
+      }
+
+      if (!R.isNull() && R->getAs<FunctionProtoType>())
+        return true;
+
+      return false;
+    };
+
+    bool HasPrototype = hasPrototype();
     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);
+}

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to