From eba9195e0075e8b03bce8a31d2d09d5ec50f4e71 Mon Sep 17 00:00:00 2001
From: Aaron Ballman <aaron@aaronballman.com>
Date: Tue, 13 May 2014 16:12:14 +0000
Subject: [PATCH] Fix the AST printer for attributed statements so that it does
 not print duplicate attribute introducers. Eg) [[clang::fallthrough]] instead
 of  [[[[clang::fallthrough]]]]

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208706 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/AST/StmtPrinter.cpp    | 15 ++-------------
 test/PCH/stmt-attrs.cpp    |  6 +++---
 test/SemaCXX/ast-print.cpp | 12 ++++++++++++
 3 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index f3ecff9ad3c..e5f24dc5d5e 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -168,19 +168,8 @@ void StmtPrinter::VisitLabelStmt(LabelStmt *Node) {
 }
 
 void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
-  OS << "[[";
-  bool first = true;
-  for (ArrayRef<const Attr*>::iterator it = Node->getAttrs().begin(),
-                                       end = Node->getAttrs().end();
-                                       it != end; ++it) {
-    if (!first) {
-      OS << ", ";
-      first = false;
-    }
-    // TODO: check this
-    (*it)->printPretty(OS, Policy);
-  }
-  OS << "]] ";
+  for (const auto *Attr : Node->getAttrs())
+    Attr->printPretty(OS, Policy);
   PrintStmt(Node->getSubStmt(), 0);
 }
 
diff --git a/test/PCH/stmt-attrs.cpp b/test/PCH/stmt-attrs.cpp
index 59134500031..3d7c7a27a7e 100644
--- a/test/PCH/stmt-attrs.cpp
+++ b/test/PCH/stmt-attrs.cpp
@@ -1,6 +1,5 @@
 // RUN: %clang_cc1 -std=c++11 -emit-pch -o %t.a %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -include-pch %t.a %s
-// expected-no-diagnostics
+// RUN: %clang_cc1 -std=c++11 -include-pch %t.a %s -ast-print -o - | FileCheck %s
 
 #ifndef HEADER
 #define HEADER
@@ -9,7 +8,8 @@ inline void test(int i) {
   switch (i) {
     case 1:
       // Notice that the NullStmt has two attributes.
-      [[clang::fallthrough]][[clang::fallthrough]];
+      // CHECK: {{\[\[clang::fallthrough\]\] \[\[clang::fallthrough\]\]}}
+      [[clang::fallthrough]] [[clang::fallthrough]];
     case 2:
       break;
   }
diff --git a/test/SemaCXX/ast-print.cpp b/test/SemaCXX/ast-print.cpp
index 3d98fd8ef3a..4851571283f 100644
--- a/test/SemaCXX/ast-print.cpp
+++ b/test/SemaCXX/ast-print.cpp
@@ -196,3 +196,15 @@ void foo() {
     return;
 }
 };
+
+namespace {
+void test(int i) {
+  switch (i) {
+    case 1:
+      // CHECK: {{\[\[clang::fallthrough\]\]}}
+      [[clang::fallthrough]];
+    case 2:
+      break;
+  }
+}
+}
-- 
GitLab