Skip to content

Commit

Permalink
Include leading attributes in DeclStmt's SourceRange
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D68581

llvm-svn: 375104
  • Loading branch information
stbergmann committed Oct 17, 2019
1 parent 3ec83e8 commit dc3957e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/Parse/ParseStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ StmtResult Parser::ParseStatementOrDeclarationAfterAttributes(
Decl =
ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs);
}
if (Attrs.Range.getBegin().isValid())
DeclStart = Attrs.Range.getBegin();
return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
}

Expand Down
16 changes: 16 additions & 0 deletions clang/test/AST/sourceranges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ struct map {

}; // namespace std

// CHECK: NamespaceDecl {{.*}} attributed_decl
namespace attributed_decl {
void f() {
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:28>
[[maybe_unused]] int i1;
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>
__attribute__((unused)) int i2;
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>
int __attribute__((unused)) i3;
// CHECK: DeclStmt {{.*}} <<built-in>:{{.*}}, {{.*}}:[[@LINE+1]]:40>
__declspec(dllexport) extern int i4;
// CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:40>
extern int __declspec(dllexport) i5;
}
}

#if __cplusplus >= 201703L
// CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list
std::map<int, int> construct_with_init_list() {
Expand Down

0 comments on commit dc3957e

Please sign in to comment.