From: Aaron Ballman Date: Fri, 1 Aug 2014 13:49:00 +0000 (+0000) Subject: The GNU-style aligned attribute has an optional expression, but the generated pretty... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18dfa9d42e05217a0c17ad051788b705996cefb4;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214513 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Sema/ast-print.c b/test/Sema/ast-print.c index 382f0d3896..8ac4960b11 100644 --- a/test/Sema/ast-print.c +++ b/test/Sema/ast-print.c @@ -39,3 +39,6 @@ int rvarr(int n, int a[restrict static n]) { return a[2]; } +typedef struct { + int f; +} T __attribute__ ((__aligned__)); diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index 0f0f89e55c..45e9e02508 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -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") {