[clang] [clang] fix crash when casting a parenthesized unresolved template-id (PR #183633)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 27 05:01:38 PST 2026
https://github.com/Serosh-commits updated https://github.com/llvm/llvm-project/pull/183633
>From 4f2a394c925a34d9037825683c0a9fe07702499e Mon Sep 17 00:00:00 2001
From: Serosh-commits <janmejayapanda400 at gmail.com>
Date: Fri, 27 Feb 2026 03:34:44 +0530
Subject: [PATCH 1/2] add release note and remove extra checks
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Sema/SemaExpr.cpp | 12 ++++++------
clang/test/SemaCXX/gh183505.cpp | 12 ++++++++++++
3 files changed, 19 insertions(+), 6 deletions(-)
create mode 100644 clang/test/SemaCXX/gh183505.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 613d87668be18..def7f6c3d32c2 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -262,6 +262,7 @@ Miscellaneous Clang Crashes Fixed
- Fixed a crash when using loop hint with a value dependent argument inside a
generic lambda. (#GH172289)
- Fixed a crash in C++ overload resolution with ``_Atomic``-qualified argument types. (#GH170433)
+- Fixed a crash when casting a parenthesized unresolved template-id or array section. (#GH183505)
OpenACC Specific Changes
------------------------
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 27f1cce88897b..4f614ca317b38 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -21522,7 +21522,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
switch (placeholderType->getKind()) {
case BuiltinType::UnresolvedTemplate: {
- auto *ULE = cast<UnresolvedLookupExpr>(E);
+ auto *ULE = cast<UnresolvedLookupExpr>(E->IgnoreParens());
const DeclarationNameInfo &NameInfo = ULE->getNameInfo();
// There's only one FoundDecl for UnresolvedTemplate type. See
// BuildTemplateIdExpr.
@@ -21565,7 +21565,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
/*CanonicalArgs=*/{},
HasAnyDependentTA ? Context.DependentTy : Context.IntTy);
return CreateRecoveryExpr(NameInfo.getBeginLoc(), NameInfo.getEndLoc(), {},
- TST);
+ TST);
}
// Overloaded expressions.
@@ -21629,11 +21629,11 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
unsigned BuiltinID = FD->getBuiltinID();
if (BuiltinID == Builtin::BI__noop) {
E = ImpCastExprToType(E, Context.getPointerType(FD->getType()),
- CK_BuiltinFnToFnPtr)
+ CK_BuiltinFnToFnPtr)
.get();
return CallExpr::Create(Context, E, /*Args=*/{}, Context.IntTy,
- VK_PRValue, SourceLocation(),
- FPOptionsOverride());
+ VK_PRValue, SourceLocation(),
+ FPOptionsOverride());
}
if (Context.BuiltinInfo.isInStdNamespace(BuiltinID)) {
@@ -21689,7 +21689,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
// shouldn't need to do any further diagnostic here.
if (!E->containsErrors())
Diag(E->getBeginLoc(), diag::err_array_section_use)
- << cast<ArraySectionExpr>(E)->isOMPArraySection();
+ << cast<ArraySectionExpr>(E->IgnoreParens())->isOMPArraySection();
return ExprError();
// Expressions of unknown type.
diff --git a/clang/test/SemaCXX/gh183505.cpp b/clang/test/SemaCXX/gh183505.cpp
new file mode 100644
index 0000000000000..94c70c3270f72
--- /dev/null
+++ b/clang/test/SemaCXX/gh183505.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+int ab[7];
+int[(int)(abc<>)]; // expected-error {{use of undeclared identifier 'abc'}} \
+ // expected-error {{expected expression}}
+
+int[(int)(undefined_name<>)]; // expected-error {{use of undeclared identifier 'undefined_name'}} \
+ // expected-error {{expected expression}}
+
+int[(int)(<>)]; // expected-error {{expected expression}}
+
+int[(int)(123<>)]; // expected-error {{expected expression}}
>From 91755b1300887d8382d287eade099e31b64731a1 Mon Sep 17 00:00:00 2001
From: Serosh-commits <janmejayapanda400 at gmail.com>
Date: Fri, 27 Feb 2026 15:08:48 +0530
Subject: [PATCH 2/2] some nits and ci fixes
---
clang/lib/Sema/SemaExpr.cpp | 8 ++++----
clang/test/SemaCXX/gh183505.cpp | 14 +++++++++-----
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 4f614ca317b38..20e95d8982781 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -21565,7 +21565,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
/*CanonicalArgs=*/{},
HasAnyDependentTA ? Context.DependentTy : Context.IntTy);
return CreateRecoveryExpr(NameInfo.getBeginLoc(), NameInfo.getEndLoc(), {},
- TST);
+ TST);
}
// Overloaded expressions.
@@ -21629,11 +21629,11 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) {
unsigned BuiltinID = FD->getBuiltinID();
if (BuiltinID == Builtin::BI__noop) {
E = ImpCastExprToType(E, Context.getPointerType(FD->getType()),
- CK_BuiltinFnToFnPtr)
+ CK_BuiltinFnToFnPtr)
.get();
return CallExpr::Create(Context, E, /*Args=*/{}, Context.IntTy,
- VK_PRValue, SourceLocation(),
- FPOptionsOverride());
+ VK_PRValue, SourceLocation(),
+ FPOptionsOverride());
}
if (Context.BuiltinInfo.isInStdNamespace(BuiltinID)) {
diff --git a/clang/test/SemaCXX/gh183505.cpp b/clang/test/SemaCXX/gh183505.cpp
index 94c70c3270f72..f170b29ed0cb8 100644
--- a/clang/test/SemaCXX/gh183505.cpp
+++ b/clang/test/SemaCXX/gh183505.cpp
@@ -1,12 +1,16 @@
// RUN: %clang_cc1 -fsyntax-only -verify %s
-int ab[7];
+int ab[7]; // expected-note {{'ab' declared here}} \
+ // expected-note {{class template declared here}}
int[(int)(abc<>)]; // expected-error {{use of undeclared identifier 'abc'}} \
- // expected-error {{expected expression}}
+ // expected-error {{'ab' is expected to be a non-type template, but instantiated to a class template}} \
+ // expected-error {{expected unqualified-id}}
int[(int)(undefined_name<>)]; // expected-error {{use of undeclared identifier 'undefined_name'}} \
- // expected-error {{expected expression}}
+ // expected-error {{expected unqualified-id}}
-int[(int)(<>)]; // expected-error {{expected expression}}
+int[(int)(<>)]; // expected-error 3 {{expected expression}} \
+ // expected-error {{expected unqualified-id}}
-int[(int)(123<>)]; // expected-error {{expected expression}}
+int[(int)(123<>)]; // expected-error 2 {{expected expression}} \
+ // expected-error {{expected unqualified-id}}
More information about the cfe-commits
mailing list