]> granicus.if.org Git - clang/commitdiff
Include leading attributes in DeclStmt's SourceRange
authorStephan Bergmann <sbergman@redhat.com>
Thu, 17 Oct 2019 11:20:21 +0000 (11:20 +0000)
committerStephan Bergmann <sbergman@redhat.com>
Thu, 17 Oct 2019 11:20:21 +0000 (11:20 +0000)
Differential Revision: https://reviews.llvm.org/D68581

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@375104 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Parse/ParseStmt.cpp
test/AST/sourceranges.cpp

index 3bfe4a70bac71343cf728682ecab5208a1b08c70..727ab75adae8bb9aaa027ad5d09ea25459b3dc9f 100644 (file)
@@ -220,6 +220,8 @@ Retry:
         Decl =
             ParseDeclaration(DeclaratorContext::BlockContext, DeclEnd, Attrs);
       }
+      if (Attrs.Range.getBegin().isValid())
+        DeclStart = Attrs.Range.getBegin();
       return Actions.ActOnDeclStmt(Decl, DeclStart, DeclEnd);
     }
 
index 53f2f57e6754503e790c3b214c7b0b973fb628f9..3c023c8689461ad2212c777d6c9443fde4d7ea48 100644 (file)
@@ -92,6 +92,22 @@ struct map {
 \r
 }; // namespace std\r
 \r
+// CHECK: NamespaceDecl {{.*}} attributed_decl\r
+namespace attributed_decl {\r
+  void f() {\r
+    // CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:28>\r
+    [[maybe_unused]] int i1;\r
+    // CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>\r
+    __attribute__((unused)) int i2;\r
+    // CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:35>\r
+    int __attribute__((unused)) i3;\r
+    // CHECK: DeclStmt {{.*}} <<built-in>:{{.*}}, {{.*}}:[[@LINE+1]]:40>\r
+    __declspec(dllexport) extern int i4;\r
+    // CHECK: DeclStmt {{.*}} <line:[[@LINE+1]]:5, col:40>\r
+    extern int __declspec(dllexport) i5;\r
+  }\r
+}\r
+\r
 #if __cplusplus >= 201703L\r
 // CHECK-1Z: FunctionDecl {{.*}} construct_with_init_list\r
 std::map<int, int> construct_with_init_list() {\r