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) {
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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits