aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Tooling/Syntax/TreeTest.cpp
diff options
context:
space:
mode:
authorEduardo Caldas <ecaldas@google.com>2020-06-15 17:08:39 +0000
committerEduardo Caldas <ecaldas@google.com>2020-07-10 16:21:11 +0000
commitf33c2c27a8d4ea831aa7c2c2649066be91318d85 (patch)
tree1824386289595d9de6ec3af9dc83c83e01612a3b /clang/unittests/Tooling/Syntax/TreeTest.cpp
parente5123ea248eb460c6695dc28ed2f1cc53495356b (diff)
downloadllvm-f33c2c27a8d4ea831aa7c2c2649066be91318d85.zip
llvm-f33c2c27a8d4ea831aa7c2c2649066be91318d85.tar.gz
llvm-f33c2c27a8d4ea831aa7c2c2649066be91318d85.tar.bz2
Fix crash on `user defined literals`
Summary: Given an UserDefinedLiteral `1.2_w`: Problem: Lexer generates one Token for the literal, but ClangAST references two source locations Fix: Ignore the operator and interpret it as the underlying literal. e.g.: `1.2_w` token generates syntax node IntegerLiteral(1.2_w) Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D82157
Diffstat (limited to 'clang/unittests/Tooling/Syntax/TreeTest.cpp')
-rw-r--r--clang/unittests/Tooling/Syntax/TreeTest.cpp195
1 files changed, 175 insertions, 20 deletions
diff --git a/clang/unittests/Tooling/Syntax/TreeTest.cpp b/clang/unittests/Tooling/Syntax/TreeTest.cpp
index acd0fbf..91e7a8f 100644
--- a/clang/unittests/Tooling/Syntax/TreeTest.cpp
+++ b/clang/unittests/Tooling/Syntax/TreeTest.cpp
@@ -1184,20 +1184,108 @@ void test() {
)txt"));
}
-TEST_P(SyntaxTreeTest, IntegerLiteral) {
+TEST_P(SyntaxTreeTest, UserDefinedLiteral) {
+ if (!GetParam().isCXX11OrLater()) {
+ return;
+ }
EXPECT_TRUE(treeDumpEqual(
R"cpp(
+unsigned operator "" _i(unsigned long long);
+unsigned operator "" _f(long double);
+unsigned operator "" _c(char);
+
+unsigned operator "" _r(const char*); // raw-literal operator
+
+template <char...>
+unsigned operator "" _t(); // numeric literal operator template
+
void test() {
- 12;
- 12u;
- 12l;
- 12ul;
- 014;
- 0XC;
+ 12_i; // call: operator "" _i(12uLL) | kind: integer
+ 1.2_f; // call: operator "" _f(1.2L) | kind: float
+ '2'_c; // call: operator "" _c('2') | kind: char
+
+ // TODO: Generate `FloatUserDefinedLiteralExpression` and
+ // `IntegerUserDefinedLiteralExpression` instead of
+ // `UnknownUserDefinedLiteralExpression`. See `getUserDefinedLiteralKind`
+ 12_r; // call: operator "" _r("12") | kind: integer
+ 1.2_r; // call: operator "" _i("1.2") | kind: float
+ 12_t; // call: operator<'1', '2'> "" _x() | kind: integer
+ 1.2_t; // call: operator<'1', '2'> "" _x() | kind: float
}
-)cpp",
+ )cpp",
R"txt(
*: TranslationUnit
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_i
+| | `-ParametersAndQualifiers
+| | |-(
+| | |-SimpleDeclaration
+| | | |-unsigned
+| | | |-long
+| | | `-long
+| | `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_f
+| | `-ParametersAndQualifiers
+| | |-(
+| | |-SimpleDeclaration
+| | | |-long
+| | | `-double
+| | `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_c
+| | `-ParametersAndQualifiers
+| | |-(
+| | |-SimpleDeclaration
+| | | `-char
+| | `-)
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_r
+| | `-ParametersAndQualifiers
+| | |-(
+| | |-SimpleDeclaration
+| | | |-const
+| | | |-char
+| | | `-SimpleDeclarator
+| | | `-*
+| | `-)
+| `-;
+|-TemplateDeclaration
+| |-template
+| |-<
+| |-SimpleDeclaration
+| | `-char
+| |-...
+| |->
+| `-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_t
+| | `-ParametersAndQualifiers
+| | |-(
+| | `-)
+| `-;
`-SimpleDeclaration
|-void
|-SimpleDeclarator
@@ -1208,28 +1296,95 @@ void test() {
`-CompoundStatement
|-{
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12
+ | |-IntegerUserDefinedLiteralExpression
+ | | `-12_i
| `-;
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12u
+ | |-FloatUserDefinedLiteralExpression
+ | | `-1.2_f
| `-;
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12l
+ | |-CharUserDefinedLiteralExpression
+ | | `-'2'_c
| `-;
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-12ul
+ | |-UnknownUserDefinedLiteralExpression
+ | | `-12_r
| `-;
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-014
+ | |-UnknownUserDefinedLiteralExpression
+ | | `-1.2_r
| `-;
|-ExpressionStatement
- | |-IntegerLiteralExpression
- | | `-0XC
+ | |-UnknownUserDefinedLiteralExpression
+ | | `-12_t
+ | `-;
+ |-ExpressionStatement
+ | |-UnknownUserDefinedLiteralExpression
+ | | `-1.2_t
+ | `-;
+ `-}
+)txt"));
+}
+
+TEST_P(SyntaxTreeTest, UserDefinedLiteralString) {
+ if (!GetParam().isCXX11OrLater()) {
+ return;
+ }
+ EXPECT_TRUE(treeDumpEqual(
+ R"cpp(
+typedef decltype(sizeof(void *)) size_t;
+unsigned operator "" _s(const char*, size_t);
+void test() {
+ "12"_s;// call: operator "" _s("12") | kind: string
+}
+ )cpp",
+ R"txt(
+*: TranslationUnit
+|-SimpleDeclaration
+| |-typedef
+| |-decltype
+| |-(
+| |-UnknownExpression
+| | |-sizeof
+| | |-(
+| | |-void
+| | |-*
+| | `-)
+| |-)
+| |-SimpleDeclarator
+| | `-size_t
+| `-;
+|-SimpleDeclaration
+| |-unsigned
+| |-SimpleDeclarator
+| | |-operator
+| | |-""
+| | |-_s
+| | `-ParametersAndQualifiers
+| | |-(
+| | |-SimpleDeclaration
+| | | |-const
+| | | |-char
+| | | `-SimpleDeclarator
+| | | `-*
+| | |-,
+| | |-SimpleDeclaration
+| | | `-size_t
+| | `-)
+| `-;
+`-SimpleDeclaration
+ |-void
+ |-SimpleDeclarator
+ | |-test
+ | `-ParametersAndQualifiers
+ | |-(
+ | `-)
+ `-CompoundStatement
+ |-{
+ |-ExpressionStatement
+ | |-StringUserDefinedLiteralExpression
+ | | `-"12"_s
| `-;
`-}
)txt"));