Skip to content

Commit 5c8ec3c

Browse files
committed
[CLANG] Set DeclStart at start of parsed attributes
1 parent c5bc577 commit 5c8ec3c

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

clang/lib/Parse/ParseDeclCXX.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3043,6 +3043,16 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
30433043
MaybeParseMicrosoftAttributes(DeclSpecAttrs))
30443044
;
30453045

3046+
SourceLocation DeclStart;
3047+
if (DeclAttrs.Range.isValid()) {
3048+
DeclStart = DeclSpecAttrs.Range.isInvalid()
3049+
? DeclAttrs.Range.getBegin()
3050+
: std::min(DeclAttrs.Range.getBegin(),
3051+
DeclSpecAttrs.Range.getBegin());
3052+
} else {
3053+
DeclStart = DeclSpecAttrs.Range.getBegin();
3054+
}
3055+
30463056
// decl-specifier-seq:
30473057
// Parse the common declaration-specifiers piece.
30483058
ParsingDeclSpec DS(*this, TemplateDiags);
@@ -3070,6 +3080,9 @@ Parser::DeclGroupPtrTy Parser::ParseCXXClassMemberDeclaration(
30703080
// Turn off colon protection that was set for declspec.
30713081
X.restore();
30723082

3083+
if (DeclStart.isValid())
3084+
DS.SetRangeStart(DeclStart);
3085+
30733086
// If we had a free-standing type definition with a missing semicolon, we
30743087
// may get this far before the problem becomes obvious.
30753088
if (DS.hasTagDefinition() &&

clang/test/AST/ast-dump-color.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ struct Invalid {
9191
//CHECK: {{^}}[[Blue]]| `-[[RESET]][[MAGENTA]]DeclRefExpr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:40[[RESET]]> [[Green]]'class Mutex':'Mutex'[[RESET]][[Cyan]] lvalue[[RESET]][[Cyan]][[RESET]] [[GREEN]]Var[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]][[CYAN]] 'mu1'[[RESET]] [[Green]]'class Mutex':'Mutex'[[RESET]] non_odr_use_unevaluated{{$}}
9292
//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
9393
//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]]
94-
//CHECK: {{^}}[[Blue]]| |-[[RESET]][[GREEN]]CXXConstructorDecl[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]line:29:29[[RESET]], [[Yellow]]col:42[[RESET]]> [[Yellow]]col:29[[RESET]] invalid[[CYAN]] Invalid[[RESET]] [[Green]]'void (int)'[[RESET]]
94+
//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]]
9595
//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]]
9696
//CHECK: {{^}}[[Blue]]| | `-[[RESET]][[BLUE]]NoInlineAttr[[RESET]][[Yellow]] 0x{{[0-9a-fA-F]*}}[[RESET]] <[[Yellow]]col:18[[RESET]]>
9797
//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

clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -670,9 +670,18 @@ int main()
670670
// CHECK-NEXT: },
671671
// CHECK-NEXT: "range": {
672672
// CHECK-NEXT: "begin": {
673-
// CHECK-NEXT: "offset": 404,
674-
// CHECK-NEXT: "col": 16,
675-
// CHECK-NEXT: "tokLen": 9
673+
// CHECK-NEXT: "spellingLoc": {
674+
// CHECK-NEXT: "offset": 123,
675+
// CHECK-NEXT: "line": 4,
676+
// CHECK-NEXT: "col": 20,
677+
// CHECK-NEXT: "tokLen": 1
678+
// CHECK-NEXT: },
679+
// CHECK-NEXT: "expansionLoc": {
680+
// CHECK-NEXT: "offset": 393,
681+
// CHECK-NEXT: "line": 17,
682+
// CHECK-NEXT: "col": 5,
683+
// CHECK-NEXT: "tokLen": 10
684+
// CHECK-NEXT: }
676685
// CHECK-NEXT: },
677686
// CHECK-NEXT: "end": {
678687
// CHECK-NEXT: "offset": 481,

clang/test/Index/annotate-attribute.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int templateFunction(T value) __attribute__((annotate("works")));
2424

2525
// CHECK: ClassDecl=Test:3:7 (Definition) Extent=[3:1 - 17:2]
2626
// CHECK-NEXT: CXXAccessSpecifier=:4:1 (Definition) Extent=[4:1 - 4:8]
27-
// CHECK-NEXT: CXXMethod=aMethod:5:51 Extent=[5:46 - 5:60]
27+
// CHECK-NEXT: CXXMethod=aMethod:5:51 Extent=[5:3 - 5:60]
2828
// CHECK-NEXT: attribute(annotate)=spiffy_method Extent=[5:18 - 5:43]
2929
// CHECK-NEXT: CXXAccessSpecifier=:7:1 (Definition) Extent=[7:1 - 7:43]
3030
// CHECK-NEXT: attribute(annotate)=works Extent=[7:23 - 7:40]

clang/test/SemaCXX/warn-thread-safety-analysis.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2434,9 +2434,10 @@ class Foo {
24342434
namespace WarnNoDecl {
24352435

24362436
class Foo {
2437-
void foo(int a); __attribute__((
2438-
exclusive_locks_required(a))); // expected-warning {{declaration does not declare anything}} \
2439-
// expected-warning {{attribute exclusive_locks_required ignored}}
2437+
void foo(int a); __attribute__(( // \
2438+
// expected-warning {{declaration does not declare anything}}
2439+
exclusive_locks_required(a))); // \
2440+
// expected-warning {{attribute exclusive_locks_required ignored}}
24402441

24412442
};
24422443

0 commit comments

Comments
 (0)