[PATCH] D16430: Fix printing of nested variable declarations with suppressed specifiers

Nick Sumner via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 21 15:04:41 PST 2016


nick.sumner created this revision.
nick.sumner added reviewers: bkramer, rsmith.
nick.sumner added a subscriber: cfe-commits.

Allow nested variable declarations to have their types printed correctly even
when the incoming PrintingPolicy suppresses specifiers. This can happen when
initializing a variable with a statement expression. Given the C code:

    int a, b = ({
        int c = 1;
        c;
    });

The declaration of c is printed with a missing type specifier:

    int a, b = ({
        c = 1;
        c;
    });

With the patch, the declaration of c is properly printed:

    int a, b = ({
        int c = 1;
        c;
    });

This is related to the previous patch: http://reviews.llvm.org/D16352

http://reviews.llvm.org/D16430

Files:
  lib/AST/StmtPrinter.cpp
  test/Sema/ast-print.c

Index: test/Sema/ast-print.c
===================================================================
--- test/Sema/ast-print.c
+++ test/Sema/ast-print.c
@@ -58,3 +58,11 @@
 // CHECK: int *x = ((void *)0), *y = ((void *)0);
   int *x = ((void *)0), *y = ((void *)0);
 }
+
+void stmtExpr() {
+  int a, b = ({
+// CHECK: int c = 1;
+    int c = 1;
+    c;
+  });
+}
Index: lib/AST/StmtPrinter.cpp
===================================================================
--- lib/AST/StmtPrinter.cpp
+++ lib/AST/StmtPrinter.cpp
@@ -127,7 +127,9 @@
 
 void StmtPrinter::PrintRawDeclStmt(const DeclStmt *S) {
   SmallVector<Decl*, 2> Decls(S->decls());
-  Decl::printGroup(Decls.data(), Decls.size(), OS, Policy, IndentLevel);
+  PrintingPolicy SubPolicy(Policy);
+  SubPolicy.SuppressSpecifiers = false;
+  Decl::printGroup(Decls.data(), Decls.size(), OS, SubPolicy, IndentLevel);
 }
 
 void StmtPrinter::VisitNullStmt(NullStmt *Node) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16430.45601.patch
Type: text/x-patch
Size: 922 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160121/9525736a/attachment.bin>


More information about the cfe-commits mailing list