diff options
author | Yunzhong Gao <Yunzhong_Gao@playstation.sony.com> | 2015-06-10 00:27:52 +0000 |
---|---|---|
committer | Yunzhong Gao <Yunzhong_Gao@playstation.sony.com> | 2015-06-10 00:27:52 +0000 |
commit | cb77930d6b20e53c735233eecf4572a1c30eb0c0 (patch) | |
tree | 74f8f3c0612aee5391a6cb5bbb5eb01c0a6d5be8 /clang/test/Analysis/designated-initializer.c | |
parent | 7912d9b8999266e55ff40e15d37fa458e66f436c (diff) | |
download | bcm5719-llvm-cb77930d6b20e53c735233eecf4572a1c30eb0c0.tar.gz bcm5719-llvm-cb77930d6b20e53c735233eecf4572a1c30eb0c0.zip |
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
Diffstat (limited to 'clang/test/Analysis/designated-initializer.c')
-rw-r--r-- | clang/test/Analysis/designated-initializer.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/clang/test/Analysis/designated-initializer.c b/clang/test/Analysis/designated-initializer.c new file mode 100644 index 00000000000..b601f872571 --- /dev/null +++ b/clang/test/Analysis/designated-initializer.c @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=debug.DumpCFG %s 2>&1 \ +// RUN: | FileCheck %s + +struct Q { int a, b, c; }; +union UQ { struct Q q; }; +union UQ getUQ() { + union UQ u = { { 1, 2, 3 } }; + return u; +} + +void test() { + struct LUQ { union UQ uq; } var = { getUQ(), .uq.q.a = 100 }; + struct Q s[] = { + [0] = (struct Q){1, 2}, + [0].c = 3 + }; +} + +// CHECK: void test() +// CHECK: [B1] +// CHECK: 1: getUQ +// CHECK: 2: [B1.1] (ImplicitCastExpr, FunctionToPointerDecay, union UQ (*)()) +// CHECK: 3: [B1.2]() +// CHECK: 4: 100 +// CHECK: 5: /*no init*/ +// CHECK: 6: /*no init*/ +// CHECK: 7: {[B1.4], [B1.5], [B1.6]} +// CHECK: 8: {[B1.7]} +// CHECK: 9: {/*base*/[B1.3], /*updater*/[B1.8]} +// CHECK: 10: {[B1.3], .uq.q.a = [B1.4]} +// CHECK: 11: struct LUQ var = {getUQ(), .uq.q.a = 100}; +// CHECK: 12: 1 +// CHECK: 13: 2 +// CHECK: 14: /*implicit*/(int)0 +// CHECK: 15: {[B1.12], [B1.13]} +// CHECK: 18: /*no init*/ +// CHECK: 19: /*no init*/ +// CHECK: 20: 3 +// CHECK: 21: {[B1.18], [B1.19], [B1.20]} +// CHECK: 22: {/*base*/[B1.17], /*updater*/[B1.21]} +// CHECK: 24: struct Q s[] = {[0] = (struct Q){1, 2}, [0].c = 3}; |