[PATCH] D84222: [AST][RecoveryExpr] Error-dependent expression should not be treat as a nullptr pointer constant.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 20 23:12:28 PDT 2020
hokein created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
If an expression is contains-error and its type is unknown (dependent), we
don't treat it as a null pointer constant.
Fix a recovery-ast crash on C.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D84222
Files:
clang/lib/AST/Expr.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
@@ -39,3 +39,14 @@
// CHECK-NEXT: `-DeclRefExpr {{.*}} 'a' 'const int'
static int foo = a++; // verify no crash on local static var decl.
}
+
+void test2() {
+ int* ptr;
+ // FIXME: the top-level expr should be a binary operator.
+ // CHECK: ImplicitCastExpr {{.*}} contains-errors <LValueToRValue>
+ // CHECK-NEXT: `-RecoveryExpr {{.*}} contains-errors lvalue
+ // CHECK-NEXT: |-DeclRefExpr {{.*}} 'ptr' 'int *'
+ // CHECK-NEXT: `-RecoveryExpr {{.*}}
+ // CHECK-NEXT: `-DeclRefExpr {{.*}} 'some_func'
+ ptr = some_func(); // should not crash
+}
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -3744,7 +3744,8 @@
case NPC_NeverValueDependent:
llvm_unreachable("Unexpected value dependent expression!");
case NPC_ValueDependentIsNull:
- if (isTypeDependent() || getType()->isIntegralType(Ctx))
+ if ((!containsErrors() && isTypeDependent()) ||
+ getType()->isIntegralType(Ctx))
return NPCK_ZeroExpression;
else
return NPCK_NotNull;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84222.279429.patch
Type: text/x-patch
Size: 1316 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200721/679a9870/attachment.bin>
More information about the cfe-commits
mailing list