llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: woruyu (woruyu) <details> <summary>Changes</summary> This fixes https://github.com/llvm/llvm-project/issues/242122. When substitution of the controlling type fails, the controlling expression is unset, so isInvalid() returns false. This lets Clang attempt to rebuild the generic selection with a null operand. Use isUsable() to detect when both the expression and type are absent and propagate the substitution failure. Assisted-by: OpenAI Codex --- Full diff: https://github.com/llvm/llvm-project/pull/244586.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.md (+3) - (modified) clang/lib/Sema/TreeTransform.h (+1-1) - (modified) clang/test/SemaCXX/generic-selection.cpp (+10) ``````````diff diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index f17f79eafcb70..76812a8c8e75d 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -1273,6 +1273,9 @@ documentation](CIR/index.md) for more information regarding ClangIR's status and - Fixed bugs where Clang could apply an incorrectly high alignment to a vptr load within a virtual function thunk. (#GH242501) +- Fixed a crash when template substitution produces an invalid controlling type + for `_Generic`. (#GH242122) + #### Bug Fixes to AST Handling - Fixed a non-deterministic ordering of unused local typedefs that made diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 2b6348b7ec8a6..0a72bfe9f440b 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -13842,7 +13842,7 @@ TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { else ControllingType = getDerived().TransformType(E->getControllingType()); - if (ControllingExpr.isInvalid() && !ControllingType) + if (!ControllingExpr.isUsable() && !ControllingType) return ExprError(); SmallVector<Expr *, 4> AssocExprs; diff --git a/clang/test/SemaCXX/generic-selection.cpp b/clang/test/SemaCXX/generic-selection.cpp index ed9d2b7d44be3..8aab5d023aa3e 100644 --- a/clang/test/SemaCXX/generic-selection.cpp +++ b/clang/test/SemaCXX/generic-selection.cpp @@ -90,3 +90,13 @@ void func(struct S s) { (void)_Generic(s, struct W : S { int b; } : 1); // expected-error {{expected '(' for function-style cast or type construction}} } } // namespace GH55562 + +namespace GH242122 { +template <typename T> struct S { + // T() is parsed as a function type returning T. + enum { id = _Generic(T(), int(): 1) }; // expected-error {{function cannot return function type 'void ()'}} +}; + +static_assert(S<int>::id == 1, ""); +template struct S<void()>; // expected-note {{in instantiation of template class 'GH242122::S<void ()>' requested here}} +} // namespace GH242122 `````````` </details> https://github.com/llvm/llvm-project/pull/244586 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
