llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Dhanashree Petare (DhanashreePetare) <details> <summary>Changes</summary> **Description:** - **Problem:** Clang crashed with an assertion in `CreateNewFunctionDecl` when a function was declared using `__typeof` with an `__asm__` alias and `__attribute__((noreturn))` under `-std=c2x`. - **Change:** Extend prototype detection to recognize adjusted/function types (and handle null `QualType`) so strict-prototype checks no longer trigger incorrectly. Patch in SemaDecl.cpp. - **Test:** Add regression test typeof-asm-noreturn.c. --- Full diff: https://github.com/llvm/llvm-project/pull/174092.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaDecl.cpp (+14-3) - (added) clang/test/Sema/typeof-asm-noreturn.c (+10) ``````````diff diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 11323803e1910..df228811da5d4 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); +} `````````` </details> https://github.com/llvm/llvm-project/pull/174092 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
