Implementing C99 partial re-initialization behavior (DR-253)
authorYunzhong Gao <Yunzhong_Gao@playstation.sony.com>
Wed, 10 Jun 2015 00:27:52 +0000 (00:27 +0000)
committerYunzhong Gao <Yunzhong_Gao@playstation.sony.com>
Wed, 10 Jun 2015 00:27:52 +0000 (00:27 +0000)
commitcb77930d6b20e53c735233eecf4572a1c30eb0c0
tree74f8f3c0612aee5391a6cb5bbb5eb01c0a6d5be8
parent7912d9b8999266e55ff40e15d37fa458e66f436c
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
28 files changed:
clang/include/clang/AST/DataRecursiveASTVisitor.h
clang/include/clang/AST/Expr.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/StmtNodes.td
clang/include/clang/Serialization/ASTBitCodes.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/CodeGen/CGExprConstant.cpp
clang/lib/Sema/SemaExceptionSpec.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/test/Analysis/designated-initializer.c [new file with mode: 0644]
clang/test/CodeGen/partial-reinitialization1.c [new file with mode: 0644]
clang/test/CodeGen/partial-reinitialization2.c [new file with mode: 0644]
clang/test/PCH/designated-init.c.h
clang/test/Sema/designated-initializers.c
clang/test/SemaCXX/decltype.cpp
clang/tools/libclang/CXCursor.cpp