compnerd created this revision.
compnerd added reviewers: aaron.ballman, sammccall.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
compnerd requested review of this revision.
Herald added a project: clang.

We would previously reject valid input where GNU attributes preceded the 
standard attributes on top-level declarations.  A previous attribute handling 
change had begun rejecting this whilst GCC does honour this layout.  In 
practice, this breaks use of `extern "C"` attributed functions which use both 
standard and GNU attributes as experienced by the Swift runtime.

The majority of the changes here are plumbing the parsed attributes down to the 
use sites.  This incidentally improves source location tracking and token 
handling in the source manager.  The downside of this is that it exposes a 
latent issue in the indexing path where we would try to backtrack to annotate 
attributes post-expansion.  However the proper parsing now introduced results 
in the token stream now retrieving the pre-expanded token whilst still 
associating the attribute to the declaration.  This percolates throughout the 
other various tests.

The one remaining failure with this test is Index/annotate-tokens.c where the 
leading attribute is not associated with the declaration due to the 
`FinalizeDeclarationGroup` not re-associating the attributes with the 
declarations in the declaration group.  However, the declaration still does 
receive the attribute.

Special thanks to Aaron Ballman for the many hints and extensive rubber ducking 
that was involved in identifying the various places where we accidentally 
dropped attributes.

Fixes: #58229


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137979

Files:
  clang/include/clang/Parse/Parser.h
  clang/lib/Parse/ParseDeclCXX.cpp
  clang/lib/Parse/ParseHLSL.cpp
  clang/lib/Parse/ParseObjc.cpp
  clang/lib/Parse/ParseOpenMP.cpp
  clang/lib/Parse/Parser.cpp
  clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_10.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c
  clang/test/AST/ast-dump-openmp-begin-declare-variant_12.c
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
  clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
  clang/test/Parser/attr-order.cpp
  clang/test/Parser/cxx-attributes.cpp
  clang/test/SemaCXX/attr-unavailable.cpp
  clang/test/SemaObjC/objc-asm-attribute-neg-test.m
  clang/unittests/Tooling/SourceCodeTest.cpp

Index: clang/unittests/Tooling/SourceCodeTest.cpp
===================================================================
--- clang/unittests/Tooling/SourceCodeTest.cpp
+++ clang/unittests/Tooling/SourceCodeTest.cpp
@@ -247,14 +247,12 @@
 
   // Includes attributes.
   Visitor.runOverAnnotated(R"cpp(
-      #define ATTR __attribute__((deprecated("message")))
-      $r[[ATTR
+      $r[[__attribute__((deprecated("message")))
       int x;]])cpp");
 
   // Includes attributes and comments together.
   Visitor.runOverAnnotated(R"cpp(
-      #define ATTR __attribute__((deprecated("message")))
-      $r[[ATTR
+      $r[[__attribute__((deprecated("message")))
       // Comment.
       int x;]])cpp");
 }
@@ -402,14 +400,12 @@
 
   // Includes attributes.
   Visit(R"cpp(
-      #define ATTR __attribute__((deprecated("message")))
-      $r[[ATTR
+      $r[[__attribute__((deprecated("message")))
       int x;]])cpp");
 
   // Includes attributes and comments together.
   Visit(R"cpp(
-      #define ATTR __attribute__((deprecated("message")))
-      $r[[ATTR
+      $r[[__attribute__((deprecated("message")))
       // Comment.
       int x;]])cpp");
 }
Index: clang/test/SemaObjC/objc-asm-attribute-neg-test.m
===================================================================
--- clang/test/SemaObjC/objc-asm-attribute-neg-test.m
+++ clang/test/SemaObjC/objc-asm-attribute-neg-test.m
@@ -28,7 +28,7 @@
 @end
 
 __attribute__((objc_runtime_name("MySecretNamespace.ForwardClass")))
-@class ForwardClass; // expected-error {{prefix attribute must be followed by an interface, protocol, or implementation}}
+@class ForwardClass; // expected-error@-1 {{prefix attribute must be followed by an interface, protocol, or implementation}}
 
 __attribute__((objc_runtime_name("MySecretNamespace.ForwardProtocol")))
 @protocol ForwardProtocol;
Index: clang/test/SemaCXX/attr-unavailable.cpp
===================================================================
--- clang/test/SemaCXX/attr-unavailable.cpp
+++ clang/test/SemaCXX/attr-unavailable.cpp
@@ -42,18 +42,18 @@
 // delayed process for 'deprecated'.
 // <rdar://problem/12241361> and <rdar://problem/15584219>
 enum DeprecatedEnum { DE_A, DE_B } __attribute__((deprecated)); // expected-note {{'DeprecatedEnum' has been explicitly marked deprecated here}}
-__attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
 typedef enum DeprecatedEnum AnotherDeprecatedEnum; // expected-warning {{'DeprecatedEnum' is deprecated}}
 
+__attribute__((deprecated)) typedef enum DeprecatedEnum DeprecatedEnum;
 __attribute__((deprecated))
 DeprecatedEnum testDeprecated(DeprecatedEnum X) { return X; }
 
 
 enum UnavailableEnum { UE_A, UE_B } __attribute__((unavailable)); // expected-note {{'UnavailableEnum' has been explicitly marked unavailable here}}
-__attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
 typedef enum UnavailableEnum AnotherUnavailableEnum; // expected-error {{'UnavailableEnum' is unavailable}}
+                                                     //
 
-
+__attribute__((unavailable)) typedef enum UnavailableEnum UnavailableEnum;
 __attribute__((unavailable))
 UnavailableEnum testUnavailable(UnavailableEnum X) { return X; }
 
Index: clang/test/Parser/cxx-attributes.cpp
===================================================================
--- clang/test/Parser/cxx-attributes.cpp
+++ clang/test/Parser/cxx-attributes.cpp
@@ -1,5 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+// GH#58229 - rejects-valid
+__attribute__((__visibility__("default"))) [[nodiscard]] int f();
+[[nodiscard]] __attribute__((__visibility__("default"))) int f();
+
 class c {
   virtual void f1(const char* a, ...)
     __attribute__ (( __format__(__printf__,2,3) )) = 0;
Index: clang/test/Parser/attr-order.cpp
===================================================================
--- clang/test/Parser/attr-order.cpp
+++ clang/test/Parser/attr-order.cpp
@@ -17,8 +17,8 @@
 __declspec(dllexport) [[noreturn]] __attribute__((cdecl)) void d(); // expected-error {{an attribute list cannot appear here}}
 __declspec(dllexport) __attribute__((cdecl)) [[noreturn]] void e(); // expected-error {{an attribute list cannot appear here}}
 __attribute__((cdecl)) __declspec(dllexport) [[noreturn]] void f(); // expected-error {{an attribute list cannot appear here}}
-__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g(); // expected-error {{an attribute list cannot appear here}}
+__attribute__((cdecl)) [[noreturn]] __declspec(dllexport) void g();
 
 [[noreturn]] __attribute__((cdecl))
-[[]] // expected-error {{an attribute list cannot appear here}}
+[[]]
 __declspec(dllexport) void h();
Index: clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
===================================================================
--- clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
+++ clang/test/Analysis/Inputs/expected-plists/retain-release.m.objcpp.plist
@@ -17941,7 +17941,7 @@
      <key>kind</key><string>event</string>
      <key>location</key>
      <dict>
-      <key>line</key><integer>1633</integer>
+      <key>line</key><integer>1634</integer>
       <key>col</key><integer>1</integer>
       <key>file</key><integer>0</integer>
      </dict>
@@ -17959,13 +17959,13 @@
         <key>start</key>
          <array>
           <dict>
-           <key>line</key><integer>1633</integer>
+           <key>line</key><integer>1634</integer>
            <key>col</key><integer>1</integer>
            <key>file</key><integer>0</integer>
           </dict>
           <dict>
-           <key>line</key><integer>1633</integer>
-           <key>col</key><integer>19</integer>
+           <key>line</key><integer>1634</integer>
+           <key>col</key><integer>9</integer>
            <key>file</key><integer>0</integer>
           </dict>
          </array>
@@ -18264,7 +18264,6 @@
   <dict>
    <key>0</key>
    <array>
-    <integer>1633</integer>
     <integer>1634</integer>
     <integer>1635</integer>
     <integer>1643</integer>
@@ -18344,7 +18343,7 @@
      <key>kind</key><string>event</string>
      <key>location</key>
      <dict>
-      <key>line</key><integer>1633</integer>
+      <key>line</key><integer>1634</integer>
       <key>col</key><integer>1</integer>
       <key>file</key><integer>0</integer>
      </dict>
@@ -18362,13 +18361,13 @@
         <key>start</key>
          <array>
           <dict>
-           <key>line</key><integer>1633</integer>
+           <key>line</key><integer>1634</integer>
            <key>col</key><integer>1</integer>
            <key>file</key><integer>0</integer>
           </dict>
           <dict>
-           <key>line</key><integer>1633</integer>
-           <key>col</key><integer>19</integer>
+           <key>line</key><integer>1634</integer>
+           <key>col</key><integer>9</integer>
            <key>file</key><integer>0</integer>
           </dict>
          </array>
@@ -18529,7 +18528,6 @@
   <dict>
    <key>0</key>
    <array>
-    <integer>1633</integer>
     <integer>1634</integer>
     <integer>1635</integer>
     <integer>1655</integer>
@@ -18607,7 +18605,7 @@
      <key>kind</key><string>event</string>
      <key>location</key>
      <dict>
-      <key>line</key><integer>1633</integer>
+      <key>line</key><integer>1634</integer>
       <key>col</key><integer>1</integer>
       <key>file</key><integer>0</integer>
      </dict>
@@ -18625,13 +18623,13 @@
         <key>start</key>
          <array>
           <dict>
-           <key>line</key><integer>1633</integer>
+           <key>line</key><integer>1634</integer>
            <key>col</key><integer>1</integer>
            <key>file</key><integer>0</integer>
           </dict>
           <dict>
-           <key>line</key><integer>1633</integer>
-           <key>col</key><integer>19</integer>
+           <key>line</key><integer>1634</integer>
+           <key>col</key><integer>9</integer>
            <key>file</key><integer>0</integer>
           </dict>
          </array>
@@ -18792,7 +18790,6 @@
   <dict>
    <key>0</key>
    <array>
-    <integer>1633</integer>
     <integer>1634</integer>
     <integer>1635</integer>
     <integer>1659</integer>
Index: clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
===================================================================
--- clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
+++ clang/test/Analysis/Inputs/expected-plists/retain-release.m.objc.plist
@@ -17872,7 +17872,7 @@
      <key>kind</key><string>event</string>
      <key>location</key>
      <dict>
-      <key>line</key><integer>1633</integer>
+      <key>line</key><integer>1634</integer>
       <key>col</key><integer>1</integer>
       <key>file</key><integer>0</integer>
      </dict>
@@ -17890,13 +17890,13 @@
         <key>start</key>
          <array>
           <dict>
-           <key>line</key><integer>1633</integer>
+           <key>line</key><integer>1634</integer>
            <key>col</key><integer>1</integer>
            <key>file</key><integer>0</integer>
           </dict>
           <dict>
-           <key>line</key><integer>1633</integer>
-           <key>col</key><integer>19</integer>
+           <key>line</key><integer>1634</integer>
+           <key>col</key><integer>9</integer>
            <key>file</key><integer>0</integer>
           </dict>
          </array>
@@ -18195,7 +18195,6 @@
   <dict>
    <key>0</key>
    <array>
-    <integer>1633</integer>
     <integer>1634</integer>
     <integer>1635</integer>
     <integer>1643</integer>
@@ -18275,7 +18274,7 @@
      <key>kind</key><string>event</string>
      <key>location</key>
      <dict>
-      <key>line</key><integer>1633</integer>
+      <key>line</key><integer>1634</integer>
       <key>col</key><integer>1</integer>
       <key>file</key><integer>0</integer>
      </dict>
@@ -18293,13 +18292,13 @@
         <key>start</key>
          <array>
           <dict>
-           <key>line</key><integer>1633</integer>
+           <key>line</key><integer>1634</integer>
            <key>col</key><integer>1</integer>
            <key>file</key><integer>0</integer>
           </dict>
           <dict>
-           <key>line</key><integer>1633</integer>
-           <key>col</key><integer>19</integer>
+           <key>line</key><integer>1634</integer>
+           <key>col</key><integer>9</integer>
            <key>file</key><integer>0</integer>
           </dict>
          </array>
@@ -18460,7 +18459,6 @@
   <dict>
    <key>0</key>
    <array>
-    <integer>1633</integer>
     <integer>1634</integer>
     <integer>1635</integer>
     <integer>1655</integer>
@@ -18538,7 +18536,7 @@
      <key>kind</key><string>event</string>
      <key>location</key>
      <dict>
-      <key>line</key><integer>1633</integer>
+      <key>line</key><integer>1634</integer>
       <key>col</key><integer>1</integer>
       <key>file</key><integer>0</integer>
      </dict>
@@ -18556,13 +18554,13 @@
         <key>start</key>
          <array>
           <dict>
-           <key>line</key><integer>1633</integer>
+           <key>line</key><integer>1634</integer>
            <key>col</key><integer>1</integer>
            <key>file</key><integer>0</integer>
           </dict>
           <dict>
-           <key>line</key><integer>1633</integer>
-           <key>col</key><integer>19</integer>
+           <key>line</key><integer>1634</integer>
+           <key>col</key><integer>9</integer>
            <key>file</key><integer>0</integer>
           </dict>
          </array>
@@ -18723,7 +18721,6 @@
   <dict>
    <key>0</key>
    <array>
-    <integer>1633</integer>
     <integer>1634</integer>
     <integer>1635</integer>
     <integer>1659</integer>
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_12.c
===================================================================
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_12.c
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_12.c
@@ -65,56 +65,56 @@
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]] <col:10> 'int' 1
 // C-NEXT: | |-OverloadableAttr [[ADDR_4:0x[a-z0-9]*]] <line:8:37>
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_5:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_6:0x[a-z0-9]*]] <col:22> 'int ({{.*}})' Function [[ADDR_7:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int ({{.*}})'
-// C-NEXT: |-FunctionDecl [[ADDR_8:0x[a-z0-9]*]] <col:22, line:18:1> line:16:5 used also_before 'int (int)'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_6:0x[a-z0-9]*]] <line:34:1> 'int ({{.*}})' Function [[ADDR_7:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |-FunctionDecl [[ADDR_8:0x[a-z0-9]*]] <line:16:1, line:18:1> line:16:5 used also_before 'int (int)'
 // C-NEXT: | |-ParmVarDecl [[ADDR_9:0x[a-z0-9]*]] <col:17, col:21> col:21 i 'int'
 // C-NEXT: | |-CompoundStmt [[ADDR_10:0x[a-z0-9]*]] <col:24, line:18:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_11:0x[a-z0-9]*]] <line:17:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_12:0x[a-z0-9]*]] <col:10> 'int' 2
 // C-NEXT: | |-OverloadableAttr [[ADDR_13:0x[a-z0-9]*]] <line:8:37>
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_14:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_15:0x[a-z0-9]*]] <col:22> 'int (int)' Function [[ADDR_16:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int (int)'
-// C-NEXT: |-FunctionDecl [[ADDR_17:0x[a-z0-9]*]] <col:22, line:22:1> line:20:5 used also_before 'int (float)'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_15:0x[a-z0-9]*]] <line:38:1> 'int (int)' Function [[ADDR_16:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int (int)'
+// C-NEXT: |-FunctionDecl [[ADDR_17:0x[a-z0-9]*]] <line:20:1, line:22:1> line:20:5 used also_before 'int (float)'
 // C-NEXT: | |-ParmVarDecl [[ADDR_18:0x[a-z0-9]*]] <col:17, col:23> col:23 f 'float'
 // C-NEXT: | |-CompoundStmt [[ADDR_19:0x[a-z0-9]*]] <col:26, line:22:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_20:0x[a-z0-9]*]] <line:21:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_21:0x[a-z0-9]*]] <col:10> 'int' 0
 // C-NEXT: | `-OverloadableAttr [[ADDR_22:0x[a-z0-9]*]] <line:8:37>
-// C-NEXT: |-FunctionDecl [[ADDR_23:0x[a-z0-9]*]] <col:22, line:26:1> line:24:5 used also_before 'int (double)'
+// C-NEXT: |-FunctionDecl [[ADDR_23:0x[a-z0-9]*]] <line:24:1, line:26:1> line:24:5 used also_before 'int (double)'
 // C-NEXT: | |-ParmVarDecl [[ADDR_24:0x[a-z0-9]*]] <col:17, col:24> col:24 d 'double'
 // C-NEXT: | |-CompoundStmt [[ADDR_25:0x[a-z0-9]*]] <col:27, line:26:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_26:0x[a-z0-9]*]] <line:25:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_27:0x[a-z0-9]*]] <col:10> 'int' 3
 // C-NEXT: | |-OverloadableAttr [[ADDR_28:0x[a-z0-9]*]] <line:8:37>
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_29:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_30:0x[a-z0-9]*]] <col:22> 'int (double)' Function [[ADDR_31:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int (double)'
-// C-NEXT: |-FunctionDecl [[ADDR_32:0x[a-z0-9]*]] <col:22, line:30:1> line:28:5 used also_before 'int (long)'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_30:0x[a-z0-9]*]] <line:43:1> 'int (double)' Function [[ADDR_31:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int (double)'
+// C-NEXT: |-FunctionDecl [[ADDR_32:0x[a-z0-9]*]] <line:28:1, line:30:1> line:28:5 used also_before 'int (long)'
 // C-NEXT: | |-ParmVarDecl [[ADDR_33:0x[a-z0-9]*]] <col:17, col:22> col:22 l 'long'
 // C-NEXT: | |-CompoundStmt [[ADDR_34:0x[a-z0-9]*]] <col:25, line:30:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_35:0x[a-z0-9]*]] <line:29:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_36:0x[a-z0-9]*]] <col:10> 'int' 4
 // C-NEXT: | |-OverloadableAttr [[ADDR_37:0x[a-z0-9]*]] <line:8:37>
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_38:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_39:0x[a-z0-9]*]] <col:22> 'int (long)' Function [[ADDR_40:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int (long)'
-// C-NEXT: |-FunctionDecl [[ADDR_7]] <col:22, line:36:1> line:8:22 also_before[implementation={vendor(llvm)}] 'int ({{.*}})'
-// C-NEXT: | |-CompoundStmt [[ADDR_41:0x[a-z0-9]*]] <line:34:23, line:36:1>
+// C-NEXT: |   `-DeclRefExpr [[ADDR_39:0x[a-z0-9]*]] <line:47:1> 'int (long)' Function [[ADDR_40:0x[a-z0-9]*]] 'also_before[implementation={vendor(llvm)}]' 'int (long)'
+// C-NEXT: |-FunctionDecl [[ADDR_7]] <line:34:1, line:36:1> line:34:1 also_before[implementation={vendor(llvm)}] 'int ({{.*}})'
+// C-NEXT: | |-CompoundStmt [[ADDR_41:0x[a-z0-9]*]] <col:23, line:36:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_42:0x[a-z0-9]*]] <line:35:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_43:0x[a-z0-9]*]] <col:10> 'int' 0
 // C-NEXT: | `-OverloadableAttr [[ADDR_44:0x[a-z0-9]*]] <line:8:37>
-// C-NEXT: |-FunctionDecl [[ADDR_16]] <col:22, line:40:1> line:8:22 also_before[implementation={vendor(llvm)}] 'int (int)'
-// C-NEXT: | |-ParmVarDecl [[ADDR_45:0x[a-z0-9]*]] <line:38:17, col:21> col:21 i 'int'
+// C-NEXT: |-FunctionDecl [[ADDR_16]] <line:38:1, line:40:1> line:38:1 also_before[implementation={vendor(llvm)}] 'int (int)'
+// C-NEXT: | |-ParmVarDecl [[ADDR_45:0x[a-z0-9]*]] <col:17, col:21> col:21 i 'int'
 // C-NEXT: | |-CompoundStmt [[ADDR_46:0x[a-z0-9]*]] <col:24, line:40:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_47:0x[a-z0-9]*]] <line:39:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_48:0x[a-z0-9]*]] <col:10> 'int' 0
 // C-NEXT: | `-OverloadableAttr [[ADDR_49:0x[a-z0-9]*]] <line:8:37>
-// C-NEXT: |-FunctionDecl [[ADDR_31]] <col:22, line:45:1> line:8:22 also_before[implementation={vendor(llvm)}] 'int (double)'
-// C-NEXT: | |-ParmVarDecl [[ADDR_50:0x[a-z0-9]*]] <line:43:17, col:24> col:24 d 'double'
+// C-NEXT: |-FunctionDecl [[ADDR_31]] <line:43:1, line:45:1> line:43:1 also_before[implementation={vendor(llvm)}] 'int (double)'
+// C-NEXT: | |-ParmVarDecl [[ADDR_50:0x[a-z0-9]*]] <col:17, col:24> col:24 d 'double'
 // C-NEXT: | |-CompoundStmt [[ADDR_51:0x[a-z0-9]*]] <col:27, line:45:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_52:0x[a-z0-9]*]] <line:44:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_53:0x[a-z0-9]*]] <col:10> 'int' 0
 // C-NEXT: | `-OverloadableAttr [[ADDR_54:0x[a-z0-9]*]] <line:8:37>
-// C-NEXT: |-FunctionDecl [[ADDR_40]] <col:22, line:49:1> line:8:22 also_before[implementation={vendor(llvm)}] 'int (long)'
-// C-NEXT: | |-ParmVarDecl [[ADDR_55:0x[a-z0-9]*]] <line:47:17, col:22> col:22 l 'long'
+// C-NEXT: |-FunctionDecl [[ADDR_40]] <line:47:1, line:49:1> line:47:1 also_before[implementation={vendor(llvm)}] 'int (long)'
+// C-NEXT: | |-ParmVarDecl [[ADDR_55:0x[a-z0-9]*]] <col:17, col:22> col:22 l 'long'
 // C-NEXT: | |-CompoundStmt [[ADDR_56:0x[a-z0-9]*]] <col:25, line:49:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_57:0x[a-z0-9]*]] <line:48:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_58:0x[a-z0-9]*]] <col:10> 'int' 0
@@ -130,17 +130,17 @@
 // C-NEXT:         | | | | |-CallExpr [[ADDR_68:0x[a-z0-9]*]] <col:10, col:22> 'int'
 // C-NEXT:         | | | | | `-ImplicitCastExpr [[ADDR_69:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // C-NEXT:         | | | | |   `-DeclRefExpr [[ADDR_70:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' {{.*}}Function [[ADDR_0]] 'also_before' 'int ({{.*}})'
-// C-NEXT:         | | | | `-CallExpr [[ADDR_71:0x[a-z0-9]*]] <line:8:22, line:55:22> 'int'
-// C-NEXT:         | | | |   `-ImplicitCastExpr [[ADDR_72:0x[a-z0-9]*]] <line:8:22> 'int (*)({{.*}})' <FunctionToPointerDecay>
-// C-NEXT:         | | | |     `-DeclRefExpr [[ADDR_6]] <col:22> 'int ({{.*}})' Function [[ADDR_7]] 'also_before[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT:         | | | | `-CallExpr [[ADDR_71:0x[a-z0-9]*]] <line:34:1, line:55:22> 'int'
+// C-NEXT:         | | | |   `-ImplicitCastExpr [[ADDR_72:0x[a-z0-9]*]] <line:34:1> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// C-NEXT:         | | | |     `-DeclRefExpr [[ADDR_6]] <col:1> 'int ({{.*}})' Function [[ADDR_7]] 'also_before[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT:         | | | `-PseudoObjectExpr [[ADDR_73:0x[a-z0-9]*]] <line:55:26, col:39> 'int'
 // C-NEXT:         | | |   |-CallExpr [[ADDR_74:0x[a-z0-9]*]] <col:26, col:39> 'int'
 // C-NEXT:         | | |   | |-ImplicitCastExpr [[ADDR_75:0x[a-z0-9]*]] <col:26> 'int (*)(int)' <FunctionToPointerDecay>
 // C-NEXT:         | | |   | | `-DeclRefExpr [[ADDR_76:0x[a-z0-9]*]] <col:26> 'int (int)' {{.*}}Function [[ADDR_8]] 'also_before' 'int (int)'
 // C-NEXT:         | | |   | `-IntegerLiteral [[ADDR_77:0x[a-z0-9]*]] <col:38> 'int' 1
-// C-NEXT:         | | |   `-CallExpr [[ADDR_78:0x[a-z0-9]*]] <line:8:22, line:55:39> 'int'
-// C-NEXT:         | | |     |-ImplicitCastExpr [[ADDR_79:0x[a-z0-9]*]] <line:8:22> 'int (*)(int)' <FunctionToPointerDecay>
-// C-NEXT:         | | |     | `-DeclRefExpr [[ADDR_15]] <col:22> 'int (int)' Function [[ADDR_16]] 'also_before[implementation={vendor(llvm)}]' 'int (int)'
+// C-NEXT:         | | |   `-CallExpr [[ADDR_78:0x[a-z0-9]*]] <line:38:1, line:55:39> 'int'
+// C-NEXT:         | | |     |-ImplicitCastExpr [[ADDR_79:0x[a-z0-9]*]] <line:38:1> 'int (*)(int)' <FunctionToPointerDecay>
+// C-NEXT:         | | |     | `-DeclRefExpr [[ADDR_15]] <col:1> 'int (int)' Function [[ADDR_16]] 'also_before[implementation={vendor(llvm)}]' 'int (int)'
 // C-NEXT:         | | |     `-IntegerLiteral [[ADDR_77]] <line:55:38> 'int' 1
 // C-NEXT:         | | `-CallExpr [[ADDR_80:0x[a-z0-9]*]] <col:43, col:59> 'int'
 // C-NEXT:         | |   |-ImplicitCastExpr [[ADDR_81:0x[a-z0-9]*]] <col:43> 'int (*)(float)' <FunctionToPointerDecay>
@@ -151,18 +151,18 @@
 // C-NEXT:         |   | |-ImplicitCastExpr [[ADDR_86:0x[a-z0-9]*]] <col:63> 'int (*)(double)' <FunctionToPointerDecay>
 // C-NEXT:         |   | | `-DeclRefExpr [[ADDR_87:0x[a-z0-9]*]] <col:63> 'int (double)' {{.*}}Function [[ADDR_23]] 'also_before' 'int (double)'
 // C-NEXT:         |   | `-FloatingLiteral [[ADDR_88:0x[a-z0-9]*]] <col:75> 'double' 3.000000e+00
-// C-NEXT:         |   `-CallExpr [[ADDR_89:0x[a-z0-9]*]] <line:8:22, line:55:78> 'int'
-// C-NEXT:         |     |-ImplicitCastExpr [[ADDR_90:0x[a-z0-9]*]] <line:8:22> 'int (*)(double)' <FunctionToPointerDecay>
-// C-NEXT:         |     | `-DeclRefExpr [[ADDR_30]] <col:22> 'int (double)' Function [[ADDR_31]] 'also_before[implementation={vendor(llvm)}]' 'int (double)'
+// C-NEXT:         |   `-CallExpr [[ADDR_89:0x[a-z0-9]*]] <line:43:1, line:55:78> 'int'
+// C-NEXT:         |     |-ImplicitCastExpr [[ADDR_90:0x[a-z0-9]*]] <line:43:1> 'int (*)(double)' <FunctionToPointerDecay>
+// C-NEXT:         |     | `-DeclRefExpr [[ADDR_30]] <col:1> 'int (double)' Function [[ADDR_31]] 'also_before[implementation={vendor(llvm)}]' 'int (double)'
 // C-NEXT:         |     `-FloatingLiteral [[ADDR_88]] <line:55:75> 'double' 3.000000e+00
 // C-NEXT:         `-PseudoObjectExpr [[ADDR_91:0x[a-z0-9]*]] <col:82, col:96> 'int'
 // C-NEXT:           |-CallExpr [[ADDR_92:0x[a-z0-9]*]] <col:82, col:96> 'int'
 // C-NEXT:           | |-ImplicitCastExpr [[ADDR_93:0x[a-z0-9]*]] <col:82> 'int (*)(long)' <FunctionToPointerDecay>
 // C-NEXT:           | | `-DeclRefExpr [[ADDR_94:0x[a-z0-9]*]] <col:82> 'int (long)' {{.*}}Function [[ADDR_32]] 'also_before' 'int (long)'
 // C-NEXT:           | `-IntegerLiteral [[ADDR_95:0x[a-z0-9]*]] <col:94> 'long' 4
-// C-NEXT:           `-CallExpr [[ADDR_96:0x[a-z0-9]*]] <line:8:22, line:55:96> 'int'
-// C-NEXT:             |-ImplicitCastExpr [[ADDR_97:0x[a-z0-9]*]] <line:8:22> 'int (*)(long)' <FunctionToPointerDecay>
-// C-NEXT:             | `-DeclRefExpr [[ADDR_39]] <col:22> 'int (long)' Function [[ADDR_40]] 'also_before[implementation={vendor(llvm)}]' 'int (long)'
+// C-NEXT:           `-CallExpr [[ADDR_96:0x[a-z0-9]*]] <line:47:1, line:55:96> 'int'
+// C-NEXT:             |-ImplicitCastExpr [[ADDR_97:0x[a-z0-9]*]] <line:47:1> 'int (*)(long)' <FunctionToPointerDecay>
+// C-NEXT:             | `-DeclRefExpr [[ADDR_39]] <col:1> 'int (long)' Function [[ADDR_40]] 'also_before[implementation={vendor(llvm)}]' 'int (long)'
 // C-NEXT:             `-IntegerLiteral [[ADDR_95]] <line:55:94> 'long' 4
 
 // CXX:      |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:14:1> line:12:5 used also_before 'int ({{.*}})'
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c
===================================================================
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_11.c
@@ -47,12 +47,12 @@
 //  - we see the specialization in the AST
 //  - we pick the right callees
 
-// C:      |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}, line:13:27> col:11 implicit used also_after1 'int ({{.*}})'
+// C:      |-FunctionDecl [[ADDR_0:0x[a-z0-9]*]] <{{.*}}:13:7, col:27> col:11 implicit used also_after1 'int ({{.*}})'
 // C-NEXT: | |-ConstAttr [[ADDR_1:0x[a-z0-9]*]] <line:9:30>
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_2:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_3:0x[a-z0-9]*]] <col:15> 'int ({{.*}})' Function [[ADDR_4:0x[a-z0-9]*]] 'also_after1[implementation={vendor(llvm)}]' 'int ({{.*}})'
-// C-NEXT: |-FunctionDecl [[ADDR_4]] <col:15, line:15:1> line:9:15 also_after1[implementation={vendor(llvm)}] 'int ({{.*}})'
-// C-NEXT: | |-CompoundStmt [[ADDR_5:0x[a-z0-9]*]] <line:13:29, line:15:1>
+// C-NEXT: |   `-DeclRefExpr [[ADDR_3:0x[a-z0-9]*]] <line:13:7> 'int ({{.*}})' Function [[ADDR_4:0x[a-z0-9]*]] 'also_after1[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |-FunctionDecl [[ADDR_4]] <col:7, line:15:1> line:13:7 also_after1[implementation={vendor(llvm)}] 'int ({{.*}})'
+// C-NEXT: | |-CompoundStmt [[ADDR_5:0x[a-z0-9]*]] <col:29, line:15:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_6:0x[a-z0-9]*]] <line:14:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_7:0x[a-z0-9]*]] <col:10> 'int' 0
 // C-NEXT: | `-ConstAttr [[ADDR_8:0x[a-z0-9]*]] <line:9:30>
@@ -63,11 +63,11 @@
 // C-NEXT: | `-CompoundStmt [[ADDR_13:0x[a-z0-9]*]] <col:30, line:18:1>
 // C-NEXT: |   `-ReturnStmt [[ADDR_14:0x[a-z0-9]*]] <line:17:3, col:10>
 // C-NEXT: |     `-IntegerLiteral [[ADDR_15:0x[a-z0-9]*]] <col:10> 'int' 0
-// C-NEXT: |-FunctionDecl [[ADDR_16:0x[a-z0-9]*]] <line:19:1, col:46> col:30 implicit used also_after3 'int ({{.*}})'
+// C-NEXT: |-FunctionDecl [[ADDR_16:0x[a-z0-9]*]] <line:19:26, col:46> col:30 implicit used also_after3 'int ({{.*}})'
 // C-NEXT: | |-NoThrowAttr [[ADDR_17:0x[a-z0-9]*]] <col:16>
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <col:1> 'int ({{.*}})' Function [[ADDR_20:0x[a-z0-9]*]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}})'
-// C-NEXT: |-FunctionDecl [[ADDR_20]] <col:1, line:21:1> line:19:1 also_after3[implementation={vendor(llvm)}] 'int ({{.*}})'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <col:26> 'int ({{.*}})' Function [[ADDR_20:0x[a-z0-9]*]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |-FunctionDecl [[ADDR_20]] <col:26, line:21:1> line:19:26 also_after3[implementation={vendor(llvm)}] 'int ({{.*}})'
 // C-NEXT: | |-CompoundStmt [[ADDR_21:0x[a-z0-9]*]] <col:48, line:21:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_22:0x[a-z0-9]*]] <line:20:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_23:0x[a-z0-9]*]] <col:10> 'int' 0
@@ -91,7 +91,7 @@
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_41:0x[a-z0-9]*]] <col:10> 'int' 1
 // C-NEXT: | |-ConstAttr [[ADDR_42:0x[a-z0-9]*]] <line:9:30> Inherited
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_43:0x[a-z0-9]*]] <<invalid sloc>> Inherited Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_3]] <col:15> 'int ({{.*}})' Function [[ADDR_4]] 'also_after1[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_3]] <line:13:7> 'int ({{.*}})' Function [[ADDR_4]] 'also_after1[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT: |-FunctionDecl [[ADDR_44:0x[a-z0-9]*]] prev [[ADDR_9]] <line:30:1, line:32:1> line:30:5 used also_after2 'int ({{.*}})'
 // C-NEXT: | |-CompoundStmt [[ADDR_45:0x[a-z0-9]*]] <col:23, line:32:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_46:0x[a-z0-9]*]] <line:31:3, col:10>
@@ -104,7 +104,7 @@
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_52:0x[a-z0-9]*]] <col:10> 'int' 3
 // C-NEXT: | |-NoThrowAttr [[ADDR_53:0x[a-z0-9]*]] <line:19:16> Inherited
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_54:0x[a-z0-9]*]] <<invalid sloc>> Inherited Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_19]] <col:1> 'int ({{.*}})' Function [[ADDR_20]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_19]] <col:26> 'int ({{.*}})' Function [[ADDR_20]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT: |-FunctionDecl [[ADDR_55:0x[a-z0-9]*]] prev [[ADDR_25]] <line:36:1, line:38:1> line:36:5 used also_after4 'int ({{.*}})'
 // C-NEXT: | |-CompoundStmt [[ADDR_56:0x[a-z0-9]*]] <col:23, line:38:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_57:0x[a-z0-9]*]] <line:37:3, col:10>
@@ -124,9 +124,9 @@
 // C-NEXT:         | | | |-CallExpr [[ADDR_70:0x[a-z0-9]*]] <col:10, col:22> 'int'
 // C-NEXT:         | | | | `-ImplicitCastExpr [[ADDR_71:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // C-NEXT:         | | | |   `-DeclRefExpr [[ADDR_72:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' Function [[ADDR_38]] 'also_after1' 'int ({{.*}})'
-// C-NEXT:         | | | `-CallExpr [[ADDR_73:0x[a-z0-9]*]] <line:9:15, line:43:22> 'int'
-// C-NEXT:         | | |   `-ImplicitCastExpr [[ADDR_74:0x[a-z0-9]*]] <line:9:15> 'int (*)({{.*}})' <FunctionToPointerDecay>
-// C-NEXT:         | | |     `-DeclRefExpr [[ADDR_3]] <col:15> 'int ({{.*}})' Function [[ADDR_4]] 'also_after1[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT:         | | | `-CallExpr [[ADDR_73:0x[a-z0-9]*]] <line:13:7, line:43:22> 'int'
+// C-NEXT:         | | |   `-ImplicitCastExpr [[ADDR_74:0x[a-z0-9]*]] <line:13:7> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// C-NEXT:         | | |     `-DeclRefExpr [[ADDR_3]] <col:7> 'int ({{.*}})' Function [[ADDR_4]] 'also_after1[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT:         | | `-PseudoObjectExpr [[ADDR_75:0x[a-z0-9]*]] <line:43:26, col:38> 'int'
 // C-NEXT:         | |   |-CallExpr [[ADDR_76:0x[a-z0-9]*]] <col:26, col:38> 'int'
 // C-NEXT:         | |   | `-ImplicitCastExpr [[ADDR_77:0x[a-z0-9]*]] <col:26> 'int (*)({{.*}})' <FunctionToPointerDecay>
@@ -138,9 +138,9 @@
 // C-NEXT:         |   |-CallExpr [[ADDR_82:0x[a-z0-9]*]] <col:42, col:54> 'int'
 // C-NEXT:         |   | `-ImplicitCastExpr [[ADDR_83:0x[a-z0-9]*]] <col:42> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // C-NEXT:         |   |   `-DeclRefExpr [[ADDR_84:0x[a-z0-9]*]] <col:42> 'int ({{.*}})' Function [[ADDR_49]] 'also_after3' 'int ({{.*}})'
-// C-NEXT:         |   `-CallExpr [[ADDR_85:0x[a-z0-9]*]] <line:19:1, line:43:54> 'int'
-// C-NEXT:         |     `-ImplicitCastExpr [[ADDR_86:0x[a-z0-9]*]] <line:19:1> 'int (*)({{.*}})' <FunctionToPointerDecay>
-// C-NEXT:         |       `-DeclRefExpr [[ADDR_19]] <col:1> 'int ({{.*}})' Function [[ADDR_20]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT:         |   `-CallExpr [[ADDR_85:0x[a-z0-9]*]] <line:19:26, line:43:54> 'int'
+// C-NEXT:         |     `-ImplicitCastExpr [[ADDR_86:0x[a-z0-9]*]] <line:19:26> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// C-NEXT:         |       `-DeclRefExpr [[ADDR_19]] <col:26> 'int ({{.*}})' Function [[ADDR_20]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT:         `-PseudoObjectExpr [[ADDR_87:0x[a-z0-9]*]] <line:43:58, col:70> 'int'
 // C-NEXT:           |-CallExpr [[ADDR_88:0x[a-z0-9]*]] <col:58, col:70> 'int'
 // C-NEXT:           | `-ImplicitCastExpr [[ADDR_89:0x[a-z0-9]*]] <col:58> 'int (*)({{.*}})' <FunctionToPointerDecay>
@@ -163,10 +163,10 @@
 // CXX-NEXT: | `-CompoundStmt [[ADDR_11:0x[a-z0-9]*]] <col:30, line:18:1>
 // CXX-NEXT: |   `-ReturnStmt [[ADDR_12:0x[a-z0-9]*]] <line:17:3, col:10>
 // CXX-NEXT: |     `-IntegerLiteral [[ADDR_13:0x[a-z0-9]*]] <col:10> 'int' 0
-// CXX-NEXT: |-FunctionDecl [[ADDR_14:0x[a-z0-9]*]] <line:19:1, col:46> col:30 implicit used also_after3 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT: |-FunctionDecl [[ADDR_14:0x[a-z0-9]*]] <line:19:26, col:46> col:30 implicit used also_after3 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_15:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// CXX-NEXT: |   `-DeclRefExpr [[ADDR_16:0x[a-z0-9]*]] <col:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_17:0x[a-z0-9]*]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
-// CXX-NEXT: |-FunctionDecl [[ADDR_17]] <col:1, line:21:1> line:19:1 also_after3[implementation={vendor(llvm)}] 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT: |   `-DeclRefExpr [[ADDR_16:0x[a-z0-9]*]] <col:26> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_17:0x[a-z0-9]*]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT: |-FunctionDecl [[ADDR_17]] <col:26, line:21:1> line:19:26 also_after3[implementation={vendor(llvm)}] 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT: | `-CompoundStmt [[ADDR_18:0x[a-z0-9]*]] <col:48, line:21:1>
 // CXX-NEXT: |   `-ReturnStmt [[ADDR_19:0x[a-z0-9]*]] <line:20:3, col:10>
 // CXX-NEXT: |     `-IntegerLiteral [[ADDR_20:0x[a-z0-9]*]] <col:10> 'int' 0
@@ -196,7 +196,7 @@
 // CXX-NEXT: | | `-ReturnStmt [[ADDR_42:0x[a-z0-9]*]] <line:34:3, col:10>
 // CXX-NEXT: | |   `-IntegerLiteral [[ADDR_43:0x[a-z0-9]*]] <col:10> 'int' 3
 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_44:0x[a-z0-9]*]] <<invalid sloc>> Inherited Implicit implementation={vendor(llvm)}
-// CXX-NEXT: |   `-DeclRefExpr [[ADDR_16]] <line:19:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_17]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT: |   `-DeclRefExpr [[ADDR_16]] <line:19:26> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_17]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT: |-FunctionDecl [[ADDR_45:0x[a-z0-9]*]] <line:36:1, line:38:1> line:36:5 invalid also_after4 'int ({{.*}})'
 // CXX-NEXT: | |-CompoundStmt [[ADDR_46:0x[a-z0-9]*]] <col:23, line:38:1>
 // CXX-NEXT: | | `-ReturnStmt [[ADDR_47:0x[a-z0-9]*]] <line:37:3, col:10>
@@ -228,9 +228,9 @@
 // CXX-NEXT:         |   |-CallExpr [[ADDR_70:0x[a-z0-9]*]] <col:42, col:54> 'int'
 // CXX-NEXT:         |   | `-ImplicitCastExpr [[ADDR_71:0x[a-z0-9]*]] <col:42> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // CXX-NEXT:         |   |   `-DeclRefExpr [[ADDR_72:0x[a-z0-9]*]] <col:42> 'int ({{.*}})' {{.*}}Function [[ADDR_40]] 'also_after3' 'int ({{.*}})'
-// CXX-NEXT:         |   `-CallExpr [[ADDR_73:0x[a-z0-9]*]] <line:19:1, line:43:54> 'int'
-// CXX-NEXT:         |     `-ImplicitCastExpr [[ADDR_74:0x[a-z0-9]*]] <line:19:1> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay>
-// CXX-NEXT:         |       `-DeclRefExpr [[ADDR_16]] <col:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_17]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT:         |   `-CallExpr [[ADDR_73:0x[a-z0-9]*]] <line:19:26, line:43:54> 'int'
+// CXX-NEXT:         |     `-ImplicitCastExpr [[ADDR_74:0x[a-z0-9]*]] <line:19:26> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay>
+// CXX-NEXT:         |       `-DeclRefExpr [[ADDR_16]] <col:26> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_17]] 'also_after3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT:         `-PseudoObjectExpr [[ADDR_75:0x[a-z0-9]*]] <line:43:58, col:70> 'int'
 // CXX-NEXT:           |-CallExpr [[ADDR_76:0x[a-z0-9]*]] <col:58, col:70> 'int'
 // CXX-NEXT:           | `-ImplicitCastExpr [[ADDR_77:0x[a-z0-9]*]] <col:58> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay>
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant_10.c
===================================================================
--- clang/test/AST/ast-dump-openmp-begin-declare-variant_10.c
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant_10.c
@@ -51,7 +51,7 @@
 // C-NEXT: | | `-ReturnStmt [[ADDR_2:0x[a-z0-9]*]] <line:12:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]] <col:10> 'int' 1
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_4:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]] <line:8:15> 'int ({{.*}})' Function [[ADDR_6:0x[a-z0-9]*]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_5:0x[a-z0-9]*]] <line:25:7> 'int ({{.*}})' Function [[ADDR_6:0x[a-z0-9]*]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT: |-FunctionDecl [[ADDR_7:0x[a-z0-9]*]] <line:14:1, line:16:1> line:14:5 used also_before2 'int ({{.*}})'
 // C-NEXT: | |-CompoundStmt [[ADDR_8:0x[a-z0-9]*]] <col:24, line:16:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_9:0x[a-z0-9]*]] <line:15:3, col:10>
@@ -63,15 +63,15 @@
 // C-NEXT: | | `-ReturnStmt [[ADDR_16:0x[a-z0-9]*]] <line:18:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_17:0x[a-z0-9]*]] <col:10> 'int' 3
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// C-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <line:31:1> 'int ({{.*}})' Function [[ADDR_20:0x[a-z0-9]*]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <line:31:26> 'int ({{.*}})' Function [[ADDR_20:0x[a-z0-9]*]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT: |-FunctionDecl [[ADDR_21:0x[a-z0-9]*]] <line:20:1, line:22:1> line:20:5 used also_before4 'int ({{.*}})'
 // C-NEXT: | |-CompoundStmt [[ADDR_22:0x[a-z0-9]*]] <col:24, line:22:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_23:0x[a-z0-9]*]] <line:21:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_24:0x[a-z0-9]*]] <col:10> 'int' 4
 // C-NEXT: | `-OMPDeclareVariantAttr [[ADDR_25:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
 // C-NEXT: |   `-DeclRefExpr [[ADDR_26:0x[a-z0-9]*]] <line:34:1> 'int ({{.*}})' Function [[ADDR_27:0x[a-z0-9]*]] 'also_before4[implementation={vendor(llvm)}]' 'int ({{.*}})'
-// C-NEXT: |-FunctionDecl [[ADDR_6]] <line:8:15, line:27:1> line:8:15 also_before1[implementation={vendor(llvm)}] 'int ({{.*}})'
-// C-NEXT: | |-CompoundStmt [[ADDR_28:0x[a-z0-9]*]] <line:25:30, line:27:1>
+// C-NEXT: |-FunctionDecl [[ADDR_6]] <line:25:7, line:27:1> line:25:7 also_before1[implementation={vendor(llvm)}] 'int ({{.*}})'
+// C-NEXT: | |-CompoundStmt [[ADDR_28:0x[a-z0-9]*]] <col:30, line:27:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_29:0x[a-z0-9]*]] <line:26:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_30:0x[a-z0-9]*]] <col:10> 'int' 0
 // C-NEXT: | `-ConstAttr [[ADDR_31:0x[a-z0-9]*]] <line:8:30>
@@ -79,7 +79,7 @@
 // C-NEXT: | `-CompoundStmt [[ADDR_32:0x[a-z0-9]*]] <col:31, line:30:1>
 // C-NEXT: |   `-ReturnStmt [[ADDR_33:0x[a-z0-9]*]] <line:29:3, col:10>
 // C-NEXT: |     `-IntegerLiteral [[ADDR_34:0x[a-z0-9]*]] <col:10> 'int' 0
-// C-NEXT: |-FunctionDecl [[ADDR_20]] <line:31:1, line:33:1> line:31:1 also_before3[implementation={vendor(llvm)}] 'int ({{.*}})'
+// C-NEXT: |-FunctionDecl [[ADDR_20]] <line:31:26, line:33:1> line:31:26 also_before3[implementation={vendor(llvm)}] 'int ({{.*}})'
 // C-NEXT: | |-CompoundStmt [[ADDR_35:0x[a-z0-9]*]] <col:49, line:33:1>
 // C-NEXT: | | `-ReturnStmt [[ADDR_36:0x[a-z0-9]*]] <line:32:3, col:10>
 // C-NEXT: | |   `-IntegerLiteral [[ADDR_37:0x[a-z0-9]*]] <col:10> 'int' 0
@@ -101,9 +101,9 @@
 // C-NEXT:         | | | |-CallExpr [[ADDR_52:0x[a-z0-9]*]] <col:10, col:23> 'int'
 // C-NEXT:         | | | | `-ImplicitCastExpr [[ADDR_53:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // C-NEXT:         | | | |   `-DeclRefExpr [[ADDR_54:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' Function [[ADDR_0]] 'also_before1' 'int ({{.*}})'
-// C-NEXT:         | | | `-CallExpr [[ADDR_55:0x[a-z0-9]*]] <line:8:15, line:42:23> 'int'
-// C-NEXT:         | | |   `-ImplicitCastExpr [[ADDR_56:0x[a-z0-9]*]] <line:8:15> 'int (*)({{.*}})' <FunctionToPointerDecay>
-// C-NEXT:         | | |     `-DeclRefExpr [[ADDR_5]] <col:15> 'int ({{.*}})' Function [[ADDR_6]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT:         | | | `-CallExpr [[ADDR_55:0x[a-z0-9]*]] <line:25:7, line:42:23> 'int'
+// C-NEXT:         | | |   `-ImplicitCastExpr [[ADDR_56:0x[a-z0-9]*]] <line:25:7> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// C-NEXT:         | | |     `-DeclRefExpr [[ADDR_5]] <col:7> 'int ({{.*}})' Function [[ADDR_6]] 'also_before1[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT:         | | `-PseudoObjectExpr [[ADDR_57:0x[a-z0-9]*]] <line:42:27, col:40> 'int'
 // C-NEXT:         | |   |-CallExpr [[ADDR_58:0x[a-z0-9]*]] <col:27, col:40> 'int'
 // C-NEXT:         | |   | `-ImplicitCastExpr [[ADDR_59:0x[a-z0-9]*]] <col:27> 'int (*)({{.*}})' <FunctionToPointerDecay>
@@ -115,9 +115,9 @@
 // C-NEXT:         |   |-CallExpr [[ADDR_64:0x[a-z0-9]*]] <col:44, col:57> 'int'
 // C-NEXT:         |   | `-ImplicitCastExpr [[ADDR_65:0x[a-z0-9]*]] <col:44> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // C-NEXT:         |   |   `-DeclRefExpr [[ADDR_66:0x[a-z0-9]*]] <col:44> 'int ({{.*}})' Function [[ADDR_14]] 'also_before3' 'int ({{.*}})'
-// C-NEXT:         |   `-CallExpr [[ADDR_67:0x[a-z0-9]*]] <line:31:1, line:42:57> 'int'
-// C-NEXT:         |     `-ImplicitCastExpr [[ADDR_68:0x[a-z0-9]*]] <line:31:1> 'int (*)({{.*}})' <FunctionToPointerDecay>
-// C-NEXT:         |       `-DeclRefExpr [[ADDR_19]] <col:1> 'int ({{.*}})' Function [[ADDR_20]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}})'
+// C-NEXT:         |   `-CallExpr [[ADDR_67:0x[a-z0-9]*]] <line:31:26, line:42:57> 'int'
+// C-NEXT:         |     `-ImplicitCastExpr [[ADDR_68:0x[a-z0-9]*]] <line:31:26> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// C-NEXT:         |       `-DeclRefExpr [[ADDR_19]] <col:26> 'int ({{.*}})' Function [[ADDR_20]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}})'
 // C-NEXT:         `-PseudoObjectExpr [[ADDR_69:0x[a-z0-9]*]] <line:42:61, col:74> 'int'
 // C-NEXT:           |-CallExpr [[ADDR_70:0x[a-z0-9]*]] <col:61, col:74> 'int'
 // C-NEXT:           | `-ImplicitCastExpr [[ADDR_71:0x[a-z0-9]*]] <col:61> 'int (*)({{.*}})' <FunctionToPointerDecay>
@@ -143,7 +143,7 @@
 // CXX-NEXT: | | `-ReturnStmt [[ADDR_16:0x[a-z0-9]*]] <line:18:3, col:10>
 // CXX-NEXT: | |   `-IntegerLiteral [[ADDR_17:0x[a-z0-9]*]] <col:10> 'int' 3
 // CXX-NEXT: | `-OMPDeclareVariantAttr [[ADDR_18:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={vendor(llvm)}
-// CXX-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <line:31:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_20:0x[a-z0-9]*]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT: |   `-DeclRefExpr [[ADDR_19:0x[a-z0-9]*]] <line:31:26> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_20:0x[a-z0-9]*]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT: |-FunctionDecl [[ADDR_21:0x[a-z0-9]*]] <line:20:1, line:22:1> line:20:5 used also_before4 'int ({{.*}})'
 // CXX-NEXT: | |-CompoundStmt [[ADDR_22:0x[a-z0-9]*]] <col:24, line:22:1>
 // CXX-NEXT: | | `-ReturnStmt [[ADDR_23:0x[a-z0-9]*]] <line:21:3, col:10>
@@ -158,7 +158,7 @@
 // CXX-NEXT: | `-CompoundStmt [[ADDR_31:0x[a-z0-9]*]] <col:31, line:30:1>
 // CXX-NEXT: |   `-ReturnStmt [[ADDR_32:0x[a-z0-9]*]] <line:29:3, col:10>
 // CXX-NEXT: |     `-IntegerLiteral [[ADDR_33:0x[a-z0-9]*]] <col:10> 'int' 0
-// CXX-NEXT: |-FunctionDecl [[ADDR_20]] <line:31:1, line:33:1> line:31:1 also_before3[implementation={vendor(llvm)}] 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT: |-FunctionDecl [[ADDR_20]] <line:31:26, line:33:1> line:31:26 also_before3[implementation={vendor(llvm)}] 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT: | `-CompoundStmt [[ADDR_34:0x[a-z0-9]*]] <col:49, line:33:1>
 // CXX-NEXT: |   `-ReturnStmt [[ADDR_35:0x[a-z0-9]*]] <line:32:3, col:10>
 // CXX-NEXT: |     `-IntegerLiteral [[ADDR_36:0x[a-z0-9]*]] <col:10> 'int' 0
@@ -191,9 +191,9 @@
 // CXX-NEXT:         |   |-CallExpr [[ADDR_60:0x[a-z0-9]*]] <col:44, col:57> 'int'
 // CXX-NEXT:         |   | `-ImplicitCastExpr [[ADDR_61:0x[a-z0-9]*]] <col:44> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // CXX-NEXT:         |   |   `-DeclRefExpr [[ADDR_62:0x[a-z0-9]*]] <col:44> 'int ({{.*}})' {{.*}}Function [[ADDR_14]] 'also_before3' 'int ({{.*}})'
-// CXX-NEXT:         |   `-CallExpr [[ADDR_63:0x[a-z0-9]*]] <line:31:1, line:42:57> 'int'
-// CXX-NEXT:         |     `-ImplicitCastExpr [[ADDR_64:0x[a-z0-9]*]] <line:31:1> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay>
-// CXX-NEXT:         |       `-DeclRefExpr [[ADDR_19]] <col:1> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_20]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
+// CXX-NEXT:         |   `-CallExpr [[ADDR_63:0x[a-z0-9]*]] <line:31:26, line:42:57> 'int'
+// CXX-NEXT:         |     `-ImplicitCastExpr [[ADDR_64:0x[a-z0-9]*]] <line:31:26> 'int (*)({{.*}}) __attribute__((nothrow))' <FunctionToPointerDecay>
+// CXX-NEXT:         |       `-DeclRefExpr [[ADDR_19]] <col:26> 'int ({{.*}}) __attribute__((nothrow))' Function [[ADDR_20]] 'also_before3[implementation={vendor(llvm)}]' 'int ({{.*}}) __attribute__((nothrow))'
 // CXX-NEXT:         `-PseudoObjectExpr [[ADDR_65:0x[a-z0-9]*]] <line:42:61, col:74> 'int'
 // CXX-NEXT:           |-CallExpr [[ADDR_66:0x[a-z0-9]*]] <col:61, col:74> 'int'
 // CXX-NEXT:           | `-ImplicitCastExpr [[ADDR_67:0x[a-z0-9]*]] <col:61> 'int (*)({{.*}})' <FunctionToPointerDecay>
Index: clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
===================================================================
--- clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
+++ clang/test/AST/ast-dump-openmp-begin-declare-variant-varying-return.c
@@ -78,44 +78,44 @@
 // C_FLOAT-NEXT: | |   `-ImplicitCastExpr [[ADDR_3:0x[a-z0-9]*]] <col:34> 'float' <IntegralToFloating>
 // C_FLOAT-NEXT: | |     `-IntegerLiteral [[ADDR_4:0x[a-z0-9]*]] <col:34> 'int' 0
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_5:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_6:0x[a-z0-9]*]] <col:22, line:34:1> line:32:11 used also_before 'float (int)'
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_6:0x[a-z0-9]*]] <line:14:19, line:34:1> line:32:11 used also_before 'float (int)'
 // C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_7:0x[a-z0-9]*]] <col:23, col:27> col:27 i 'int'
 // C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_8:0x[a-z0-9]*]] <col:30, line:34:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_9:0x[a-z0-9]*]] <line:33:3, line:15:34>
 // C_FLOAT-NEXT: | |   `-ImplicitCastExpr [[ADDR_10:0x[a-z0-9]*]] <col:34> 'float' <IntegralToFloating>
 // C_FLOAT-NEXT: | |     `-IntegerLiteral [[ADDR_11:0x[a-z0-9]*]] <col:34> 'int' 0
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_12:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_13:0x[a-z0-9]*]] <col:22, line:40:1> line:10:22 also_before[implementation={extension(disable_implicit_base)}] 'int ({{.*}})'
-// C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_14:0x[a-z0-9]*]] <line:38:23, line:40:1>
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_13:0x[a-z0-9]*]] <line:38:1, line:40:1> line:38:1 also_before[implementation={extension(disable_implicit_base)}] 'int ({{.*}})'
+// C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_14:0x[a-z0-9]*]] <col:23, line:40:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_15:0x[a-z0-9]*]] <line:39:3, line:16:37>
 // C_FLOAT-NEXT: | |   `-IntegerLiteral [[ADDR_16:0x[a-z0-9]*]] <col:37> 'int' 1
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_17:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_18:0x[a-z0-9]*]] <col:22, line:44:1> line:10:22 also_before[implementation={extension(disable_implicit_base)}] 'int (int)'
-// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_19:0x[a-z0-9]*]] <line:42:17, col:21> col:21 i 'int'
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_18:0x[a-z0-9]*]] <line:42:1, line:44:1> line:42:1 also_before[implementation={extension(disable_implicit_base)}] 'int (int)'
+// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_19:0x[a-z0-9]*]] <col:17, col:21> col:21 i 'int'
 // C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_20:0x[a-z0-9]*]] <col:24, line:44:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_21:0x[a-z0-9]*]] <line:43:3, line:16:37>
 // C_FLOAT-NEXT: | |   `-IntegerLiteral [[ADDR_22:0x[a-z0-9]*]] <col:37> 'int' 1
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_23:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_24:0x[a-z0-9]*]] <col:22, line:49:1> line:10:22 also_after[implementation={extension(disable_implicit_base)}] 'int (double)'
-// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_25:0x[a-z0-9]*]] <line:47:16, col:23> col:23 d 'double'
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_24:0x[a-z0-9]*]] <line:47:1, line:49:1> line:47:1 also_after[implementation={extension(disable_implicit_base)}] 'int (double)'
+// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_25:0x[a-z0-9]*]] <col:16, col:23> col:23 d 'double'
 // C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_26:0x[a-z0-9]*]] <col:26, line:49:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_27:0x[a-z0-9]*]] <line:48:3, line:18:37>
 // C_FLOAT-NEXT: | |   `-IntegerLiteral [[ADDR_28:0x[a-z0-9]*]] <col:37> 'int' 0
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_29:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_30:0x[a-z0-9]*]] <col:22, line:53:1> line:10:22 also_after[implementation={extension(disable_implicit_base)}] 'int (long)'
-// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_31:0x[a-z0-9]*]] <line:51:16, col:21> col:21 l 'long'
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_30:0x[a-z0-9]*]] <line:51:1, line:53:1> line:51:1 also_after[implementation={extension(disable_implicit_base)}] 'int (long)'
+// C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_31:0x[a-z0-9]*]] <col:16, col:21> col:21 l 'long'
 // C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_32:0x[a-z0-9]*]] <col:24, line:53:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_33:0x[a-z0-9]*]] <line:52:3, line:18:37>
 // C_FLOAT-NEXT: | |   `-IntegerLiteral [[ADDR_34:0x[a-z0-9]*]] <col:37> 'int' 0
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_35:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_36:0x[a-z0-9]*]] <col:22, line:59:1> line:57:11 used also_after 'float (double)'
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_36:0x[a-z0-9]*]] <line:14:19, line:59:1> line:57:11 used also_after 'float (double)'
 // C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_37:0x[a-z0-9]*]] <col:22, col:29> col:29 d 'double'
 // C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_38:0x[a-z0-9]*]] <col:32, line:59:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_39:0x[a-z0-9]*]] <line:58:3, line:17:34>
 // C_FLOAT-NEXT: | |   `-ImplicitCastExpr [[ADDR_40:0x[a-z0-9]*]] <col:34> 'float' <IntegralToFloating>
 // C_FLOAT-NEXT: | |     `-IntegerLiteral [[ADDR_41:0x[a-z0-9]*]] <col:34> 'int' 1
 // C_FLOAT-NEXT: | `-OverloadableAttr [[ADDR_42:0x[a-z0-9]*]] <line:10:37>
-// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_43:0x[a-z0-9]*]] <col:22, line:63:1> line:61:11 used also_after 'float (long)'
+// C_FLOAT-NEXT: |-FunctionDecl [[ADDR_43:0x[a-z0-9]*]] <line:14:19, line:63:1> line:61:11 used also_after 'float (long)'
 // C_FLOAT-NEXT: | |-ParmVarDecl [[ADDR_44:0x[a-z0-9]*]] <col:22, col:27> col:27 l 'long'
 // C_FLOAT-NEXT: | |-CompoundStmt [[ADDR_45:0x[a-z0-9]*]] <col:30, line:63:1>
 // C_FLOAT-NEXT: | | `-ReturnStmt [[ADDR_46:0x[a-z0-9]*]] <line:62:3, line:17:34>
@@ -228,45 +228,45 @@
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_3:0x[a-z0-9]*]] <col:34> 'int' 1
 // C_INT-NEXT: | |-OverloadableAttr [[ADDR_4:0x[a-z0-9]*]] <line:10:37>
 // C_INT-NEXT: | `-OMPDeclareVariantAttr [[ADDR_5:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={extension(disable_implicit_base)}
-// C_INT-NEXT: |   `-DeclRefExpr [[ADDR_6:0x[a-z0-9]*]] <col:22> 'int ({{.*}})' Function [[ADDR_7:0x[a-z0-9]*]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int ({{.*}})'
-// C_INT-NEXT: |-FunctionDecl [[ADDR_8:0x[a-z0-9]*]] <col:22, line:34:1> line:32:11 used also_before 'int (int)'
+// C_INT-NEXT: |   `-DeclRefExpr [[ADDR_6:0x[a-z0-9]*]] <line:38:1> 'int ({{.*}})' Function [[ADDR_7:0x[a-z0-9]*]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int ({{.*}})'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_8:0x[a-z0-9]*]] <line:20:19, line:34:1> line:32:11 used also_before 'int (int)'
 // C_INT-NEXT: | |-ParmVarDecl [[ADDR_9:0x[a-z0-9]*]] <col:23, col:27> col:27 i 'int'
 // C_INT-NEXT: | |-CompoundStmt [[ADDR_10:0x[a-z0-9]*]] <col:30, line:34:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_11:0x[a-z0-9]*]] <line:33:3, line:21:34>
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_12:0x[a-z0-9]*]] <col:34> 'int' 1
 // C_INT-NEXT: | |-OverloadableAttr [[ADDR_13:0x[a-z0-9]*]] <line:10:37>
 // C_INT-NEXT: | `-OMPDeclareVariantAttr [[ADDR_14:0x[a-z0-9]*]] <<invalid sloc>> Implicit implementation={extension(disable_implicit_base)}
-// C_INT-NEXT: |   `-DeclRefExpr [[ADDR_15:0x[a-z0-9]*]] <col:22> 'int (int)' Function [[ADDR_16:0x[a-z0-9]*]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int (int)'
-// C_INT-NEXT: |-FunctionDecl [[ADDR_7]] <col:22, line:40:1> line:10:22 also_before[implementation={extension(disable_implicit_base)}] 'int ({{.*}})'
-// C_INT-NEXT: | |-CompoundStmt [[ADDR_17:0x[a-z0-9]*]] <line:38:23, line:40:1>
+// C_INT-NEXT: |   `-DeclRefExpr [[ADDR_15:0x[a-z0-9]*]] <line:42:1> 'int (int)' Function [[ADDR_16:0x[a-z0-9]*]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int (int)'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_7]] <line:38:1, line:40:1> line:38:1 also_before[implementation={extension(disable_implicit_base)}] 'int ({{.*}})'
+// C_INT-NEXT: | |-CompoundStmt [[ADDR_17:0x[a-z0-9]*]] <col:23, line:40:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_18:0x[a-z0-9]*]] <line:39:3, line:22:37>
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_19:0x[a-z0-9]*]] <col:37> 'int' 0
 // C_INT-NEXT: | `-OverloadableAttr [[ADDR_20:0x[a-z0-9]*]] <line:10:37>
-// C_INT-NEXT: |-FunctionDecl [[ADDR_16]] <col:22, line:44:1> line:10:22 also_before[implementation={extension(disable_implicit_base)}] 'int (int)'
-// C_INT-NEXT: | |-ParmVarDecl [[ADDR_21:0x[a-z0-9]*]] <line:42:17, col:21> col:21 i 'int'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_16]] <line:42:1, line:44:1> line:42:1 also_before[implementation={extension(disable_implicit_base)}] 'int (int)'
+// C_INT-NEXT: | |-ParmVarDecl [[ADDR_21:0x[a-z0-9]*]] <col:17, col:21> col:21 i 'int'
 // C_INT-NEXT: | |-CompoundStmt [[ADDR_22:0x[a-z0-9]*]] <col:24, line:44:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_23:0x[a-z0-9]*]] <line:43:3, line:22:37>
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_24:0x[a-z0-9]*]] <col:37> 'int' 0
 // C_INT-NEXT: | `-OverloadableAttr [[ADDR_25:0x[a-z0-9]*]] <line:10:37>
-// C_INT-NEXT: |-FunctionDecl [[ADDR_26:0x[a-z0-9]*]] <col:22, line:49:1> line:10:22 also_after[implementation={extension(disable_implicit_base)}] 'int (double)'
-// C_INT-NEXT: | |-ParmVarDecl [[ADDR_27:0x[a-z0-9]*]] <line:47:16, col:23> col:23 d 'double'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_26:0x[a-z0-9]*]] <line:47:1, line:49:1> line:47:1 also_after[implementation={extension(disable_implicit_base)}] 'int (double)'
+// C_INT-NEXT: | |-ParmVarDecl [[ADDR_27:0x[a-z0-9]*]] <col:16, col:23> col:23 d 'double'
 // C_INT-NEXT: | |-CompoundStmt [[ADDR_28:0x[a-z0-9]*]] <col:26, line:49:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_29:0x[a-z0-9]*]] <line:48:3, line:24:37>
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_30:0x[a-z0-9]*]] <col:37> 'int' 1
 // C_INT-NEXT: | `-OverloadableAttr [[ADDR_31:0x[a-z0-9]*]] <line:10:37>
-// C_INT-NEXT: |-FunctionDecl [[ADDR_32:0x[a-z0-9]*]] <col:22, line:53:1> line:10:22 also_after[implementation={extension(disable_implicit_base)}] 'int (long)'
-// C_INT-NEXT: | |-ParmVarDecl [[ADDR_33:0x[a-z0-9]*]] <line:51:16, col:21> col:21 l 'long'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_32:0x[a-z0-9]*]] <line:51:1, line:53:1> line:51:1 also_after[implementation={extension(disable_implicit_base)}] 'int (long)'
+// C_INT-NEXT: | |-ParmVarDecl [[ADDR_33:0x[a-z0-9]*]] <col:16, col:21> col:21 l 'long'
 // C_INT-NEXT: | |-CompoundStmt [[ADDR_34:0x[a-z0-9]*]] <col:24, line:53:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_35:0x[a-z0-9]*]] <line:52:3, line:24:37>
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_36:0x[a-z0-9]*]] <col:37> 'int' 1
 // C_INT-NEXT: | `-OverloadableAttr [[ADDR_37:0x[a-z0-9]*]] <line:10:37>
-// C_INT-NEXT: |-FunctionDecl [[ADDR_38:0x[a-z0-9]*]] <col:22, line:59:1> line:57:11 used also_after 'int (double)'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_38:0x[a-z0-9]*]] <line:20:19, line:59:1> line:57:11 used also_after 'int (double)'
 // C_INT-NEXT: | |-ParmVarDecl [[ADDR_39:0x[a-z0-9]*]] <col:22, col:29> col:29 d 'double'
 // C_INT-NEXT: | |-CompoundStmt [[ADDR_40:0x[a-z0-9]*]] <col:32, line:59:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_41:0x[a-z0-9]*]] <line:58:3, line:23:34>
 // C_INT-NEXT: | |   `-IntegerLiteral [[ADDR_42:0x[a-z0-9]*]] <col:34> 'int' 0
 // C_INT-NEXT: | `-OverloadableAttr [[ADDR_43:0x[a-z0-9]*]] <line:10:37>
-// C_INT-NEXT: |-FunctionDecl [[ADDR_44:0x[a-z0-9]*]] <col:22, line:63:1> line:61:11 used also_after 'int (long)'
+// C_INT-NEXT: |-FunctionDecl [[ADDR_44:0x[a-z0-9]*]] <line:20:19, line:63:1> line:61:11 used also_after 'int (long)'
 // C_INT-NEXT: | |-ParmVarDecl [[ADDR_45:0x[a-z0-9]*]] <col:22, col:27> col:27 l 'long'
 // C_INT-NEXT: | |-CompoundStmt [[ADDR_46:0x[a-z0-9]*]] <col:30, line:63:1>
 // C_INT-NEXT: | | `-ReturnStmt [[ADDR_47:0x[a-z0-9]*]] <line:62:3, line:23:34>
@@ -283,17 +283,17 @@
 // C_INT-NEXT:         | | | | |-CallExpr [[ADDR_58:0x[a-z0-9]*]] <col:10, col:22> 'int'
 // C_INT-NEXT:         | | | | | `-ImplicitCastExpr [[ADDR_59:0x[a-z0-9]*]] <col:10> 'int (*)({{.*}})' <FunctionToPointerDecay>
 // C_INT-NEXT:         | | | | |   `-DeclRefExpr [[ADDR_60:0x[a-z0-9]*]] <col:10> 'int ({{.*}})' {{.*}}Function [[ADDR_0]] 'also_before' 'int ({{.*}})'
-// C_INT-NEXT:         | | | | `-CallExpr [[ADDR_61:0x[a-z0-9]*]] <line:10:22, line:67:22> 'int'
-// C_INT-NEXT:         | | | |   `-ImplicitCastExpr [[ADDR_62:0x[a-z0-9]*]] <line:10:22> 'int (*)({{.*}})' <FunctionToPointerDecay>
-// C_INT-NEXT:         | | | |     `-DeclRefExpr [[ADDR_6]] <col:22> 'int ({{.*}})' Function [[ADDR_7]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int ({{.*}})'
+// C_INT-NEXT:         | | | | `-CallExpr [[ADDR_61:0x[a-z0-9]*]] <line:38:1, line:67:22> 'int'
+// C_INT-NEXT:         | | | |   `-ImplicitCastExpr [[ADDR_62:0x[a-z0-9]*]] <line:38:1> 'int (*)({{.*}})' <FunctionToPointerDecay>
+// C_INT-NEXT:         | | | |     `-DeclRefExpr [[ADDR_6]] <col:1> 'int ({{.*}})' Function [[ADDR_7]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int ({{.*}})'
 // C_INT-NEXT:         | | | `-PseudoObjectExpr [[ADDR_63:0x[a-z0-9]*]] <line:67:26, col:39> 'int'
 // C_INT-NEXT:         | | |   |-CallExpr [[ADDR_64:0x[a-z0-9]*]] <col:26, col:39> 'int'
 // C_INT-NEXT:         | | |   | |-ImplicitCastExpr [[ADDR_65:0x[a-z0-9]*]] <col:26> 'int (*)(int)' <FunctionToPointerDecay>
 // C_INT-NEXT:         | | |   | | `-DeclRefExpr [[ADDR_66:0x[a-z0-9]*]] <col:26> 'int (int)' {{.*}}Function [[ADDR_8]] 'also_before' 'int (int)'
 // C_INT-NEXT:         | | |   | `-IntegerLiteral [[ADDR_67:0x[a-z0-9]*]] <col:38> 'int' 1
-// C_INT-NEXT:         | | |   `-CallExpr [[ADDR_68:0x[a-z0-9]*]] <line:10:22, line:67:39> 'int'
-// C_INT-NEXT:         | | |     |-ImplicitCastExpr [[ADDR_69:0x[a-z0-9]*]] <line:10:22> 'int (*)(int)' <FunctionToPointerDecay>
-// C_INT-NEXT:         | | |     | `-DeclRefExpr [[ADDR_15]] <col:22> 'int (int)' Function [[ADDR_16]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int (int)'
+// C_INT-NEXT:         | | |   `-CallExpr [[ADDR_68:0x[a-z0-9]*]] <line:42:1, line:67:39> 'int'
+// C_INT-NEXT:         | | |     |-ImplicitCastExpr [[ADDR_69:0x[a-z0-9]*]] <line:42:1> 'int (*)(int)' <FunctionToPointerDecay>
+// C_INT-NEXT:         | | |     | `-DeclRefExpr [[ADDR_15]] <col:1> 'int (int)' Function [[ADDR_16]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int (int)'
 // C_INT-NEXT:         | | |     `-IntegerLiteral [[ADDR_67]] <line:67:38> 'int' 1
 // C_INT-NEXT:         | | `-PseudoObjectExpr [[ADDR_70:0x[a-z0-9]*]] <col:43, col:59> 'int'
 // C_INT-NEXT:         | |   |-CallExpr [[ADDR_71:0x[a-z0-9]*]] <col:43, col:59> 'int'
@@ -301,9 +301,9 @@
 // C_INT-NEXT:         | |   | | `-DeclRefExpr [[ADDR_73:0x[a-z0-9]*]] <col:43> 'int (int)' {{.*}}Function [[ADDR_8]] 'also_before' 'int (int)'
 // C_INT-NEXT:         | |   | `-ImplicitCastExpr [[ADDR_74:0x[a-z0-9]*]] <col:55> 'int' <FloatingToIntegral>
 // C_INT-NEXT:         | |   |   `-FloatingLiteral [[ADDR_75:0x[a-z0-9]*]] <col:55> 'float' 2.000000e+00
-// C_INT-NEXT:         | |   `-CallExpr [[ADDR_76:0x[a-z0-9]*]] <line:10:22, line:67:59> 'int'
-// C_INT-NEXT:         | |     |-ImplicitCastExpr [[ADDR_77:0x[a-z0-9]*]] <line:10:22> 'int (*)(int)' <FunctionToPointerDecay>
-// C_INT-NEXT:         | |     | `-DeclRefExpr [[ADDR_15]] <col:22> 'int (int)' Function [[ADDR_16]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int (int)'
+// C_INT-NEXT:         | |   `-CallExpr [[ADDR_76:0x[a-z0-9]*]] <line:42:1, line:67:59> 'int'
+// C_INT-NEXT:         | |     |-ImplicitCastExpr [[ADDR_77:0x[a-z0-9]*]] <line:42:1> 'int (*)(int)' <FunctionToPointerDecay>
+// C_INT-NEXT:         | |     | `-DeclRefExpr [[ADDR_15]] <col:1> 'int (int)' Function [[ADDR_16]] 'also_before[implementation={extension(disable_implicit_base)}]' 'int (int)'
 // C_INT-NEXT:         | |     `-ImplicitCastExpr [[ADDR_78:0x[a-z0-9]*]] <line:67:55> 'int' <FloatingToIntegral>
 // C_INT-NEXT:         | |       `-FloatingLiteral [[ADDR_75]] <col:55> 'float' 2.000000e+00
 // C_INT-NEXT:         | `-CallExpr [[ADDR_79:0x[a-z0-9]*]] <col:63, col:77> 'int'
Index: clang/lib/Parse/Parser.cpp
===================================================================
--- clang/lib/Parse/Parser.cpp
+++ clang/lib/Parse/Parser.cpp
@@ -732,9 +732,12 @@
   }
 
   ParsedAttributes attrs(AttrFactory);
-  MaybeParseCXX11Attributes(attrs);
+  ParsedAttributes DeclSpecAttrs(AttrFactory);
+  while (MaybeParseCXX11Attributes(attrs) ||
+         MaybeParseGNUAttributes(DeclSpecAttrs))
+    ;
 
-  Result = ParseExternalDeclaration(attrs);
+  Result = ParseExternalDeclaration(attrs, DeclSpecAttrs);
   // An empty Result might mean a line with ';' or some parsing error, ignore
   // it.
   if (Result) {
@@ -777,8 +780,10 @@
 ///
 /// [Modules-TS] module-import-declaration
 ///
-Parser::DeclGroupPtrTy Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
-                                                        ParsingDeclSpec *DS) {
+Parser::DeclGroupPtrTy
+Parser::ParseExternalDeclaration(ParsedAttributes &Attrs,
+                                 ParsedAttributes &DeclSpecAttrs,
+                                 ParsingDeclSpec *DS) {
   DestroyTemplateIdAnnotationsRAIIObj CleanupRAII(*this);
   ParenBraceBracketBalancer BalancerRAIIObj(*this);
 
@@ -866,7 +871,7 @@
     // __extension__ silences extension warnings in the subexpression.
     ExtensionRAIIObject O(Diags);  // Use RAII to do this.
     ConsumeToken();
-    return ParseExternalDeclaration(Attrs);
+    return ParseExternalDeclaration(Attrs, DeclSpecAttrs);
   }
   case tok::kw_asm: {
     ProhibitAttributes(Attrs);
@@ -894,7 +899,7 @@
     break;
   }
   case tok::at:
-    return ParseObjCAtDirectives(Attrs);
+    return ParseObjCAtDirectives(Attrs, DeclSpecAttrs);
   case tok::minus:
   case tok::plus:
     if (!getLangOpts().ObjC) {
@@ -942,18 +947,16 @@
     // A function definition cannot start with any of these keywords.
     {
       SourceLocation DeclEnd;
-      ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
       return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
-                              EmptyDeclSpecAttrs);
+                              DeclSpecAttrs);
     }
 
   case tok::kw_cbuffer:
   case tok::kw_tbuffer:
     if (getLangOpts().HLSL) {
       SourceLocation DeclEnd;
-      ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
       return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
-                              EmptyDeclSpecAttrs);
+                              DeclSpecAttrs);
     }
     goto dont_know;
 
@@ -964,9 +967,8 @@
       Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
         << 0;
       SourceLocation DeclEnd;
-      ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
       return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
-                              EmptyDeclSpecAttrs);
+                              DeclSpecAttrs);
     }
     goto dont_know;
 
@@ -977,9 +979,8 @@
       // Inline namespaces. Allowed as an extension even in C++03.
       if (NextKind == tok::kw_namespace) {
         SourceLocation DeclEnd;
-        ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
         return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
-                                EmptyDeclSpecAttrs);
+                                DeclSpecAttrs);
       }
 
       // Parse (then ignore) 'inline' prior to a template instantiation. This is
@@ -988,9 +989,8 @@
         Diag(ConsumeToken(), diag::warn_static_inline_explicit_inst_ignored)
           << 1;
         SourceLocation DeclEnd;
-        ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
         return ParseDeclaration(DeclaratorContext::File, DeclEnd, Attrs,
-                                EmptyDeclSpecAttrs);
+                                DeclSpecAttrs);
       }
     }
     goto dont_know;
@@ -1026,7 +1026,7 @@
       return nullptr;
     }
     // We can't tell whether this is a function-definition or declaration yet.
-    return ParseDeclarationOrFunctionDefinition(Attrs, DS);
+    return ParseDeclarationOrFunctionDefinition(Attrs, DeclSpecAttrs, DS);
   }
 
   // This routine returns a DeclGroup, if the thing we parsed only contains a
@@ -1091,7 +1091,10 @@
 /// [OMP]   allocate-directive                         [TODO]
 ///
 Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal(
-    ParsedAttributes &Attrs, ParsingDeclSpec &DS, AccessSpecifier AS) {
+    ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs,
+    ParsingDeclSpec &DS, AccessSpecifier AS) {
+  DS.takeAttributesFrom(DeclSpecAttrs);
+
   MaybeParseMicrosoftAttributes(DS.getAttributes());
   // Parse the common declaration-specifiers piece.
   ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS,
@@ -1190,9 +1193,10 @@
 }
 
 Parser::DeclGroupPtrTy Parser::ParseDeclarationOrFunctionDefinition(
-    ParsedAttributes &Attrs, ParsingDeclSpec *DS, AccessSpecifier AS) {
+    ParsedAttributes &Attrs, ParsedAttributes &DeclSpecAttrs,
+    ParsingDeclSpec *DS, AccessSpecifier AS) {
   if (DS) {
-    return ParseDeclOrFunctionDefInternal(Attrs, *DS, AS);
+    return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, *DS, AS);
   } else {
     ParsingDeclSpec PDS(*this);
     // Must temporarily exit the objective-c container scope for
@@ -1200,7 +1204,7 @@
     // afterwards.
     ObjCDeclContextSwitch ObjCDC(*this);
 
-    return ParseDeclOrFunctionDefInternal(Attrs, PDS, AS);
+    return ParseDeclOrFunctionDefInternal(Attrs, DeclSpecAttrs, PDS, AS);
   }
 }
 
@@ -2342,7 +2346,8 @@
   while (Tok.isNot(tok::r_brace) && !isEofOrEom()) {
     ParsedAttributes Attrs(AttrFactory);
     MaybeParseCXX11Attributes(Attrs);
-    DeclGroupPtrTy Result = ParseExternalDeclaration(Attrs);
+    ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+    DeclGroupPtrTy Result = ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs);
     if (Result && !getCurScope()->getParent())
       Actions.getASTConsumer().HandleTopLevelDecl(Result.get());
   }
Index: clang/lib/Parse/ParseOpenMP.cpp
===================================================================
--- clang/lib/Parse/ParseOpenMP.cpp
+++ clang/lib/Parse/ParseOpenMP.cpp
@@ -1994,6 +1994,8 @@
   ParsingOpenMPDirectiveRAII DirScope(*this);
   ParenBraceBracketBalancer BalancerRAIIObj(*this);
 
+  ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+
   SourceLocation Loc;
   OpenMPDirectiveKind DKind;
   if (Delayed) {
@@ -2247,7 +2249,7 @@
         assert(TagType == DeclSpec::TST_unspecified);
         MaybeParseCXX11Attributes(Attrs);
         ParsingDeclSpec PDS(*this);
-        Ptr = ParseExternalDeclaration(Attrs, &PDS);
+        Ptr = ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs, &PDS);
       } else {
         Ptr =
             ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag);
Index: clang/lib/Parse/ParseObjc.cpp
===================================================================
--- clang/lib/Parse/ParseObjc.cpp
+++ clang/lib/Parse/ParseObjc.cpp
@@ -45,7 +45,11 @@
 /// [OBJC]  objc-protocol-definition
 /// [OBJC]  objc-method-definition
 /// [OBJC]  '@' 'end'
-Parser::DeclGroupPtrTy Parser::ParseObjCAtDirectives(ParsedAttributes &Attrs) {
+Parser::DeclGroupPtrTy
+Parser::ParseObjCAtDirectives(ParsedAttributes &Attrs,
+                              ParsedAttributes &DeclSpecAttrs) {
+  Attrs.takeAllFrom(DeclSpecAttrs);
+
   SourceLocation AtLoc = ConsumeToken(); // the "@"
 
   if (Tok.is(tok::code_completion)) {
@@ -54,6 +58,17 @@
     return nullptr;
   }
 
+  switch (Tok.getObjCKeywordID()) {
+  case tok::objc_interface:
+  case tok::objc_protocol:
+  case tok::objc_implementation:
+    break;
+  default:
+    for (const auto &PA : Attrs)
+      if (PA.isGNUAttribute())
+        Diag(PA.getLoc(), diag::err_objc_unexpected_attr);
+  }
+
   Decl *SingleDecl = nullptr;
   switch (Tok.getObjCKeywordID()) {
   case tok::objc_class:
@@ -651,6 +666,7 @@
         break;
 
       ParsedAttributes EmptyAttrs(AttrFactory);
+      ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
 
       // Since we call ParseDeclarationOrFunctionDefinition() instead of
       // ParseExternalDeclaration() below (so that this doesn't parse nested
@@ -664,7 +680,7 @@
       }
 
       allTUVariables.push_back(
-          ParseDeclarationOrFunctionDefinition(EmptyAttrs));
+          ParseDeclarationOrFunctionDefinition(EmptyAttrs, EmptyDeclSpecAttrs));
       continue;
     }
 
@@ -2225,7 +2241,8 @@
     while (!ObjCImplParsing.isFinished() && !isEofOrEom()) {
       ParsedAttributes attrs(AttrFactory);
       MaybeParseCXX11Attributes(attrs);
-      if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs)) {
+      ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+      if (DeclGroupPtrTy DGP = ParseExternalDeclaration(attrs, EmptyDeclSpecAttrs)) {
         DeclGroupRef DG = DGP.get();
         DeclsInGroup.append(DG.begin(), DG.end());
       }
Index: clang/lib/Parse/ParseHLSL.cpp
===================================================================
--- clang/lib/Parse/ParseHLSL.cpp
+++ clang/lib/Parse/ParseHLSL.cpp
@@ -78,8 +78,9 @@
   while (Tok.isNot(tok::r_brace) && Tok.isNot(tok::eof)) {
     // FIXME: support attribute on constants inside cbuffer/tbuffer.
     ParsedAttributes Attrs(AttrFactory);
+    ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
 
-    DeclGroupPtrTy Result = ParseExternalDeclaration(Attrs);
+    DeclGroupPtrTy Result = ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs);
     if (!validateDeclsInsideHLSLBuffer(Result, IdentifierLoc, IsCBuffer,
                                        *this)) {
       T.skipToEnd();
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -256,7 +256,8 @@
            Tok.isNot(tok::eof)) {
       ParsedAttributes Attrs(AttrFactory);
       MaybeParseCXX11Attributes(Attrs);
-      ParseExternalDeclaration(Attrs);
+      ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+      ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs);
     }
 
     // The caller is what called check -- we are simply calling
@@ -359,6 +360,7 @@
 
   ParsedAttributes DeclAttrs(AttrFactory);
   MaybeParseCXX11Attributes(DeclAttrs);
+  ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
 
   if (Tok.isNot(tok::l_brace)) {
     // Reset the source range in DS, as the leading "extern"
@@ -367,7 +369,7 @@
     DS.SetRangeEnd(SourceLocation());
     // ... but anyway remember that such an "extern" was seen.
     DS.setExternInLinkageSpec(true);
-    ParseExternalDeclaration(DeclAttrs, &DS);
+    ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs, &DS);
     return LinkageSpec ? Actions.ActOnFinishLinkageSpecification(
                              getCurScope(), LinkageSpec, SourceLocation())
                        : nullptr;
@@ -409,7 +411,7 @@
     default:
       ParsedAttributes Attrs(AttrFactory);
       MaybeParseCXX11Attributes(Attrs);
-      ParseExternalDeclaration(Attrs);
+      ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs);
       continue;
     }
 
@@ -441,7 +443,8 @@
     // FIXME: Factor out a ParseExternalDeclarationWithAttrs.
     ParsedAttributes Attrs(AttrFactory);
     MaybeParseCXX11Attributes(Attrs);
-    ParseExternalDeclaration(Attrs);
+    ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+    ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs);
     return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl,
                                          SourceLocation());
   }
@@ -460,7 +463,8 @@
          Tok.isNot(tok::eof)) {
     ParsedAttributes Attrs(AttrFactory);
     MaybeParseCXX11Attributes(Attrs);
-    ParseExternalDeclaration(Attrs);
+    ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
+    ParseExternalDeclaration(Attrs, EmptyDeclSpecAttrs);
   }
 
   T.consumeClose();
Index: clang/include/clang/Parse/Parser.h
===================================================================
--- clang/include/clang/Parse/Parser.h
+++ clang/include/clang/Parse/Parser.h
@@ -1603,14 +1603,17 @@
   //===--------------------------------------------------------------------===//
   // C99 6.9: External Definitions.
   DeclGroupPtrTy ParseExternalDeclaration(ParsedAttributes &Attrs,
+                                          ParsedAttributes &DeclSpecAttrs,
                                           ParsingDeclSpec *DS = nullptr);
   bool isDeclarationAfterDeclarator();
   bool isStartOfFunctionDefinition(const ParsingDeclarator &Declarator);
   DeclGroupPtrTy
   ParseDeclarationOrFunctionDefinition(ParsedAttributes &Attrs,
+                                       ParsedAttributes &DeclSpecAttrs,
                                        ParsingDeclSpec *DS = nullptr,
                                        AccessSpecifier AS = AS_none);
   DeclGroupPtrTy ParseDeclOrFunctionDefInternal(ParsedAttributes &Attrs,
+                                                ParsedAttributes &DeclSpecAttrs,
                                                 ParsingDeclSpec &DS,
                                                 AccessSpecifier AS);
 
@@ -1625,7 +1628,8 @@
 
   // Objective-C External Declarations
   void MaybeSkipAttributes(tok::ObjCKeywordKind Kind);
-  DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &Attrs);
+  DeclGroupPtrTy ParseObjCAtDirectives(ParsedAttributes &Attrs,
+                                       ParsedAttributes &DeclSpecAttrs);
   DeclGroupPtrTy ParseObjCAtClassDeclaration(SourceLocation atLoc);
   Decl *ParseObjCAtInterfaceDeclaration(SourceLocation AtLoc,
                                         ParsedAttributes &prefixAttrs);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to