diff options
| author | Justin Bogner <mail@justinbogner.com> | 2015-05-28 22:19:36 +0000 |
|---|---|---|
| committer | Justin Bogner <mail@justinbogner.com> | 2015-05-28 22:19:36 +0000 |
| commit | cb337035f2b145dbad697ba203bd43a6de32be46 (patch) | |
| tree | 5d2bbd1b5f2d96ebe0d72cef2e10cbb009566656 | |
| parent | 2607a0d6551fc97d03e0b0f819d5a0eb096e013e (diff) | |
| download | bcm5719-llvm-cb337035f2b145dbad697ba203bd43a6de32be46.tar.gz bcm5719-llvm-cb337035f2b145dbad697ba203bd43a6de32be46.zip | |
AST: Fix printing GNU old-style field designators
Allows StmtPrinter to print old style field designators in
initializers, fixing an issue where we would print the following
invalid code:
struct A a = {b: = 3, .c = 4};
Patch by Nick Sumner. Thanks!
llvm-svn: 238517
| -rw-r--r-- | clang/lib/AST/StmtPrinter.cpp | 10 | ||||
| -rw-r--r-- | clang/test/Sema/ast-print.c | 8 |
2 files changed, 16 insertions, 2 deletions
diff --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp index dc4f9964c7a..cd65d729730 100644 --- a/clang/lib/AST/StmtPrinter.cpp +++ b/clang/lib/AST/StmtPrinter.cpp @@ -1395,13 +1395,16 @@ void StmtPrinter::VisitParenListExpr(ParenListExpr* Node) { } void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { + bool NeedsEquals = true; for (DesignatedInitExpr::designators_iterator D = Node->designators_begin(), DEnd = Node->designators_end(); D != DEnd; ++D) { if (D->isFieldDesignator()) { if (D->getDotLoc().isInvalid()) { - if (IdentifierInfo *II = D->getFieldName()) + if (IdentifierInfo *II = D->getFieldName()) { OS << II->getName() << ":"; + NeedsEquals = false; + } } else { OS << "." << D->getFieldName()->getName(); } @@ -1418,7 +1421,10 @@ void StmtPrinter::VisitDesignatedInitExpr(DesignatedInitExpr *Node) { } } - OS << " = "; + if (NeedsEquals) + OS << " = "; + else + OS << " "; PrintExpr(Node->getInit()); } diff --git a/clang/test/Sema/ast-print.c b/clang/test/Sema/ast-print.c index 4b2b43190d4..b4d76844fef 100644 --- a/clang/test/Sema/ast-print.c +++ b/clang/test/Sema/ast-print.c @@ -45,3 +45,11 @@ typedef struct { // CHECK: struct __attribute__((visibility("default"))) S; struct __attribute__((visibility("default"))) S; + +struct pair_t { + int a; + int b; +}; + +// CHECK: struct pair_t p = {a: 3, .b = 4}; +struct pair_t p = {a: 3, .b = 4}; |

