This is an archive of the discontinued LLVM Phabricator instance.

[AST][RecoveryExpr] Error-dependent expression should not be treat as a nullptr pointer constant.
ClosedPublic

Authored by hokein on Jul 20 2020, 11:12 PM.

Details

Summary

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.

Diff Detail

Event Timeline

hokein created this revision.Jul 20 2020, 11:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2020, 11:12 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
hokein updated this revision to Diff 279433.Jul 20 2020, 11:48 PM
hokein marked an inline comment as done.

dump cast kind.

hokein added inline comments.
clang/test/AST/ast-dump-recovery.c
51

For references, the crash stacktrace is like below, the cause is that we run into the codepath.

can't implicitly cast lvalue to rvalue with this cast kind: NullToPointer
UNREACHABLE executed at llvm-project/clang/lib/Sema/Sema.cpp:545!
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: ./bin/clang -cc1 -fsyntax-only -ast-dump -frecovery-ast /tmp/t.c 
1.      /tmp/t.c:78:20: current parser token ';'
2.      /tmp/t.c:71:16: parsing function body 'NoCrash'
#13 0x0000000003e75e59 clang::Sema::ImpCastExprToType(clang::Expr*, clang::QualType, clang::CastKind, clang::ExprValueKind, llvm::SmallVector<clang::CXXBaseSpecifier*, 4u> const*, clang::Sema::CheckedConversionKind) llvm-project/clang/lib/Sema/Sema.cpp:582:16
#14 0x0000000004132c06 clang::Sema::CheckSingleAssignmentConstraints(clang::QualType, clang::ActionResult<clang::Expr*, true>&, bool, bool, bool) llvm-project/clang/lib/Sema/SemaExpr.cpp:9374:13
#15 0x00000000041420f6 clang::Sema::CheckAssignmentOperands(clang::Expr*, clang::ActionResult<clang::Expr*, true>&, clang::SourceLocation, clang::QualType) llvm-project/clang/lib/Sema/SemaExpr.cpp:12759:9
#16 0x000000000411e348 clang::Sema::CreateBuiltinBinOp(clang::SourceLocation, clang::BinaryOperatorKind, clang::Expr*, clang::Expr*) llvm-project/clang/lib/Sema/SemaExpr.cpp:0:16
#17 0x00000000041060ba clang::Sema::ActOnBinOp(clang::Scope*, clang::SourceLocation, clang::tok::TokenKind, clang::Expr*, clang::Expr*) llvm-project/clang/lib/Sema/SemaExpr.cpp:14170:1
sammccall accepted this revision.Jul 21 2020, 2:21 AM
sammccall added inline comments.
clang/lib/AST/Expr.cpp
3750

would it be clearer to say if (containsErrors()) return NPCK_NotNull at the top?

Only difference in behavior is not hitting llvm_unreachable if we have NPC_NeverValueDependent... do you think we actually want that?

This revision is now accepted and ready to land.Jul 21 2020, 2:21 AM
hokein updated this revision to Diff 279715.Jul 22 2020, 12:58 AM
hokein marked an inline comment as done.

address comment.

hokein added inline comments.Jul 22 2020, 1:01 AM
clang/lib/AST/Expr.cpp
3750

this is good point, I missed that. thanks!

This revision was automatically updated to reflect the committed changes.