Skip to content

Commit

Permalink
Fix printing of types in initializers with suppressed tags.
Browse files Browse the repository at this point in the history
Tag and specifier printing can be suppressed in Decl::printGroup, but these suppressions leak into the initializers. Thus
    int *x = ((void *)0), *y = ((void *)0);
gets printed as
    int *x = ((void *)0), *y = ((*)0);
And
    struct { struct Z z; } z = {(struct Z){}};
gets printed as
    struct { struct Z z; } z = {(){}};
The stops the suppressions from leaking into the initializers.

Patch by Nick Sumner!

Differential Revision: http://reviews.llvm.org/D16438

llvm-svn: 258679
  • Loading branch information
d0k committed Jan 25, 2016
1 parent 65b8538 commit 54f81ed
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion clang/lib/AST/DeclPrinter.cpp
Expand Up @@ -751,7 +751,10 @@ void DeclPrinter::VisitVarDecl(VarDecl *D) {
else if (D->getInitStyle() == VarDecl::CInit) {
Out << " = ";
}
Init->printPretty(Out, nullptr, Policy, Indentation);
PrintingPolicy SubPolicy(Policy);
SubPolicy.SuppressSpecifiers = false;
SubPolicy.SuppressTag = false;
Init->printPretty(Out, nullptr, SubPolicy, Indentation);
if ((D->getInitStyle() == VarDecl::CallInit) && !isa<ParenListExpr>(Init))
Out << ")";
}
Expand Down
10 changes: 10 additions & 0 deletions clang/test/Sema/ast-print.c
Expand Up @@ -53,3 +53,13 @@ struct pair_t {

// CHECK: struct pair_t p = {a: 3, .b = 4};
struct pair_t p = {a: 3, .b = 4};

void initializers() {
// CHECK: int *x = ((void *)0), *y = ((void *)0);
int *x = ((void *)0), *y = ((void *)0);
struct Z{};
struct {
struct Z z;
// CHECK: } z = {(struct Z){}};
} z = {(struct Z){}};
}

0 comments on commit 54f81ed

Please sign in to comment.