r214513 - The GNU-style aligned attribute has an optional expression, but the generated pretty printing logic was unaware of this. Fixed the pretty printing logic, and added a test to ensure it no longer asserts.

Aaron Ballman aaron at aaronballman.com
Fri Aug 1 06:49:01 PDT 2014


Author: aaronballman
Date: Fri Aug  1 08:49:00 2014
New Revision: 214513

URL: http://llvm.org/viewvc/llvm-project?rev=214513&view=rev
Log:
The GNU-style aligned attribute has an optional expression, but the generated pretty printing logic was unaware of this. Fixed the pretty printing logic, and added a test to ensure it no longer asserts.

Added a FIXME to the code about eliding the parenthesis when pretty printing such a construct.

Modified:
    cfe/trunk/test/Sema/ast-print.c
    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/test/Sema/ast-print.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/ast-print.c?rev=214513&r1=214512&r2=214513&view=diff
==============================================================================
--- cfe/trunk/test/Sema/ast-print.c (original)
+++ cfe/trunk/test/Sema/ast-print.c Fri Aug  1 08:49:00 2014
@@ -39,3 +39,6 @@ int rvarr(int n, int a[restrict static n
   return a[2];
 }
 
+typedef struct {
+  int f;
+} T __attribute__ ((__aligned__));

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=214513&r1=214512&r2=214513&view=diff
==============================================================================
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Fri Aug  1 08:49:00 2014
@@ -486,9 +486,10 @@ namespace {
     }
     void writeValue(raw_ostream &OS) const override {
       OS << "\";\n";
-      OS << "    assert(is" << getLowerName() << "Expr && " << getLowerName()
-         << "Expr != nullptr);\n";
-      OS << "    " << getLowerName() << "Expr->printPretty(OS, 0, Policy);\n";
+      // The aligned attribute argument expression is optional.
+      OS << "    if (is" << getLowerName() << "Expr && "
+         << getLowerName() << "Expr)\n";
+      OS << "      " << getLowerName() << "Expr->printPretty(OS, 0, Policy);\n";
       OS << "    OS << \"";
     }
     void writeDump(raw_ostream &OS) const override {
@@ -1120,6 +1121,11 @@ writePrettyPrintFunction(Record &R,
       continue;
     }
 
+    // FIXME: always printing the parenthesis isn't the correct behavior for
+    // attributes which have optional arguments that were not provided. For
+    // instance: __attribute__((aligned)) will be pretty printed as
+    // __attribute__((aligned())). The logic should check whether there is only
+    // a single argument, and if it is optional, whether it has been provided.
     if (!Args.empty())
       OS << "(";
     if (Spelling == "availability") {





More information about the cfe-commits mailing list