[clang] 752b971 - [AST] Always set dependent-type for the CallExpr for error-recovery in C.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Sun Jun 11 22:23:24 PDT 2023
Author: Haojian Wu
Date: 2023-06-12T07:04:39+02:00
New Revision: 752b97129789dec1c2b6093bcbf848d6efb14523
URL: https://github.com/llvm/llvm-project/commit/752b97129789dec1c2b6093bcbf848d6efb14523
DIFF: https://github.com/llvm/llvm-project/commit/752b97129789dec1c2b6093bcbf848d6efb14523.diff
LOG: [AST] Always set dependent-type for the CallExpr for error-recovery in C.
When build CallExpr for error-recovery where we have any dependent
child nodes), we should set a dependent type for CallExpr to avoid
running into some unexpected following semantic analysis.
This also aligns with the C++ behavior.
This fixes the symptom crashes: https://github.com/llvm/llvm-project/issues/50244
Differential Revision: https://reviews.llvm.org/D152561
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/lib/Sema/SemaExpr.cpp
clang/test/AST/ast-dump-recovery.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dd31bc6bf3fa3..f0744c5c8310c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -492,6 +492,9 @@ Bug Fixes in This Version
(`See patch <https://reviews.llvm.org/D152303>`_).
- Fix crash when passing a value larger then 64 bits to the aligned attribute.
(`#50534 <https://github.com/llvm/llvm-project/issues/50534>`_).
+- CallExpr built for C error-recovery now is always type-dependent. Fixes a
+ crash when we encounter a unresolved TypoExpr during diagnostic emission.
+ (`#50244 <https://github.com/llvm/llvm-project/issues/50244>_`).
Bug Fixes to Compiler Builtins
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b41dd0785dc80..ba5077e873c09 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7225,13 +7225,8 @@ ExprResult Sema::BuildCallExpr(Scope *Scope, Expr *Fn, SourceLocation LParenLoc,
llvm::any_of(ArgExprs,
[](clang::Expr *E) { return E->containsErrors(); })) &&
"should only occur in error-recovery path.");
- QualType ReturnType =
- llvm::isa_and_nonnull<FunctionDecl>(NDecl)
- ? cast<FunctionDecl>(NDecl)->getCallResultType()
- : Context.DependentTy;
- return CallExpr::Create(Context, Fn, ArgExprs, ReturnType,
- Expr::getValueKindForType(ReturnType), RParenLoc,
- CurFPFeatureOverrides());
+ return CallExpr::Create(Context, Fn, ArgExprs, Context.DependentTy,
+ VK_PRValue, RParenLoc, CurFPFeatureOverrides());
}
return BuildResolvedCallExpr(Fn, NDecl, LParenLoc, ArgExprs, RParenLoc,
ExecConfig, IsExecConfig);
diff --git a/clang/test/AST/ast-dump-recovery.c b/clang/test/AST/ast-dump-recovery.c
index 33f0f2ad3c996..969e0e7941244 100644
--- a/clang/test/AST/ast-dump-recovery.c
+++ b/clang/test/AST/ast-dump-recovery.c
@@ -93,7 +93,7 @@ void test3() {
(*__builtin_classify_type)(1);
extern void ext();
- // CHECK: CallExpr {{.*}} 'void' contains-errors
+ // CHECK: CallExpr {{.*}} '<dependent type>' contains-errors
// CHECK-NEXT: |-DeclRefExpr {{.*}} 'ext'
// CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
ext(undef_var);
@@ -117,3 +117,12 @@ void test5_GH62711() {
// CHECK-NEXT: | `-RecoveryExpr {{.*}} '<dependent type>' contains-errors
if (__builtin_va_arg(undef, int) << 1);
}
+
+void test6_GH50244() {
+ double array[16];
+ // CHECK: UnaryExprOrTypeTraitExpr {{.*}} 'unsigned long' contains-errors sizeof
+ // CHECK-NEXT: `-CallExpr {{.*}} '<dependent type>' contains-errors
+ // CHECK-NEXT: |-DeclRefExpr {{.*}} 'int ()'
+ // CHECK-NEXT: `-RecoveryExpr {{.*}} '<dependent type>'
+ sizeof array / sizeof foo(undef);
+}
More information about the cfe-commits
mailing list