Author: Haojian Wu Date: 2021-02-18T10:32:04+01:00 New Revision: 780ead41e075eb7875874633cd9c6f2d5ceab95e
URL: https://github.com/llvm/llvm-project/commit/780ead41e075eb7875874633cd9c6f2d5ceab95e DIFF: https://github.com/llvm/llvm-project/commit/780ead41e075eb7875874633cd9c6f2d5ceab95e.diff LOG: [Syntax] No crash on OpaqueValueExpr. OpaqueValueExpr doesn't correspond to the concrete syntax, it has invalid source location, ignore them. Reviewed By: kbobyrev Differential Revision: https://reviews.llvm.org/D96112 Added: Modified: clang/lib/Tooling/Syntax/BuildTree.cpp clang/unittests/Tooling/Syntax/BuildTreeTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Tooling/Syntax/BuildTree.cpp b/clang/lib/Tooling/Syntax/BuildTree.cpp index a5cb293832d9..07888b5c32fa 100644 --- a/clang/lib/Tooling/Syntax/BuildTree.cpp +++ b/clang/lib/Tooling/Syntax/BuildTree.cpp @@ -856,6 +856,11 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> { return RecursiveASTVisitor::TraverseStmt(S); } + bool TraverseOpaqueValueExpr(OpaqueValueExpr *VE) { + // OpaqueValue doesn't correspond to concrete syntax, ignore it. + return true; + } + // Some expressions are not yet handled by syntax trees. bool WalkUpFromExpr(Expr *E) { assert(!isImplicitExpr(E) && "should be handled by TraverseStmt"); diff --git a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp index 299a2c320a4c..b6bcd4eb2da5 100644 --- a/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/BuildTreeTest.cpp @@ -512,6 +512,25 @@ TranslationUnit Detached )txt")); } +TEST_P(BuildSyntaxTreeTest, ConditionalOperator) { + // FIXME: conditional expression is not modeled yet. + EXPECT_TRUE(treeDumpEqualOnAnnotations( + R"cpp( +void test() { + [[1?:2]]; +} +)cpp", + {R"txt( +UnknownExpression Expression +|-IntegerLiteralExpression +| `-'1' LiteralToken +|-'?' +|-':' +`-IntegerLiteralExpression + `-'2' LiteralToken +)txt"})); +} + TEST_P(BuildSyntaxTreeTest, UnqualifiedId_Identifier) { EXPECT_TRUE(treeDumpEqualOnAnnotations( R"cpp( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits