diff options
author | Congcong Cai <congcongcai0907@163.com> | 2023-03-15 01:07:55 +0800 |
---|---|---|
committer | Congcong Cai <congcongcai0907@163.com> | 2023-03-15 01:08:41 +0800 |
commit | e417f02b5159c13f011335636faaf8c6847b627f (patch) | |
tree | c3d57acd74bc359544323a83543290efd13ad9e8 /clang/lib/Sema/SemaTemplateVariadic.cpp | |
parent | 507cba21c382ced5fc075ac74637847fbc2a4c07 (diff) | |
download | llvm-e417f02b5159c13f011335636faaf8c6847b627f.zip llvm-e417f02b5159c13f011335636faaf8c6847b627f.tar.gz llvm-e417f02b5159c13f011335636faaf8c6847b627f.tar.bz2 |
[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
Diffstat (limited to 'clang/lib/Sema/SemaTemplateVariadic.cpp')
-rw-r--r-- | clang/lib/Sema/SemaTemplateVariadic.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaTemplateVariadic.cpp b/clang/lib/Sema/SemaTemplateVariadic.cpp index 86268b5..dfcc78d 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); |