]> granicus.if.org Git - clang/commitdiff
Don't constant-fold when pretty-printing alignment attribute. This fixes a
authorRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 16 Aug 2012 02:43:29 +0000 (02:43 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Thu, 16 Aug 2012 02:43:29 +0000 (02:43 +0000)
potential crasher -- Context is sometimes a null reference (!!) here.

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

include/clang/AST/Attr.h
lib/AST/DeclPrinter.cpp
lib/AST/StmtPrinter.cpp
test/Tooling/clang-check-ast-dump.cpp
utils/TableGen/ClangAttrEmitter.cpp

index 27b44d4bd97b05d8debdd93e1b92215bba055e55..b17bd48b7d03c0c8af2bd34c0f04087680701c9f 100644 (file)
@@ -105,7 +105,8 @@ public:
   virtual bool isLateParsed() const { return false; }
 
   // Pretty print this attribute.
-  virtual void printPretty(llvm::raw_ostream &OS, ASTContext &C) const = 0;
+  virtual void printPretty(llvm::raw_ostream &OS,
+                           const PrintingPolicy &Policy) const = 0;
 
   // Implement isa/cast/dyncast/etc.
   static bool classof(const Attr *) { return true; }
index 8a53900d5d0d0b3563fe8f394f8660d4764a8bef..9194eb43b368d7759cfbe6f591ebbebf99dcfd15 100644 (file)
@@ -195,8 +195,8 @@ void DeclPrinter::prettyPrintAttributes(Decl *D) {
   if (D->hasAttrs()) {
     AttrVec &Attrs = D->getAttrs();
     for (AttrVec::const_iterator i=Attrs.begin(), e=Attrs.end(); i!=e; ++i) {
-        Attr *A = *i;
-        A->printPretty(Out, Context);
+      Attr *A = *i;
+      A->printPretty(Out, Policy);
     }
   }
 }
index 85d5a79569a60944eff597582354a9c461c5a881..d5ae74d59e6e0fe15b853d2bb0875cbea0d910d7 100644 (file)
@@ -181,7 +181,7 @@ void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) {
       first = false;
     }
     // TODO: check this
-    (*it)->printPretty(OS, Context);
+    (*it)->printPretty(OS, Policy);
   }
   OS << "]] ";
   PrintStmt(Node->getSubStmt(), 0);
index 86533af3e11db55055b5f51bf94abb235859a6fd..53a4c2b418a670718071ecbb1d5b637a31583c00 100644 (file)
 // CHECK-LIST-NEXT: test_namespace::TheClass
 // CHECK-LIST-NEXT: test_namespace::TheClass::theMethod
 // CHECK-LIST-NEXT: x
+//
+// RUN: clang-check -ast-dump -ast-dump-filter test_namespace::TheClass::n "%s" -- 2>&1 | FileCheck -check-prefix CHECK-ATTR %s
+// CHECK-ATTR: test_namespace
+// CHECK-ATTR-NEXT: int n __attribute__((aligned(1 + 1
 
 namespace test_namespace {
 
@@ -30,6 +34,7 @@ public:
   int theMethod(int x) {
     return x + x;
   }
+  int n __attribute__((aligned(1+1)));
 };
 
 }
index 1b1a478ceb134ca509d34cb450b462d92c6fc9c8..ef1ad3e1d2d915cd135ceedee6e4091880f92772 100644 (file)
@@ -349,7 +349,9 @@ namespace {
          << "Type(), Record);\n";
     }
     void writeValue(raw_ostream &OS) const {
-      OS << "\" << get" << getUpperName() << "(Ctx) << \"";
+      OS << "\";\n"
+         << "  " << getLowerName() << "Expr->printPretty(OS, 0, Policy);\n"
+         << "  OS << \"";
     }
   };
 
@@ -728,7 +730,8 @@ void EmitClangAttrClass(RecordKeeper &Records, raw_ostream &OS) {
     OS << "  }\n\n";
 
     OS << "  virtual " << R.getName() << "Attr *clone (ASTContext &C) const;\n";
-    OS << "  virtual void printPretty(llvm::raw_ostream &OS, ASTContext &Ctx) const;\n";
+    OS << "  virtual void printPretty(llvm::raw_ostream &OS,"
+       << "                           const PrintingPolicy &Policy) const;\n";
 
     for (ai = Args.begin(); ai != ae; ++ai) {
       (*ai)->writeAccessors(OS);
@@ -786,7 +789,7 @@ void EmitClangAttrImpl(RecordKeeper &Records, raw_ostream &OS) {
     OS << ");\n}\n\n";
 
     OS << "void " << R.getName() << "Attr::printPretty("
-       << "llvm::raw_ostream &OS, ASTContext &Ctx) const {\n";
+       << "llvm::raw_ostream &OS, const PrintingPolicy &Policy) const {\n";
     if (Spellings.begin() != Spellings.end()) {
       std::string Spelling = (*Spellings.begin())->getValueAsString("Name");
       OS << "  OS << \" __attribute__((" << Spelling;