[Clang] prevent crash in early parsing of enable_if for C function declarators with identifier-list parameters (#174017)
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
0f3a9f658a/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.
This commit is contained in:
parent
2d26a7b74e
commit
dfc0abd325
@ -632,6 +632,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
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
@ -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,
|
||||
|
||||
4
clang/test/Parser/enableif-attr.cpp
Normal file
4
clang/test/Parser/enableif-attr.cpp
Normal file
@ -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}}
|
||||
Loading…
x
Reference in New Issue
Block a user