[clang] e417f02 - [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag
Congcong Cai via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 14 10:09:49 PDT 2023
Author: Congcong Cai
Date: 2023-03-15T01:08:41+08:00
New Revision: e417f02b5159c13f011335636faaf8c6847b627f
URL: https://github.com/llvm/llvm-project/commit/e417f02b5159c13f011335636faaf8c6847b627f
DIFF: https://github.com/llvm/llvm-project/commit/e417f02b5159c13f011335636faaf8c6847b627f.diff
LOG: [SemaCXX]use CorrectDelayedTyposInExpr in ActOnCXXFoldExpr only when Diag
PR #61326
- fix clang crash when fold expression contains a delayed typos correction.
code snippet in `ActOnCXXFoldExpr`
``` if (!LHS || !RHS) {
Expr *Pack = LHS ? LHS : RHS;
assert(Pack && "fold expression with neither LHS nor RHS");
DiscardOperands();
if (!Pack->containsUnexpandedParameterPack())
return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
<< Pack->getSourceRange();
}
```
`DiscardOperands` will be triggered when LHS/RHS is delayed typo correction expression.
It will output and clean all diagnose but still return a valid expression. (in else branch)
valid expression will be handled in caller function. When caller wants to output the diagnose, the diagnose in delayed typo correction expression has been consumed in `ActOnCXXFoldExpr`. It causes clang crash.
Reviewed By: erichkeane
Differential Revision: https://reviews.llvm.org/D145892
Added:
clang/test/SemaCXX/fold_expr_typo.cpp
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaTemplateVariadic.cpp
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a52af53bbd28..5fae7ce3077a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -197,6 +197,8 @@ Bug Fixes in This Version
be reached despite being reachable. This fixes
`#61177 <https://github.com/llvm/llvm-project/issues/61177>`_ in anticipation
of `CWG2699 <https://wg21.link/CWG2699>_` being accepted by WG21.
+- Fix crash when parsing fold expression containing a delayed typo correction.
+ (`#61326 <https://github.com/llvm/llvm-project/issues/61326>`_)
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 86268b504cbb..dfcc78dafdc4 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -1220,10 +1220,11 @@ ExprResult Sema::ActOnCXXFoldExpr(Scope *S, SourceLocation LParenLoc, Expr *LHS,
if (!LHS || !RHS) {
Expr *Pack = LHS ? LHS : RHS;
assert(Pack && "fold expression with neither LHS nor RHS");
- DiscardOperands();
- if (!Pack->containsUnexpandedParameterPack())
+ if (!Pack->containsUnexpandedParameterPack()) {
+ DiscardOperands();
return Diag(EllipsisLoc, diag::err_pack_expansion_without_parameter_packs)
<< Pack->getSourceRange();
+ }
}
BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Operator);
diff --git a/clang/test/SemaCXX/fold_expr_typo.cpp b/clang/test/SemaCXX/fold_expr_typo.cpp
new file mode 100644
index 000000000000..0ef9c15b5947
--- /dev/null
+++ b/clang/test/SemaCXX/fold_expr_typo.cpp
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+template <typename... T>
+void foo(T &&...Params) {
+ foo<T>(Unknown); // expected-error {{expression contains unexpanded parameter pack 'T'}}\
+ expected-error {{use of undeclared identifier 'Unknown'}}
+ ((foo<T>(Unknown)), ...); // expected-error {{use of undeclared identifier 'Unknown'}}
+}
+
+template <typename... U> struct A {
+ template <typename... T> void foo(T &&...Params) {
+ foo<T>((... + static_cast<U>(1))); // expected-error {{expression contains unexpanded parameter pack 'T'}}
+ }
+};
More information about the cfe-commits
mailing list