llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) <details> <summary>Changes</summary> Fixes #<!-- -->173826 --- This patch resolves an issue where Clang could crash while parsing the `enable_if` attribute on C function declarators with identifier-list parameters. In C, identifier-list function declarators use parameter identifiers rather than full parameter declarations, as specified by the C spec. Since `enable_if` is parsed early to participate in redeclaration checks https://github.com/llvm/llvm-project/blob/0f3a9f658a7f459b9aa701ec42a999b645653862/clang/lib/Parse/ParseDecl.cpp#L674-L675 the parser could encounter such identifiers before their parameter declarations exist and incorrectly assume they were already formed, leading to an assertion failure. This change makes the early `enable_if` parsing path handle parameters that have not yet been declared, preventing the crash while preserving existing behavior for well-formed function prototypes. --- Full diff: https://github.com/llvm/llvm-project/pull/174017.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+1) - (modified) clang/lib/Parse/ParseDecl.cpp (+3-4) - (added) clang/test/Parser/enableif-attr.cpp (+4) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 2319ff13f7864..c55ea757d28cb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -623,6 +623,7 @@ Bug Fixes to C++ Support - Fix the result of ``__is_pointer_interconvertible_base_of`` when arguments are qualified and passed via template parameters. (#GH135273) - Fixed a crash when evaluating nested requirements in requires-expressions that reference invented parameters. (#GH166325) - Fixed a crash when standard comparison categories (e.g. ``std::partial_ordering``) are defined with incorrect static member types. (#GH170015) (#GH56571) +- Fixed a crash when parsing the ``enable_if`` attribute on C function declarations with identifier-list parameters. (#GH173826) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 8688ccf41acb5..0e2caa214f3fd 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -680,10 +680,9 @@ void Parser::ParseGNUAttributeArgs( PrototypeScope.emplace(this, Scope::FunctionPrototypeScope | Scope::FunctionDeclarationScope | Scope::DeclScope); - for (unsigned i = 0; i != FTI.NumParams; ++i) { - ParmVarDecl *Param = cast<ParmVarDecl>(FTI.Params[i].Param); - Actions.ActOnReenterCXXMethodParameter(getCurScope(), Param); - } + for (unsigned i = 0; i != FTI.NumParams; ++i) + Actions.ActOnReenterCXXMethodParameter( + getCurScope(), dyn_cast_or_null<ParmVarDecl>(FTI.Params[i].Param)); } ParseAttributeArgsCommon(AttrName, AttrNameLoc, Attrs, EndLoc, ScopeName, diff --git a/clang/test/Parser/enableif-attr.cpp b/clang/test/Parser/enableif-attr.cpp new file mode 100644 index 0000000000000..6d80a5bd713ce --- /dev/null +++ b/clang/test/Parser/enableif-attr.cpp @@ -0,0 +1,4 @@ +// RUN: %clang_cc1 -x c -fsyntax-only -verify %s + +void f1(x) __attribute__((enable_if(1, ""))); // expected-error {{a parameter list without types is only allowed in a function definition}} +void f2(x, y) __attribute__((enable_if(1, ""))); // expected-error {{a parameter list without types is only allowed in a function definition}} `````````` </details> https://github.com/llvm/llvm-project/pull/174017 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
