[clang] [Clang] prevent crash in early parsing of enable_if for C function declarators with identifier-list parameters (PR #174017)
Oleksandr T. via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 6 05:33:25 PST 2026
https://github.com/a-tarasyuk updated https://github.com/llvm/llvm-project/pull/174017
>From 52f3db4d583941b2100f9bf6fac68bb65b8047f1 Mon Sep 17 00:00:00 2001
From: Oleksandr Tarasiuk <oleksandr.tarasiuk at outlook.com>
Date: Tue, 30 Dec 2025 21:51:07 +0200
Subject: [PATCH] [Clang] prevent crash in early parsing of enable_if for C
function declarators with identifier-list parameters
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Parse/ParseDecl.cpp | 7 +++----
clang/test/Parser/enableif-attr.cpp | 4 ++++
3 files changed, 8 insertions(+), 4 deletions(-)
create mode 100644 clang/test/Parser/enableif-attr.cpp
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}}
More information about the cfe-commits
mailing list