hokein created this revision. hokein added a reviewer: sammccall. Herald added a project: All. hokein requested review of this revision. Herald added a project: clang.
Fixes https://github.com/llvm/llvm-project/issues/62711 We never set the value-dependent bit for the VAArgExpr before this patch, this was fine becase the dependent-type TypoExpr was always resolved before checking the operands (see https://github.com/llvm/llvm-project/blob/main/clang/lib/Sema/SemaExpr.cpp#L21173-L21180) Now we have enabled the dependence by default for C, the typo expr is not early resolved before checking rather than delayed (share the same codepath with C++). The fix is to propagate the value-dependent bit for VAArgExpr where it contains a TypoExpr, so that the AST node can be handled properly. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D150955 Files: clang/lib/AST/ComputeDependence.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 @@ -109,3 +109,11 @@ b, }; } + +// Verify no crash +void test5_GH62711() { + // CHECK: VAArgExpr {{.*}} 'int' contains-errors + // CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '<dependent type>' contains-errors + // CHECK-NEXT: | `-RecoveryExpr {{.*}} '<dependent type>' contains-errors + if (__builtin_va_arg(undef, int) << 1); +} Index: clang/lib/AST/ComputeDependence.cpp =================================================================== --- clang/lib/AST/ComputeDependence.cpp +++ clang/lib/AST/ComputeDependence.cpp @@ -227,7 +227,7 @@ auto D = toExprDependenceAsWritten( E->getWrittenTypeInfo()->getType()->getDependence()) | (E->getSubExpr()->getDependence() & ~ExprDependence::Type); - return D & ~ExprDependence::Value; + return D; } ExprDependence clang::computeDependence(NoInitExpr *E) {
Index: clang/test/AST/ast-dump-recovery.c =================================================================== --- clang/test/AST/ast-dump-recovery.c +++ clang/test/AST/ast-dump-recovery.c @@ -109,3 +109,11 @@ b, }; } + +// Verify no crash +void test5_GH62711() { + // CHECK: VAArgExpr {{.*}} 'int' contains-errors + // CHECK-NEXT: | `-ImplicitCastExpr {{.*}} '<dependent type>' contains-errors + // CHECK-NEXT: | `-RecoveryExpr {{.*}} '<dependent type>' contains-errors + if (__builtin_va_arg(undef, int) << 1); +} Index: clang/lib/AST/ComputeDependence.cpp =================================================================== --- clang/lib/AST/ComputeDependence.cpp +++ clang/lib/AST/ComputeDependence.cpp @@ -227,7 +227,7 @@ auto D = toExprDependenceAsWritten( E->getWrittenTypeInfo()->getType()->getDependence()) | (E->getSubExpr()->getDependence() & ~ExprDependence::Type); - return D & ~ExprDependence::Value; + return D; } ExprDependence clang::computeDependence(NoInitExpr *E) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits