From 3a7cc81d52f9b7a6e7e94c9efcd1113f1aeb8c9a Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sun, 2 Feb 2014 15:28:46 +0000 Subject: [PATCH] Report a correct end location for nameless parameters. Ranges before: void test(void (*)(int), int, float); ~~~~~~~~~~~~~ ~~~~ ~~~~~~ Ranges after: void test(void (*)(int), int, float); ~~~~~~~~~~~~~ ~~~ ~~~~~ This does not change the actual location of the ParmVarDecl, it still points to the location where the name would be. PR17970. llvm-svn: 200640 --- clang/lib/AST/Decl.cpp | 4 +++- clang/test/Index/annotate-tokens-cxx0x.cpp | 4 ++-- clang/test/Index/annotate-tokens.cpp | 8 ++++---- clang/test/Index/index-templates.cpp | 2 +- clang/test/Index/load-decls.c | 7 +++++++ clang/test/Index/load-namespaces.cpp | 2 +- clang/test/Index/preamble.c | 2 +- clang/test/Index/recursive-cxx-member-calls.cpp | 16 ++++++++-------- clang/test/Index/usrs.m | 6 +++--- 9 files changed, 30 insertions(+), 21 deletions(-) diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index aa92805f5106..1a7e8f7af8cc 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -1569,7 +1569,9 @@ bool typeIsPostfix(clang::QualType QT) { SourceRange DeclaratorDecl::getSourceRange() const { SourceLocation RangeEnd = getLocation(); if (TypeSourceInfo *TInfo = getTypeSourceInfo()) { - if (typeIsPostfix(TInfo->getType())) + // If the declaration has no name or the type extends past the name take the + // end location of the type. + if (!getDeclName() || typeIsPostfix(TInfo->getType())) RangeEnd = TInfo->getTypeLoc().getSourceRange().getEnd(); } return SourceRange(getOuterLocStart(), RangeEnd); diff --git a/clang/test/Index/annotate-tokens-cxx0x.cpp b/clang/test/Index/annotate-tokens-cxx0x.cpp index 4e6d156dfa9f..8992aff25234 100644 --- a/clang/test/Index/annotate-tokens-cxx0x.cpp +++ b/clang/test/Index/annotate-tokens-cxx0x.cpp @@ -83,14 +83,14 @@ void test2() { // CHECK-WITH-OVERRIDE: Identifier: "foo" [19:15 - 19:18] CXXMethod=foo:19:15 (virtual) // CHECK-WITH-OVERRIDE: Punctuation: "(" [19:18 - 19:19] CXXMethod=foo:19:15 (virtual) // CHECK-WITH-OVERRIDE: Identifier: "Int" [19:19 - 19:22] TypeRef=Int:16:13 -// CHECK-WITH-OVERRIDE: Punctuation: ")" [19:22 - 19:23] ParmDecl=:19:22 (Definition) +// CHECK-WITH-OVERRIDE: Punctuation: ")" [19:22 - 19:23] CXXMethod=foo:19:15 (virtual) // CHECK-WITH-OVERRIDE: Punctuation: ";" [19:23 - 19:24] ClassDecl=B:18:7 (Definition) // CHECK-WITH-OVERRIDE: Keyword: "virtual" [23:3 - 23:10] CXXMethod=foo:23:16 (virtual) [Overrides @19:15] // CHECK-WITH-OVERRIDE: Keyword: "void" [23:11 - 23:15] CXXMethod=foo:23:16 (virtual) [Overrides @19:15] // CHECK-WITH-OVERRIDE: Identifier: "foo" [23:16 - 23:19] CXXMethod=foo:23:16 (virtual) [Overrides @19:15] // CHECK-WITH-OVERRIDE: Punctuation: "(" [23:19 - 23:20] CXXMethod=foo:23:16 (virtual) [Overrides @19:15] // CHECK-WITH-OVERRIDE: Identifier: "Int" [23:20 - 23:23] TypeRef=Int:16:13 -// CHECK-WITH-OVERRIDE: Punctuation: ")" [23:23 - 23:24] ParmDecl=:23:23 (Definition) +// CHECK-WITH-OVERRIDE: Punctuation: ")" [23:23 - 23:24] CXXMethod=foo:23:16 (virtual) [Overrides @19:15] // CHECK-WITH-OVERRIDE: Keyword: "override" [23:25 - 23:33] attribute(override)= // CHECK-WITH-OVERRIDE: Punctuation: ";" [23:33 - 23:34] ClassDecl=S:22:7 (Definition) diff --git a/clang/test/Index/annotate-tokens.cpp b/clang/test/Index/annotate-tokens.cpp index 8f2cdeb56435..292e49c08106 100644 --- a/clang/test/Index/annotate-tokens.cpp +++ b/clang/test/Index/annotate-tokens.cpp @@ -71,8 +71,8 @@ void test4() { // CHECK: Keyword: "operator" [9:5 - 9:13] CXXMethod=operator++:9:5 // CHECK: Punctuation: "++" [9:13 - 9:15] CXXMethod=operator++:9:5 // CHECK: Punctuation: "(" [9:15 - 9:16] CXXMethod=operator++:9:5 -// CHECK: Keyword: "int" [9:16 - 9:19] ParmDecl=:9:19 (Definition) -// CHECK: Punctuation: ")" [9:19 - 9:20] ParmDecl=:9:19 (Definition) +// CHECK: Keyword: "int" [9:16 - 9:19] ParmDecl=:9:19 (Definition +// CHECK: Punctuation: ")" [9:19 - 9:20] CXXMethod=operator++:9:5 // CHECK: Punctuation: ";" [9:20 - 9:21] StructDecl=X:7:8 (Definition) // CHECK: Punctuation: "}" [10:1 - 10:2] StructDecl=X:7:8 (Definition) // CHECK: Punctuation: ";" [10:2 - 10:3] @@ -143,7 +143,7 @@ void test4() { // CHECK: Punctuation: "(" [23:22 - 23:23] NonTypeTemplateParameter=tfn:23:18 (Definition) // CHECK: Identifier: "X" [23:23 - 23:24] TypeRef=struct X:7:8 // CHECK: Punctuation: "*" [23:24 - 23:25] ParmDecl=:23:25 (Definition) -// CHECK: Punctuation: ")" [23:25 - 23:26] ParmDecl=:23:25 (Definition) +// CHECK: Punctuation: ")" [23:25 - 23:26] NonTypeTemplateParameter=tfn:23:18 (Definition) // CHECK: Punctuation: ">" [23:26 - 23:27] ClassTemplate=TS:24:8 (Definition) // CHECK: Keyword: "struct" [24:1 - 24:7] ClassTemplate=TS:24:8 (Definition) // CHECK: Identifier: "TS" [24:8 - 24:10] ClassTemplate=TS:24:8 (Definition) @@ -165,7 +165,7 @@ void test4() { // CHECK: Punctuation: "(" [28:22 - 28:23] NonTypeTemplateParameter=tfn:28:18 (Definition) // CHECK: Identifier: "X" [28:23 - 28:24] TypeRef=struct X:7:8 // CHECK: Punctuation: "*" [28:24 - 28:25] ParmDecl=:28:25 (Definition) -// CHECK: Punctuation: ")" [28:25 - 28:26] ParmDecl=:28:25 (Definition) +// CHECK: Punctuation: ")" [28:25 - 28:26] NonTypeTemplateParameter=tfn:28:18 (Definition) // CHECK: Punctuation: ">" [28:26 - 28:27] CXXMethod=foo:29:15 (Definition) // CHECK: Keyword: "void" [29:1 - 29:5] CXXMethod=foo:29:15 (Definition) // CHECK: Identifier: "TS" [29:6 - 29:8] TemplateRef=TS:24:8 diff --git a/clang/test/Index/index-templates.cpp b/clang/test/Index/index-templates.cpp index 05068df5c599..5fcb652cea1a 100644 --- a/clang/test/Index/index-templates.cpp +++ b/clang/test/Index/index-templates.cpp @@ -143,7 +143,7 @@ struct SuperPair : Pair, Pair { }; // CHECK-LOAD: index-templates.cpp:40:8: ClassTemplate=storage:40:8 (Definition) Extent=[39:1 - 40:19] // CHECK-LOAD: index-templates.cpp:39:45: TemplateTemplateParameter=DataStructure:39:45 (Definition) Extent=[39:10 - 39:66] // CHECK-LOAD: index-templates.cpp:39:19: TemplateTypeParameter=:39:19 (Definition) Extent=[39:19 - 39:27] -// CHECK-LOAD: index-templates.cpp:39:37: NonTypeTemplateParameter=:39:37 (Definition) Extent=[39:29 - 39:38] +// CHECK-LOAD: index-templates.cpp:39:37: NonTypeTemplateParameter=:39:37 (Definition) Extent=[39:29 - 39:37] // CHECK-LOAD: index-templates.cpp:39:61: TemplateRef=array:37:8 Extent=[39:61 - 39:66] // CHECK-LOAD: index-templates.cpp:42:18: TypedefDecl=Unsigned:42:18 (Definition) Extent=[42:1 - 42:26] // CHECK-LOAD: index-templates.cpp:45:8: ClassTemplate=value_c:45:8 Extent=[44:1 - 45:15] diff --git a/clang/test/Index/load-decls.c b/clang/test/Index/load-decls.c index e0617c07df42..8d50134b58ae 100644 --- a/clang/test/Index/load-decls.c +++ b/clang/test/Index/load-decls.c @@ -6,6 +6,8 @@ enum Color { Rouge = Red }; +void PR17970(void (*)(int), float); + // RUN: c-index-test -test-load-source all %s | FileCheck %s // CHECK: load-decls.c:1:6: EnumDecl=Color:1:6 (Definition) Extent=[1:1 - 7:2] // CHECK: load-decls.c:2:3: EnumConstantDecl=Red:2:3 (Definition) Extent=[2:3 - 2:6] @@ -13,3 +15,8 @@ enum Color { // CHECK: load-decls.c:4:3: EnumConstantDecl=Blue:4:3 (Definition) Extent=[4:3 - 4:7] // CHECK: load-decls.c:6:3: EnumConstantDecl=Rouge:6:3 (Definition) Extent=[6:3 - 6:14] // CHECK: load-decls.c:6:11: DeclRefExpr=Red:2:3 Extent=[6:11 - 6:14] +// +// CHECK: load-decls.c:9:6: FunctionDecl=PR17970:9:6 Extent=[9:1 - 9:35] +// CHECK: load-decls.c:9:21: ParmDecl=:9:21 (Definition) Extent=[9:14 - 9:27] +// CHECK: load-decls.c:9:26: ParmDecl=:9:26 (Definition) Extent=[9:23 - 9:26] +// CHECK: load-decls.c:9:34: ParmDecl=:9:34 (Definition) Extent=[9:29 - 9:34] diff --git a/clang/test/Index/load-namespaces.cpp b/clang/test/Index/load-namespaces.cpp index 49de66a81d36..7d83aca1d7d1 100644 --- a/clang/test/Index/load-namespaces.cpp +++ b/clang/test/Index/load-namespaces.cpp @@ -40,7 +40,7 @@ namespace my_rel_ops = std::rel_ops; // CHECK: load-namespaces.cpp:16:17: NamespaceRef=std0x:14:11 Extent=[16:17 - 16:22] // CHECK: load-namespaces.cpp:18:11: Namespace=std:18:11 (Definition) Extent=[18:1 - 20:2] // CHECK: load-namespaces.cpp:19:7: FunctionDecl=g:19:7 Extent=[19:3 - 19:13] -// CHECK: load-namespaces.cpp:19:12: ParmDecl=:19:12 (Definition) Extent=[19:9 - 19:13] +// CHECK: load-namespaces.cpp:19:12: ParmDecl=:19:12 (Definition) Extent=[19:9 - 19:12] // CHECK: load-namespaces.cpp:22:12: UsingDeclaration=g[19:7, 10:8] Extent=[22:1 - 22:13] // CHECK: load-namespaces.cpp:22:7: NamespaceRef=std:18:11 Extent=[22:7 - 22:10] // CHECK: load-namespaces.cpp:24:11: FunctionDecl=g:24:11 (Definition) Extent=[24:1 - 25:2] diff --git a/clang/test/Index/preamble.c b/clang/test/Index/preamble.c index 92a9b84546ff..d69644f6da11 100644 --- a/clang/test/Index/preamble.c +++ b/clang/test/Index/preamble.c @@ -17,7 +17,7 @@ void f(int x) { // CHECK: preamble.h:4:9: DeclRefExpr=ptr1:3:10 Extent=[4:9 - 4:13] // CHECK: preamble.h:5:10: IntegerLiteral= Extent=[5:10 - 5:11] // CHECK: preamble.c:5:5: FunctionDecl=wibble:5:5 Extent=[5:1 - 5:16] -// CHECK: preamble.c:5:15: ParmDecl=:5:15 (Definition) Extent=[5:12 - 5:16] +// CHECK: preamble.c:5:15: ParmDecl=:5:15 (Definition) Extent=[5:12 - 5:15] // CHECK-DIAG: preamble.h:4:7:{4:9-4:13}: warning: incompatible pointer types assigning to 'int *' from 'float *' // RUN: env CINDEXTEST_EDITING=1 c-index-test -code-completion-at=%s:8:1 -I %S/Inputs -include %t %s 2> %t.stderr.txt | FileCheck -check-prefix CHECK-CC %s // CHECK-CC: FunctionDecl:{ResultType int}{TypedText bar}{LeftParen (}{Placeholder int i}{RightParen )} (50) diff --git a/clang/test/Index/recursive-cxx-member-calls.cpp b/clang/test/Index/recursive-cxx-member-calls.cpp index cb10166da0c0..04a3c5cf9261 100644 --- a/clang/test/Index/recursive-cxx-member-calls.cpp +++ b/clang/test/Index/recursive-cxx-member-calls.cpp @@ -225,13 +225,13 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) { // CHECK-tokens: Keyword: "const" [7:14 - 7:19] ParmDecl=:7:26 (Definition) // CHECK-tokens: Keyword: "void" [7:20 - 7:24] ParmDecl=:7:26 (Definition) // CHECK-tokens: Punctuation: "*" [7:25 - 7:26] ParmDecl=:7:26 (Definition) -// CHECK-tokens: Punctuation: "," [7:26 - 7:27] ParmDecl=:7:26 (Definition) +// CHECK-tokens: Punctuation: "," [7:26 - 7:27] FunctionDecl=memcmp:7:7 // CHECK-tokens: Keyword: "const" [7:28 - 7:33] ParmDecl=:7:40 (Definition) // CHECK-tokens: Keyword: "void" [7:34 - 7:38] ParmDecl=:7:40 (Definition) // CHECK-tokens: Punctuation: "*" [7:39 - 7:40] ParmDecl=:7:40 (Definition) -// CHECK-tokens: Punctuation: "," [7:40 - 7:41] ParmDecl=:7:40 (Definition) +// CHECK-tokens: Punctuation: "," [7:40 - 7:41] FunctionDecl=memcmp:7:7 // CHECK-tokens: Identifier: "size_t" [7:42 - 7:48] TypeRef=size_t:2:25 -// CHECK-tokens: Punctuation: ")" [7:48 - 7:49] ParmDecl=:7:48 (Definition) +// CHECK-tokens: Punctuation: ")" [7:48 - 7:49] FunctionDecl=memcmp:7:7 // CHECK-tokens: Punctuation: ";" [7:49 - 7:50] UnexposedDecl=:6:8 (Definition) // CHECK-tokens: Identifier: "size_t" [8:3 - 8:9] TypeRef=size_t:2:25 // CHECK-tokens: Identifier: "strlen" [8:10 - 8:16] FunctionDecl=strlen:8:10 @@ -239,7 +239,7 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) { // CHECK-tokens: Keyword: "const" [8:17 - 8:22] ParmDecl=:8:29 (Definition) // CHECK-tokens: Keyword: "char" [8:23 - 8:27] ParmDecl=:8:29 (Definition) // CHECK-tokens: Punctuation: "*" [8:28 - 8:29] ParmDecl=:8:29 (Definition) -// CHECK-tokens: Punctuation: ")" [8:29 - 8:30] ParmDecl=:8:29 (Definition) +// CHECK-tokens: Punctuation: ")" [8:29 - 8:30] FunctionDecl=strlen:8:10 // CHECK-tokens: Punctuation: ";" [8:30 - 8:31] // CHECK-tokens: Punctuation: "}" [9:1 - 9:2] // CHECK-tokens: Keyword: "namespace" [10:1 - 10:10] @@ -1534,13 +1534,13 @@ AttributeList::Kind AttributeList::getKind(const IdentifierInfo * Name) { // CHECK: 4:55: FieldDecl=second:4:55 (Definition) Extent=[4:51 - 4:61] // CHECK: 6:8: UnexposedDecl=:6:8 (Definition) Extent=[6:1 - 9:2] // CHECK: 7:7: FunctionDecl=memcmp:7:7 Extent=[7:3 - 7:49] -// CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:14 - 7:27] -// CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:28 - 7:41] -// CHECK: 7:48: ParmDecl=:7:48 (Definition) Extent=[7:42 - 7:49] +// CHECK: 7:26: ParmDecl=:7:26 (Definition) Extent=[7:14 - 7:26] +// CHECK: 7:40: ParmDecl=:7:40 (Definition) Extent=[7:28 - 7:40] +// CHECK: 7:48: ParmDecl=:7:48 (Definition) Extent=[7:42 - 7:48] // CHECK: 7:42: TypeRef=size_t:2:25 Extent=[7:42 - 7:48] // CHECK: 8:10: FunctionDecl=strlen:8:10 Extent=[8:3 - 8:30] // CHECK: 8:3: TypeRef=size_t:2:25 Extent=[8:3 - 8:9] -// CHECK: 8:29: ParmDecl=:8:29 (Definition) Extent=[8:17 - 8:30] +// CHECK: 8:29: ParmDecl=:8:29 (Definition) Extent=[8:17 - 8:29] // CHECK: 10:17: Namespace=clang:10:17 (Definition) Extent=[10:1 - 35:2] // CHECK: 11:9: ClassDecl=IdentifierInfo:11:9 Extent=[11:3 - 11:23] // CHECK: 12:9: ClassDecl=AttributeList:12:9 (Definition) Extent=[12:3 - 34:4] diff --git a/clang/test/Index/usrs.m b/clang/test/Index/usrs.m index cc2e0fd4b4c2..0ba0e1afdf0f 100644 --- a/clang/test/Index/usrs.m +++ b/clang/test/Index/usrs.m @@ -258,9 +258,9 @@ int test_multi_declaration(void) { // CHECK-source: usrs.m:69:23: UnexposedExpr= Extent=[69:23 - 69:24] // CHECK-source: usrs.m:69:23: IntegerLiteral= Extent=[69:23 - 69:24] // CHECK-source: usrs.m:72:6: FunctionDecl=aux_1:72:6 Extent=[72:1 - 72:26] -// CHECK-source: usrs.m:72:15: ParmDecl=:72:15 (Definition) Extent=[72:12 - 72:16] -// CHECK-source: usrs.m:72:20: ParmDecl=:72:20 (Definition) Extent=[72:17 - 72:21] -// CHECK-source: usrs.m:72:25: ParmDecl=:72:25 (Definition) Extent=[72:22 - 72:26] +// CHECK-source: usrs.m:72:15: ParmDecl=:72:15 (Definition) Extent=[72:12 - 72:15] +// CHECK-source: usrs.m:72:20: ParmDecl=:72:20 (Definition) Extent=[72:17 - 72:20] +// CHECK-source: usrs.m:72:25: ParmDecl=:72:25 (Definition) Extent=[72:22 - 72:25] // CHECK-source: usrs.m:73:5: FunctionDecl=test_multi_declaration:73:5 (Definition) Extent=[73:1 - 77:2] // CHECK-source: usrs.m:73:34: CompoundStmt= Extent=[73:34 - 77:2] // CHECK-source: usrs.m:74:3: DeclStmt= Extent=[74:3 - 74:33]