hokein created this revision. hokein added reviewers: aaron.ballman, sammccall. Herald added a project: All. hokein requested review of this revision. Herald added a project: clang.
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 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D152561 Files: clang/lib/Sema/SemaExpr.cpp clang/test/AST/ast-dump-recovery.c Index: clang/test/AST/ast-dump-recovery.c =================================================================== --- clang/test/AST/ast-dump-recovery.c +++ clang/test/AST/ast-dump-recovery.c @@ -93,7 +93,7 @@ (*__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 @@ // 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); +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -7201,13 +7201,8 @@ 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);
Index: clang/test/AST/ast-dump-recovery.c =================================================================== --- clang/test/AST/ast-dump-recovery.c +++ clang/test/AST/ast-dump-recovery.c @@ -93,7 +93,7 @@ (*__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 @@ // 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); +} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -7201,13 +7201,8 @@ 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);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits