Skip to content

Commit dc3957e

Browse files
committed
Include leading attributes in DeclStmt's SourceRange
Differential Revision: https://reviews.llvm.org/D68581 llvm-svn: 375104
1 parent 3ec83e8 commit dc3957e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

clang/lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
220220
Decl =
221221
ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs);
222222
}
223+
if (Attrs.Range.getBegin().isValid())
224+
DeclStart = Attrs.Range.getBegin();
223225
return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
224226
}
225227

clang/test/AST/sourceranges.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,22 @@ struct map {
9292

9393
}; // namespace std
9494

95+
// CHECK: NamespaceDecl {{.*}} attributed_decl
96+
namespace attributed_decl {
97+
void f() {
98+
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:28>
99+
[[maybe_unused]] int i1;
100+
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>
101+
__attribute__((unused)) int i2;
102+
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>
103+
int __attribute__((unused)) i3;
104+
// CHECK: DeclStmt {{.*}} <<built-in>:{{.*}}, {{.*}}:[[@LINE+1]]:40>
105+
__declspec(dllexport) extern int i4;
106+
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:40>
107+
extern int __declspec(dllexport) i5;
108+
}
109+
}
110+
95111
#if __cplusplus >= 201703L
96112
// CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list
97113
std::map<int, int> construct_with_init_list() {

0 commit comments

Comments
 (0)