[clang] Sema: detect adjusted function prototypes to fix crash with __typeof + __asm + noreturn (#173598) (PR #174092)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jan 2 19:18:54 PST 2026


================
@@ -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 {
----------------
Sirraide wrote:

This condition is complicated enough to where writing it as a function is honestly not a bad idea; names of lambdas should be PascalCase though.

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


More information about the cfe-commits mailing list