diff options
author | Eduardo Caldas <ecaldas@google.com> | 2020-06-24 15:11:31 +0000 |
---|---|---|
committer | Eduardo Caldas <ecaldas@google.com> | 2020-07-08 14:09:40 +0000 |
commit | ea8bba7e8d0db3541a386ad649c4bf21d53e8380 (patch) | |
tree | bf17f06ca87a923c500f26d077aeca37b1b53111 /clang/unittests/Tooling/Syntax/TreeTest.cpp | |
parent | 64363a9d93006595d05825ce8fdbcc146aac15b1 (diff) | |
download | llvm-ea8bba7e8d0db3541a386ad649c4bf21d53e8380.zip llvm-ea8bba7e8d0db3541a386ad649c4bf21d53e8380.tar.gz llvm-ea8bba7e8d0db3541a386ad649c4bf21d53e8380.tar.bz2 |
Fix crash on overloaded postfix unary operators due to invalid sloc
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82954
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r-- | clang/unittests/Tooling/Syntax/TreeTest.cpp | 220 |
1 files changed, 220 insertions, 0 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp index 094a495..acd0fbf 100644 --- a/clang/unittests/Tooling/Syntax/TreeTest.cpp +++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp @@ -2193,11 +2193,18 @@ struct X { X& operator=(const X&); friend X operator+(X, const X&); friend bool operator<(const X&, const X&); + friend X operator<<(X&, const X&); + X operator,(X&); + // TODO: Fix crash on member function pointer and add a test for `->*` + // TODO: Unbox operators in syntax tree. + // Represent operators by `+` instead of `IdExpression-UnqualifiedId-+` }; void test(X x, X y) { x = y; x + y; x < y; + x << y; + x, y; } )cpp", R"txt( @@ -2262,6 +2269,40 @@ void test(X x, X y) { | | | | `-& | | | `-) | | `-; +| |-UnknownDeclaration +| | `-SimpleDeclaration +| | |-friend +| | |-X +| | |-SimpleDeclarator +| | | |-operator +| | | |-<< +| | | `-ParametersAndQualifiers +| | | |-( +| | | |-SimpleDeclaration +| | | | |-X +| | | | `-SimpleDeclarator +| | | | `-& +| | | |-, +| | | |-SimpleDeclaration +| | | | |-const +| | | | |-X +| | | | `-SimpleDeclarator +| | | | `-& +| | | `-) +| | `-; +| |-SimpleDeclaration +| | |-X +| | |-SimpleDeclarator +| | | |-operator +| | | |-, +| | | `-ParametersAndQualifiers +| | | |-( +| | | |-SimpleDeclaration +| | | | |-X +| | | | `-SimpleDeclarator +| | | | `-& +| | | `-) +| | `-; | |-} | `-; `-SimpleDeclaration @@ -2319,6 +2360,185 @@ void test(X x, X y) { | | `-UnqualifiedId | | `-y | `-; + |-ExpressionStatement + | |-BinaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-x + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-<< + | | `-IdExpression + | | `-UnqualifiedId + | | `-y + | `-; + |-ExpressionStatement + | |-BinaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-x + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-, + | | `-IdExpression + | | `-UnqualifiedId + | | `-y + | `-; + `-} +)txt")); +} + +TEST_P(SyntaxTreeTest, UserDefinedUnaryPrefixOperator) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +struct X { + X operator++(); + bool operator!(); + X* operator&(); +}; +void test(X x) { + ++x; + !x; + &x; +} +)cpp", + R"txt( +*: TranslationUnit +|-SimpleDeclaration +| |-struct +| |-X +| |-{ +| |-SimpleDeclaration +| | |-X +| | |-SimpleDeclarator +| | | |-operator +| | | |-++ +| | | `-ParametersAndQualifiers +| | | |-( +| | | `-) +| | `-; +| |-SimpleDeclaration +| | |-bool +| | |-SimpleDeclarator +| | | |-operator +| | | |-! +| | | `-ParametersAndQualifiers +| | | |-( +| | | `-) +| | `-; +| |-SimpleDeclaration +| | |-X +| | |-SimpleDeclarator +| | | |-* +| | | |-operator +| | | |-& +| | | `-ParametersAndQualifiers +| | | |-( +| | | `-) +| | `-; +| |-} +| `-; +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | |-SimpleDeclaration + | | |-X + | | `-SimpleDeclarator + | | `-x + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-PrefixUnaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-++ + | | `-IdExpression + | | `-UnqualifiedId + | | `-x + | `-; + |-ExpressionStatement + | |-PrefixUnaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-! + | | `-IdExpression + | | `-UnqualifiedId + | | `-x + | `-; + |-ExpressionStatement + | |-PrefixUnaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-& + | | `-IdExpression + | | `-UnqualifiedId + | | `-x + | `-; + `-} +)txt")); +} + +TEST_P(SyntaxTreeTest, UserDefinedUnaryPostfixOperator) { + if (!GetParam().isCXX()) { + return; + } + EXPECT_TRUE(treeDumpEqual( + R"cpp( +struct X { + X operator++(int); +}; +void test(X x) { + x++; +} +)cpp", + R"txt( +*: TranslationUnit +|-SimpleDeclaration +| |-struct +| |-X +| |-{ +| |-SimpleDeclaration +| | |-X +| | |-SimpleDeclarator +| | | |-operator +| | | |-++ +| | | `-ParametersAndQualifiers +| | | |-( +| | | |-SimpleDeclaration +| | | | `-int +| | | `-) +| | `-; +| |-} +| `-; +`-SimpleDeclaration + |-void + |-SimpleDeclarator + | |-test + | `-ParametersAndQualifiers + | |-( + | |-SimpleDeclaration + | | |-X + | | `-SimpleDeclarator + | | `-x + | `-) + `-CompoundStatement + |-{ + |-ExpressionStatement + | |-PostfixUnaryOperatorExpression + | | |-IdExpression + | | | `-UnqualifiedId + | | | `-x + | | `-IdExpression + | | `-UnqualifiedId + | | `-++ + | `-; `-} )txt")); } |