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 7a49766679b0b7c14b7e6117c5af5a0d1162ca10 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] add previous changes --- clang/lib/Sema/SemaExpr.cpp | 9 +++++---- clang/test/SemaCXX/gh183505.cpp | 14 +++++--------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4f614ca317b38..47bb05c18319f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -21520,6 +21520,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { const BuiltinType *placeholderType = E->getType()->getAsPlaceholderType(); if (!placeholderType) return E; + switch (placeholderType->getKind()) { case BuiltinType::UnresolvedTemplate: { auto *ULE = cast<UnresolvedLookupExpr>(E->IgnoreParens()); @@ -21565,7 +21566,7 @@ ExprResult Sema::CheckPlaceholderExpr(Expr *E) { /*CanonicalArgs=*/{}, HasAnyDependentTA ? Context.DependentTy : Context.IntTy); return CreateRecoveryExpr(NameInfo.getBeginLoc(), NameInfo.getEndLoc(), {}, - TST); + TST); } // Overloaded expressions. @@ -21629,11 +21630,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..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
