Skip to content

[clang][Parser] Fix crash on malformed using declaration in constexpr function #144286

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2025

Conversation

el-ev
Copy link
Member

@el-ev el-ev commented Jun 16, 2025

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jun 16, 2025
@llvmbot
Copy link
Member

llvmbot commented Jun 16, 2025

@llvm/pr-subscribers-clang

Author: Iris Shi (el-ev)

Changes
  • Closes #144264

Full diff: https://github.com/llvm/llvm-project/pull/144286.diff

2 Files Affected:

  • (modified) clang/lib/Parse/ParseDeclCXX.cpp (+4)
  • (added) clang/test/Parser/cxx-invalid-attr-in-constexpr-crash.cpp (+8)
diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index f31c9265a0074..ed401c894f71c 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -760,6 +760,10 @@ Parser::DeclGroupPtrTy Parser::ParseUsingDeclaration(
 
     Decl *AD = ParseAliasDeclarationAfterDeclarator(
         TemplateInfo, UsingLoc, D, DeclEnd, AS, Attrs, &DeclFromDeclSpec);
+
+    if (!AD)
+      return nullptr;
+    
     return Actions.ConvertDeclToDeclGroup(AD, DeclFromDeclSpec);
   }
 
diff --git a/clang/test/Parser/cxx-invalid-attr-in-constexpr-crash.cpp b/clang/test/Parser/cxx-invalid-attr-in-constexpr-crash.cpp
new file mode 100644
index 0000000000000..82104779ca67e
--- /dev/null
+++ b/clang/test/Parser/cxx-invalid-attr-in-constexpr-crash.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// issue144264
+constexpr void test() 
+{ 
+    using TT = struct T[deprecated{}; 
+    // expected-error@-1 {{use of undeclared identifier 'deprecated'}}
+}

@el-ev el-ev requested a review from tbaederr June 16, 2025 01:38
Copy link

github-actions bot commented Jun 16, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@el-ev el-ev force-pushed the users/el-ev/issue144264 branch from 70b7c41 to 4c2a772 Compare June 16, 2025 01:45
@zwuis
Copy link
Contributor

zwuis commented Jun 16, 2025

Please add a release note.

@el-ev el-ev force-pushed the users/el-ev/issue144264 branch from 4c2a772 to fbc207f Compare June 16, 2025 04:32
@el-ev
Copy link
Member Author

el-ev commented Jun 16, 2025

Added.

@el-ev el-ev force-pushed the users/el-ev/issue144264 branch from 9760461 to 6e10acb Compare June 16, 2025 13:40
@el-ev el-ev changed the title [clang][Parser] Fix crash on invalid attribute in constexpr function [clang][Parser] Fix crash on malformed using declaration in constexpr function Jun 16, 2025
Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the test coverage was dropped in a recent commit.

Copy link
Collaborator

@AaronBallman AaronBallman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@el-ev el-ev merged commit f037329 into main Jun 16, 2025
7 of 8 checks passed
@el-ev el-ev deleted the users/el-ev/issue144264 branch June 16, 2025 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clang frontend crashes on invalid usage of [[deprecated]] inside constexpr function
5 participants