<div dir="ltr">As a possible way to actually test the generated code, the output, which must be a valid C text, could be compiled again. The result of the second compilation must be identical to the first one. For C this way indeed works, the corresponding changes are:<div class="gmail_extra">
<br></div><div class="gmail_extra"><div class="gmail_extra">diff --git a/test/Coverage/ast-printing.c b/test/Coverage/ast-printing.c</div><div class="gmail_extra">index ecaf3ab..eb22f92 100644</div><div class="gmail_extra">
--- a/test/Coverage/ast-printing.c</div><div class="gmail_extra">+++ b/test/Coverage/ast-printing.c</div><div class="gmail_extra">@@ -1,5 +1,7 @@</div><div class="gmail_extra"> // RUN: %clang_cc1 -fsyntax-only %s</div><div class="gmail_extra">
-// RUN: %clang_cc1 -ast-print %s</div><div class="gmail_extra">+// RUN: %clang_cc1 -ast-print %s -o %t.1.c</div><div class="gmail_extra">+// RUN: %clang_cc1 -ast-print %t.1.c -o %t.2.c</div><div class="gmail_extra">+// RUN: diff %t.1.c %t.2.c</div>
<div class="gmail_extra"> // RUN: %clang_cc1 -ast-dump %s</div><div class="gmail_extra"> // RUN: %clang_cc1 -print-decl-contexts %s</div><div><br></div><div>However, for C++ and ObjC this way does not work - output in these cases is not syntactically correct.</div>
<div><br></div><div>Do you think these changes may be checked in?</div><div><br></div></div><div class="gmail_extra"><div>Thanks,<br>--Serge<br></div>
<br><br><div class="gmail_quote">2014-06-21 1:53 GMT+07:00 David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5">On Fri, Jun 20, 2014 at 10:08 AM, Serge Pavlov <<a href="mailto:sepavloff@gmail.com">sepavloff@gmail.com</a>> wrote:<br>
> Author: sepavloff<br>
> Date: Fri Jun 20 12:08:28 2014<br>
> New Revision: 211380<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=211380&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=211380&view=rev</a><br>
> Log:<br>
> Fix crash caused by unnamed union or struct when doing ast-print<br>
><br>
> Modified:<br>
>     cfe/trunk/lib/AST/StmtPrinter.cpp<br>
>     cfe/trunk/test/Coverage/c-language-features.inc<br>
><br>
> Modified: cfe/trunk/lib/AST/StmtPrinter.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211380&r1=211379&r2=211380&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211380&r1=211379&r2=211380&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/AST/StmtPrinter.cpp (original)<br>
> +++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Jun 20 12:08:28 2014<br>
> @@ -1274,10 +1274,12 @@ void StmtPrinter::VisitDesignatedInitExp<br>
>                        DEnd = Node->designators_end();<br>
>         D != DEnd; ++D) {<br>
>      if (D->isFieldDesignator()) {<br>
> -      if (D->getDotLoc().isInvalid())<br>
> -        OS << D->getFieldName()->getName() << ":";<br>
> -      else<br>
> +      if (D->getDotLoc().isInvalid()) {<br>
> +        if (IdentifierInfo *II = D->getFieldName())<br>
> +          OS << II->getName() << ":";<br>
> +      } else {<br>
>          OS << "." << D->getFieldName()->getName();<br>
> +      }<br>
>      } else {<br>
>        OS << "[";<br>
>        if (D->isArrayDesignator()) {<br>
><br>
> Modified: cfe/trunk/test/Coverage/c-language-features.inc<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/c-language-features.inc?rev=211380&r1=211379&r2=211380&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/c-language-features.inc?rev=211380&r1=211379&r2=211380&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/Coverage/c-language-features.inc (original)<br>
> +++ cfe/trunk/test/Coverage/c-language-features.inc Fri Jun 20 12:08:28 2014<br>
> @@ -196,3 +196,15 @@ struct s11 {<br>
>    } f0;<br>
>    int f1;<br>
>  };<br>
> +<br>
> +// Unnamed structures.<br>
> +struct s12 {<br>
> +  struct {<br>
> +    unsigned char aa;<br>
> +    unsigned char bb;<br>
> +  };<br>
> +};<br>
> +<br>
> +void f11() {<br>
> +  struct s12 var = { .aa = 33 };<br>
> +}<br>
<br>
</div></div>Any chance of actually testing the output of ast-dump to ensure it's<br>
correct for this code? "does not crash" isn't really a good test to<br>
write (& while this test file/case is already doing that, I would<br>
prefer not to perpetuate that sort of thing).<br>
<span class=""><font color="#888888"><br>
- David<br>
</font></span></blockquote></div><br></div></div>