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 <[email protected]> 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 9c7f7e2b5523ea697738bca2b45beabc384aedf1 Mon Sep 17 00:00:00 2001 From: Serosh-commits <[email protected]> Date: Fri, 27 Feb 2026 15:08:48 +0530 Subject: [PATCH 2/2] relocate IgnoreParens to top of CheckPlaceholderExpr and simplify test --- clang/lib/Sema/SemaExpr.cpp | 18 ++++++++++-------- clang/test/SemaCXX/gh183505.cpp | 14 +++++--------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4f614ca317b38..c223a6fc1e4f5 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -21520,9 +21520,11 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { const BuiltinType *placeholderType = E->getType()->getAsPlaceholderType(); if (!placeholderType) return E; + E = E->IgnoreParens(); + switch (placeholderType->getKind()) { case BuiltinType::UnresolvedTemplate: { - auto *ULE = cast<UnresolvedLookupExpr>(E->IgnoreParens()); + auto *ULE = cast<UnresolvedLookupExpr>(E); const DeclarationNameInfo &NameInfo = ULE->getNameInfo(); // There's only one FoundDecl for UnresolvedTemplate type. See // BuildTemplateIdExpr. @@ -21565,7 +21567,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { /*CanonicalArgs=*/{}, HasAnyDependentTA ? Context.DependentTy : Context.IntTy); return CreateRecoveryExpr(NameInfo.getBeginLoc(), NameInfo.getEndLoc(), {}, - TST); + TST); } // Overloaded expressions. @@ -21591,7 +21593,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { // Bound member functions. case BuiltinType::BoundMember: { ExprResult result = E; - const Expr *BME = E->IgnoreParens(); + const Expr *BME = E; PartialDiagnostic PD = PDiag(diag::err_bound_member_function); // Try to give a nicer diagnostic if it is a bound member that we recognize. if (isa<CXXPseudoDestructorExpr>(BME)) { @@ -21629,11 +21631,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)) { @@ -21672,7 +21674,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { } case BuiltinType::IncompleteMatrixIdx: { - auto *MS = cast<MatrixSubscriptExpr>(E->IgnoreParens()); + auto *MS = cast<MatrixSubscriptExpr>(E); // At this point, we know there was no second [] to complete the operator. // In HLSL, treat "m[row]" as selecting a row lane of column sized vector. if (getLangOpts().HLSL) { @@ -21689,7 +21691,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->IgnoreParens())->isOMPArraySection(); + << cast<ArraySectionExpr>(E)->isOMPArraySection(); return ExprError(); // Expressions of unknown type. diff --git a/clang/test/SemaCXX/gh183505.cpp b/clang/test/SemaCXX/gh183505.cpp index 94c70c3270f72..9d81a1d1205be 100644 --- a/clang/test/SemaCXX/gh183505.cpp +++ b/clang/test/SemaCXX/gh183505.cpp @@ -1,12 +1,8 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s -int ab[7]; -int[(int)(abc<>)]; // expected-error {{use of undeclared identifier 'abc'}} \ - // expected-error {{expected expression}} +// GH183505: Ensure we don't crash when stripping parentheses from placeholder types. -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}} +void test_unresolved_lookup() { + (int)(abc<>); // expected-error {{use of undeclared identifier 'abc'}} + (int)((abc<>)); // expected-error {{use of undeclared identifier 'abc'}} +} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
