diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 3bfe4a70bac71..727ab75adae8b 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -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); } diff --git a/clang/test/AST/sourceranges.cpp b/clang/test/AST/sourceranges.cpp index 53f2f57e67545..3c023c8689461 100644 --- a/clang/test/AST/sourceranges.cpp +++ b/clang/test/AST/sourceranges.cpp @@ -92,6 +92,22 @@ struct map { }; // namespace std +// CHECK: NamespaceDecl {{.*}} attributed_decl +namespace attributed_decl { + void f() { + // CHECK: DeclStmt {{.*}} + [[maybe_unused]] int i1; + // CHECK: DeclStmt {{.*}} + __attribute__((unused)) int i2; + // CHECK: DeclStmt {{.*}} + int __attribute__((unused)) i3; + // CHECK: DeclStmt {{.*}} <:{{.*}}, {{.*}}:[[@LINE+1]]:40> + __declspec(dllexport) extern int i4; + // CHECK: DeclStmt {{.*}} + extern int __declspec(dllexport) i5; + } +} + #if __cplusplus >= 201703L // CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list std::map construct_with_init_list() {