https://github.com/shadow-forge-dev updated https://github.com/llvm/llvm-project/pull/183524
>From 0e71e37932c46549c8ef8a1898acbb1bd998d46c Mon Sep 17 00:00:00 2001 From: shadow-forge-dev <[email protected]> Date: Thu, 26 Feb 2026 18:53:45 +0530 Subject: [PATCH 1/2] [Clang] Propagate Error/Instantiation bits from GenericSelectionExpr association types --- clang/lib/AST/ComputeDependence.cpp | 11 +++++++++-- clang/test/Sema/gh176929.c | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 clang/test/Sema/gh176929.c diff --git a/clang/lib/AST/ComputeDependence.cpp b/clang/lib/AST/ComputeDependence.cpp index 8429f17d26be5..45b4a1a260a74 100644 --- a/clang/lib/AST/ComputeDependence.cpp +++ b/clang/lib/AST/ComputeDependence.cpp @@ -720,10 +720,17 @@ ExprDependence clang::computeDependence(GenericSelectionExpr *E, auto D = ContainsUnexpandedPack ? ExprDependence::UnexpandedPack : ExprDependence::None; for (auto *AE : E->getAssocExprs()) - D |= AE->getDependence() & ExprDependence::Error; + D |= AE->getDependence() & + (ExprDependence::Error | ExprDependence::Instantiation); + for (TypeSourceInfo *TSI : E->getAssocTypeSourceInfos()) { + if (TSI) + D |= toExprDependenceAsWritten(TSI->getType()->getDependence()) & + (ExprDependence::Error | ExprDependence::Instantiation); + } if (E->isExprPredicate()) - D |= E->getControllingExpr()->getDependence() & ExprDependence::Error; + D |= E->getControllingExpr()->getDependence() & + (ExprDependence::Error | ExprDependence::Instantiation); else D |= toExprDependenceAsWritten( E->getControllingType()->getType()->getDependence()); diff --git a/clang/test/Sema/gh176929.c b/clang/test/Sema/gh176929.c new file mode 100644 index 0000000000000..99b16d8fbb02e --- /dev/null +++ b/clang/test/Sema/gh176929.c @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +void f(int); + +char *a = _Generic("", char (*)[f(x)]: ""); // expected-error {{use of undeclared identifier 'x'}} \ + // expected-error {{type 'char (*)[f(x)]' in generic association is a variably modified type}} >From a6739f65169d58936521983b164ec38bf10b7e27 Mon Sep 17 00:00:00 2001 From: shadow-forge-dev <[email protected]> Date: Thu, 26 Feb 2026 20:42:04 +0530 Subject: [PATCH 2/2] added in release notes and extra test cases --- clang/docs/ReleaseNotes.rst | 1 + clang/test/Sema/gh176929.c | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 613d87668be18..4fb77ff1d5723 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 in ``_Generic`` selection when an association type is an error type. (#GH176929) OpenACC Specific Changes ------------------------ diff --git a/clang/test/Sema/gh176929.c b/clang/test/Sema/gh176929.c index 99b16d8fbb02e..d8349285f639a 100644 --- a/clang/test/Sema/gh176929.c +++ b/clang/test/Sema/gh176929.c @@ -1,6 +1,12 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s void f(int); +int n = 5; char *a = _Generic("", char (*)[f(x)]: ""); // expected-error {{use of undeclared identifier 'x'}} \ // expected-error {{type 'char (*)[f(x)]' in generic association is a variably modified type}} + +int b = _Generic(1, int[n]: 2, default: 3); // expected-error {{type 'int[n]' in generic association is a variably modified type}} + +int c = _Generic(1, int[n]: 2, char[n]: 3, default: 4); // expected-error {{type 'int[n]' in generic association is a variably modified type}} \ + // expected-error {{type 'char[n]' in generic association is a variably modified type}} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
