From cb77930d6b20e53c735233eecf4572a1c30eb0c0 Mon Sep 17 00:00:00 2001 From: Yunzhong Gao Date: Wed, 10 Jun 2015 00:27:52 +0000 Subject: Implementing C99 partial re-initialization behavior (DR-253) Based on previous discussion on the mailing list, clang currently lacks support for C99 partial re-initialization behavior: Reference: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2013-April/029188.html Reference: http://www.open-std.org/jtc1/sc22/wg14/www/docs/dr_253.htm This patch attempts to fix this problem. Given the following code snippet, struct P1 { char x[6]; }; struct LP1 { struct P1 p1; }; struct LP1 l = { .p1 = { "foo" }, .p1.x[2] = 'x' }; // this example is adapted from the example for "struct fred x[]" in DR-253; // currently clang produces in l: { "\0\0x" }, // whereas gcc 4.8 produces { "fox" }; // with this fix, clang will also produce: { "fox" }; Differential Review: http://reviews.llvm.org/D5789 llvm-svn: 239446 --- clang/lib/Serialization/ASTReaderStmt.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'clang/lib/Serialization/ASTReaderStmt.cpp') diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index d1ecd467248..d84b5be5850 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -801,6 +801,16 @@ void ASTStmtReader::VisitDesignatedInitExpr(DesignatedInitExpr *E) { Designators.data(), Designators.size()); } +void ASTStmtReader::VisitDesignatedInitUpdateExpr(DesignatedInitUpdateExpr *E) { + VisitExpr(E); + E->setBase(Reader.ReadSubExpr()); + E->setUpdater(Reader.ReadSubExpr()); +} + +void ASTStmtReader::VisitNoInitExpr(NoInitExpr *E) { + VisitExpr(E); +} + void ASTStmtReader::VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { VisitExpr(E); } @@ -2549,10 +2559,18 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; + case EXPR_DESIGNATED_INIT_UPDATE: + S = new (Context) DesignatedInitUpdateExpr(Empty); + break; + case EXPR_IMPLICIT_VALUE_INIT: S = new (Context) ImplicitValueInitExpr(Empty); break; + case EXPR_NO_INIT: + S = new (Context) NoInitExpr(Empty); + break; + case EXPR_VA_ARG: S = new (Context) VAArgExpr(Empty); break; -- cgit v1.2.3