[PATCH] D95871: [clang] Store the location for invalid type of a declarator.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 2 07:26:18 PST 2021
hokein created this revision.
hokein added a reviewer: sammccall.
Herald added a subscriber: kristof.beyls.
hokein requested review of this revision.
Herald added a project: clang.
Prior to the patch, for an invalid type of declarator, the TInfo's location was
invalid. This patch would improve the tooling (syntax-tree) on handling broken
code.
see the following example:
void test(undef);
// before: ParmVarDecl <col:11, <invalid sloc>> col:16 invalid 'int'
// after: ParmVarDecl <col:11> col:16 invalid 'int'
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95871
Files:
clang/lib/Sema/SemaType.cpp
clang/test/AST/ast-dump-color.cpp
clang/test/AST/ast-dump-invalid.cpp
Index: clang/test/AST/ast-dump-invalid.cpp
===================================================================
--- clang/test/AST/ast-dump-invalid.cpp
+++ clang/test/AST/ast-dump-invalid.cpp
@@ -52,10 +52,10 @@
// CHECK: | |-CXXRecordDecl {{.*}} <col:1, col:8> col:8 implicit struct Str
// CHECK-NEXT: | `-CXXMethodDecl {{.*}} <line:45:4, col:36> col:11 invalid foo1 'double (double, int)'
// CHECK-NEXT: | |-ParmVarDecl {{.*}} <col:16> col:22 'double'
-// CHECK-NEXT: | `-ParmVarDecl {{.*}} <col:24, <invalid sloc>> col:36 invalid 'int'
+// CHECK-NEXT: | `-ParmVarDecl {{.*}} <col:24> col:36 invalid 'int'
// CHECK-NEXT: `-CXXMethodDecl {{.*}} parent {{.*}} <line:47:1, line:48:14> line:47:13 invalid foo1 'double (double, int)'
// CHECK-NEXT: |-ParmVarDecl {{.*}} <col:18> col:24 'double'
-// CHECK-NEXT: |-ParmVarDecl {{.*}} <col:26, <invalid sloc>> col:38 invalid 'int'
+// CHECK-NEXT: |-ParmVarDecl {{.*}} <col:26> col:38 invalid 'int'
// CHECK-NEXT: `-CompoundStmt {{.*}} <line:48:1, col:14>
// CHECK-NEXT: `-ReturnStmt {{.*}} <col:3, col:10>
// CHECK-NEXT: `-ImplicitCastExpr {{.*}} <col:10> 'double' <IntegralToFloating>
Index: clang/test/AST/ast-dump-color.cpp
===================================================================
--- clang/test/AST/ast-dump-color.cpp
+++ clang/test/AST/ast-dump-color.cpp
@@ -92,7 +92,7 @@
//CHECK: {{^}}[[Blue]]|-[[RESET]][[GREEN]]CXXRecordDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:28:1[[RESET]], [[Yellow]]line:30:1[[RESET]]> [[Yellow]]line:28:8[[RESET]] struct[[CYAN]] Invalid[[RESET]] definition
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[GREEN]]CXXRecordDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:1[[RESET]], [[Yellow]]col:8[[RESET]]> [[Yellow]]col:8[[RESET]] implicit referenced struct[[CYAN]] Invalid[[RESET]]
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[GREEN]]CXXConstructorDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:29:3[[RESET]], [[Yellow]]col:42[[RESET]]> [[Yellow]]col:29[[RESET]] invalid[[CYAN]] Invalid[[RESET]] [[Green]]'void (int)'[[RESET]]
-//CHECK: {{^}}[[Blue]]| | |-[[RESET]][[GREEN]]ParmVarDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:37[[RESET]], [[Yellow]]<invalid sloc>[[RESET]]> [[Yellow]]col:42[[RESET]] invalid [[Green]]'int'[[RESET]]
+//CHECK: {{^}}[[Blue]]| | |-[[RESET]][[GREEN]]ParmVarDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:37[[RESET]]> [[Yellow]]col:42[[RESET]] invalid [[Green]]'int'[[RESET]]
//CHECK: {{^}}[[Blue]]| | `-[[RESET]][[BLUE]]NoInlineAttr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:18[[RESET]]>
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[GREEN]]CXXConstructorDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:28:8[[RESET]]> [[Yellow]]col:8[[RESET]] implicit used constexpr[[CYAN]] Invalid[[RESET]] [[Green]]'void () noexcept'[[RESET]] inline
//CHECK: {{^}}[[Blue]]| | `-[[RESET]][[MAGENTA]]CompoundStmt[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:8[[RESET]]>
Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -5656,8 +5656,7 @@
assert(!T.isNull() && "T must not be null at the end of this function");
if (D.isInvalidType())
- return Context.getTrivialTypeSourceInfo(T);
-
+ return Context.getTrivialTypeSourceInfo(T, D.getEndLoc());
return GetTypeSourceInfoForDeclarator(state, T, TInfo);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95871.320783.patch
Type: text/x-patch
Size: 3534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210202/b4334b19/attachment-0001.bin>
More information about the cfe-commits
mailing list