r211380 - Fix crash caused by unnamed union or struct when doing ast-print

David Blaikie dblaikie at gmail.com
Fri Jun 20 11:53:33 PDT 2014


On Fri, Jun 20, 2014 at 10:08 AM, Serge Pavlov <sepavloff at gmail.com> wrote:
> Author: sepavloff
> Date: Fri Jun 20 12:08:28 2014
> New Revision: 211380
>
> URL: http://llvm.org/viewvc/llvm-project?rev=211380&view=rev
> Log:
> Fix crash caused by unnamed union or struct when doing ast-print
>
> Modified:
>     cfe/trunk/lib/AST/StmtPrinter.cpp
>     cfe/trunk/test/Coverage/c-language-features.inc
>
> Modified: cfe/trunk/lib/AST/StmtPrinter.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/StmtPrinter.cpp?rev=211380&r1=211379&r2=211380&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/StmtPrinter.cpp (original)
> +++ cfe/trunk/lib/AST/StmtPrinter.cpp Fri Jun 20 12:08:28 2014
> @@ -1274,10 +1274,12 @@ void StmtPrinter::VisitDesignatedInitExp
>                        DEnd = Node->designators_end();
>         D != DEnd; ++D) {
>      if (D->isFieldDesignator()) {
> -      if (D->getDotLoc().isInvalid())
> -        OS << D->getFieldName()->getName() << ":";
> -      else
> +      if (D->getDotLoc().isInvalid()) {
> +        if (IdentifierInfo *II = D->getFieldName())
> +          OS << II->getName() << ":";
> +      } else {
>          OS << "." << D->getFieldName()->getName();
> +      }
>      } else {
>        OS << "[";
>        if (D->isArrayDesignator()) {
>
> Modified: cfe/trunk/test/Coverage/c-language-features.inc
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Coverage/c-language-features.inc?rev=211380&r1=211379&r2=211380&view=diff
> ==============================================================================
> --- cfe/trunk/test/Coverage/c-language-features.inc (original)
> +++ cfe/trunk/test/Coverage/c-language-features.inc Fri Jun 20 12:08:28 2014
> @@ -196,3 +196,15 @@ struct s11 {
>    } f0;
>    int f1;
>  };
> +
> +// Unnamed structures.
> +struct s12 {
> +  struct {
> +    unsigned char aa;
> +    unsigned char bb;
> +  };
> +};
> +
> +void f11() {
> +  struct s12 var = { .aa = 33 };
> +}

Any chance of actually testing the output of ast-dump to ensure it's
correct for this code? "does not crash" isn't really a good test to
write (& while this test file/case is already doing that, I would
prefer not to perpetuate that sort of thing).

- David



More information about the cfe-commits mailing list