Skip to content

Commit a0df7d2

Browse files
committed
C++: Add tests for designated initializers with repetitions.
1 parent 0aa39c0 commit a0df7d2

10 files changed

+483
-1
lines changed

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_consistency.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
ambiguousSuccessors
10+
| ssa.c:3:14:3:16 | Uninitialized: definition of foo | Instruction 'Uninitialized: definition of foo' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:2:6:2:22 | void named_designators() | void named_designators() |
11+
| ssa.c:7:13:7:37 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:6:6:6:25 | void repeated_designators() | void repeated_designators() |
12+
| ssa.cpp:418:16:418:46 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.cpp:417:6:417:29 | void nested_array_designators() | void nested_array_designators() |
1013
unexplainedLoop
1114
unnecessaryPhiInstruction
1215
memoryOperandDefinitionIsUnmodeled

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_consistency_unsound.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
ambiguousSuccessors
10+
| ssa.c:3:14:3:16 | Uninitialized: definition of foo | Instruction 'Uninitialized: definition of foo' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:2:6:2:22 | void named_designators() | void named_designators() |
11+
| ssa.c:7:13:7:37 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:6:6:6:25 | void repeated_designators() | void repeated_designators() |
12+
| ssa.cpp:418:16:418:46 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.cpp:417:6:417:29 | void nested_array_designators() | void nested_array_designators() |
1013
unexplainedLoop
1114
unnecessaryPhiInstruction
1215
memoryOperandDefinitionIsUnmodeled

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_ir.expected

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,78 @@
1+
ssa.c:
2+
# 2| void named_designators()
3+
# 2| Block 0
4+
# 2| v2_1(void) = EnterFunction :
5+
# 2| m2_2(unknown) = AliasedDefinition :
6+
# 2| m2_3(unknown) = InitializeNonLocal :
7+
# 2| m2_4(unknown) = Chi : total:m2_2, partial:m2_3
8+
# 3| r3_1(glval<Foo>) = VariableAddress[foo] :
9+
# 3| m3_2(Foo) = Uninitialized[foo] : &:r3_1
10+
#-----| Goto -> Block 1
11+
#-----| Goto -> Block 1
12+
13+
# 3| Block 1
14+
# 3| r3_3(glval<int[2]>) = FieldAddress[x] : r3_1
15+
# 3| r3_5(int) = Constant[0] :
16+
# 3| r3_7(glval<int>) = PointerAdd[4] : r3_3, r3_5
17+
# 3| r3_9(int) = Constant[1234] :
18+
# 3| m3_11(int) = Store[?] : &:r3_7, r3_9
19+
# 3| m3_13(Foo) = Chi : total:m3_2, partial:m3_11
20+
# 3| r3_15(int) = Constant[1] :
21+
# 3| r3_17(glval<int>) = PointerAdd[4] : r3_3, r3_15
22+
# 3| r3_19(int) = Constant[0] :
23+
# 3| m3_21(int) = Store[?] : &:r3_17, r3_19
24+
# 3| m3_23(Foo) = Chi : total:m3_13, partial:m3_21
25+
#-----| Goto -> Block 3
26+
27+
# 3| Block 1
28+
# 3| r3_3(glval<int[2]>) = FieldAddress[x] : r3_1
29+
# 3| r3_5(int) = Constant[0] :
30+
# 3| r3_7(glval<int>) = PointerAdd[4] : r3_3, r3_5
31+
# 3| r3_9(int) = Constant[0] :
32+
# 3| m3_11(int) = Store[?] : &:r3_7, r3_9
33+
# 3| m3_13(Foo) = Chi : total:m3_2, partial:m3_11
34+
# 3| r3_15(int) = Constant[1] :
35+
# 3| r3_17(glval<int>) = PointerAdd[4] : r3_3, r3_15
36+
# 3| r3_19(int) = Constant[5678] :
37+
# 3| m3_21(int) = Store[?] : &:r3_17, r3_19
38+
# 3| m3_23(Foo) = Chi : total:m3_13, partial:m3_21
39+
#-----| Goto -> Block 3
40+
41+
# 4| Block 3
42+
# 4| v4_1(void) = NoOp :
43+
# 2| v2_5(void) = ReturnVoid :
44+
# 2| v2_6(void) = AliasedUse : m2_3
45+
# 2| v2_7(void) = ExitFunction :
46+
47+
# 6| void repeated_designators()
48+
# 6| Block 0
49+
# 6| v6_1(void) = EnterFunction :
50+
# 6| m6_2(unknown) = AliasedDefinition :
51+
# 6| m6_3(unknown) = InitializeNonLocal :
52+
# 6| m6_4(unknown) = Chi : total:m6_2, partial:m6_3
53+
# 7| r7_1(glval<int[1]>) = VariableAddress[x] :
54+
# 7| m7_2(int[1]) = Uninitialized[x] : &:r7_1
55+
# 7| r7_3(int) = Constant[0] :
56+
# 7| r7_4(glval<int>) = PointerAdd[4] : r7_1, r7_3
57+
#-----| Goto -> Block 1
58+
#-----| Goto -> Block 1
59+
60+
# 7| Block 1
61+
# 7| r7_5(int) = Constant[1234] :
62+
# 7| m7_7(int) = Store[?] : &:r7_4, r7_5
63+
#-----| Goto -> Block 3
64+
65+
# 7| Block 1
66+
# 7| r7_5(int) = Constant[5678] :
67+
# 7| m7_7(int) = Store[?] : &:r7_4, r7_5
68+
#-----| Goto -> Block 3
69+
70+
# 8| Block 3
71+
# 8| v8_1(void) = NoOp :
72+
# 6| v6_5(void) = ReturnVoid :
73+
# 6| v6_6(void) = AliasedUse : m6_3
74+
# 6| v6_7(void) = ExitFunction :
75+
176
ssa.cpp:
277
# 13| int ChiPhiNode(Point*, bool, bool)
378
# 13| Block 0
@@ -1892,3 +1967,48 @@ ssa.cpp:
18921967
# 401| v401_13(void) = ReturnVoid :
18931968
# 401| v401_14(void) = AliasedUse : ~m408_10
18941969
# 401| v401_15(void) = ExitFunction :
1970+
1971+
# 417| void nested_array_designators()
1972+
# 417| Block 0
1973+
# 417| v417_1(void) = EnterFunction :
1974+
# 417| m417_2(unknown) = AliasedDefinition :
1975+
# 417| m417_3(unknown) = InitializeNonLocal :
1976+
# 417| m417_4(unknown) = Chi : total:m417_2, partial:m417_3
1977+
# 418| r418_1(glval<int[1][2]>) = VariableAddress[x] :
1978+
# 418| m418_2(int[1][2]) = Uninitialized[x] : &:r418_1
1979+
# 418| r418_3(int) = Constant[0] :
1980+
# 418| r418_4(glval<int[2]>) = PointerAdd[8] : r418_1, r418_3
1981+
#-----| Goto -> Block 1
1982+
#-----| Goto -> Block 1
1983+
1984+
# 418| Block 1
1985+
# 418| r418_5(int) = Constant[0] :
1986+
# 418| r418_7(glval<int>) = PointerAdd[4] : r418_4, r418_5
1987+
# 418| r418_9(int) = Constant[0] :
1988+
# 418| m418_11(int) = Store[?] : &:r418_7, r418_9
1989+
# 418| m418_13(int[1][2]) = Chi : total:m418_2, partial:m418_11
1990+
# 418| r418_15(int) = Constant[1] :
1991+
# 418| r418_17(glval<int>) = PointerAdd[4] : r418_4, r418_15
1992+
# 418| r418_19(int) = Constant[5678] :
1993+
# 418| m418_21(int) = Store[?] : &:r418_17, r418_19
1994+
# 418| m418_23(int[1][2]) = Chi : total:m418_13, partial:m418_21
1995+
#-----| Goto -> Block 3
1996+
1997+
# 418| Block 1
1998+
# 418| r418_5(int) = Constant[0] :
1999+
# 418| r418_7(glval<int>) = PointerAdd[4] : r418_4, r418_5
2000+
# 418| r418_9(int) = Constant[1234] :
2001+
# 418| m418_11(int) = Store[?] : &:r418_7, r418_9
2002+
# 418| m418_13(int[1][2]) = Chi : total:m418_2, partial:m418_11
2003+
# 418| r418_15(int) = Constant[1] :
2004+
# 418| r418_17(glval<int>) = PointerAdd[4] : r418_4, r418_15
2005+
# 418| r418_19(int) = Constant[0] :
2006+
# 418| m418_21(int) = Store[?] : &:r418_17, r418_19
2007+
# 418| m418_23(int[1][2]) = Chi : total:m418_13, partial:m418_21
2008+
#-----| Goto -> Block 3
2009+
2010+
# 419| Block 3
2011+
# 419| v419_1(void) = NoOp :
2012+
# 417| v417_5(void) = ReturnVoid :
2013+
# 417| v417_6(void) = AliasedUse : m417_3
2014+
# 417| v417_7(void) = ExitFunction :

cpp/ql/test/library-tests/ir/ssa/aliased_ssa_ir_unsound.expected

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,78 @@
1+
ssa.c:
2+
# 2| void named_designators()
3+
# 2| Block 0
4+
# 2| v2_1(void) = EnterFunction :
5+
# 2| m2_2(unknown) = AliasedDefinition :
6+
# 2| m2_3(unknown) = InitializeNonLocal :
7+
# 2| m2_4(unknown) = Chi : total:m2_2, partial:m2_3
8+
# 3| r3_1(glval<Foo>) = VariableAddress[foo] :
9+
# 3| m3_2(Foo) = Uninitialized[foo] : &:r3_1
10+
#-----| Goto -> Block 1
11+
#-----| Goto -> Block 1
12+
13+
# 3| Block 1
14+
# 3| r3_3(glval<int[2]>) = FieldAddress[x] : r3_1
15+
# 3| r3_5(int) = Constant[0] :
16+
# 3| r3_7(glval<int>) = PointerAdd[4] : r3_3, r3_5
17+
# 3| r3_9(int) = Constant[1234] :
18+
# 3| m3_11(int) = Store[?] : &:r3_7, r3_9
19+
# 3| m3_13(Foo) = Chi : total:m3_2, partial:m3_11
20+
# 3| r3_15(int) = Constant[1] :
21+
# 3| r3_17(glval<int>) = PointerAdd[4] : r3_3, r3_15
22+
# 3| r3_19(int) = Constant[0] :
23+
# 3| m3_21(int) = Store[?] : &:r3_17, r3_19
24+
# 3| m3_23(Foo) = Chi : total:m3_13, partial:m3_21
25+
#-----| Goto -> Block 3
26+
27+
# 3| Block 1
28+
# 3| r3_3(glval<int[2]>) = FieldAddress[x] : r3_1
29+
# 3| r3_5(int) = Constant[0] :
30+
# 3| r3_7(glval<int>) = PointerAdd[4] : r3_3, r3_5
31+
# 3| r3_9(int) = Constant[0] :
32+
# 3| m3_11(int) = Store[?] : &:r3_7, r3_9
33+
# 3| m3_13(Foo) = Chi : total:m3_2, partial:m3_11
34+
# 3| r3_15(int) = Constant[1] :
35+
# 3| r3_17(glval<int>) = PointerAdd[4] : r3_3, r3_15
36+
# 3| r3_19(int) = Constant[5678] :
37+
# 3| m3_21(int) = Store[?] : &:r3_17, r3_19
38+
# 3| m3_23(Foo) = Chi : total:m3_13, partial:m3_21
39+
#-----| Goto -> Block 3
40+
41+
# 4| Block 3
42+
# 4| v4_1(void) = NoOp :
43+
# 2| v2_5(void) = ReturnVoid :
44+
# 2| v2_6(void) = AliasedUse : m2_3
45+
# 2| v2_7(void) = ExitFunction :
46+
47+
# 6| void repeated_designators()
48+
# 6| Block 0
49+
# 6| v6_1(void) = EnterFunction :
50+
# 6| m6_2(unknown) = AliasedDefinition :
51+
# 6| m6_3(unknown) = InitializeNonLocal :
52+
# 6| m6_4(unknown) = Chi : total:m6_2, partial:m6_3
53+
# 7| r7_1(glval<int[1]>) = VariableAddress[x] :
54+
# 7| m7_2(int[1]) = Uninitialized[x] : &:r7_1
55+
# 7| r7_3(int) = Constant[0] :
56+
# 7| r7_4(glval<int>) = PointerAdd[4] : r7_1, r7_3
57+
#-----| Goto -> Block 1
58+
#-----| Goto -> Block 1
59+
60+
# 7| Block 1
61+
# 7| r7_5(int) = Constant[1234] :
62+
# 7| m7_7(int) = Store[?] : &:r7_4, r7_5
63+
#-----| Goto -> Block 3
64+
65+
# 7| Block 1
66+
# 7| r7_5(int) = Constant[5678] :
67+
# 7| m7_7(int) = Store[?] : &:r7_4, r7_5
68+
#-----| Goto -> Block 3
69+
70+
# 8| Block 3
71+
# 8| v8_1(void) = NoOp :
72+
# 6| v6_5(void) = ReturnVoid :
73+
# 6| v6_6(void) = AliasedUse : m6_3
74+
# 6| v6_7(void) = ExitFunction :
75+
176
ssa.cpp:
277
# 13| int ChiPhiNode(Point*, bool, bool)
378
# 13| Block 0
@@ -1881,3 +1956,48 @@ ssa.cpp:
18811956
# 401| v401_13(void) = ReturnVoid :
18821957
# 401| v401_14(void) = AliasedUse : ~m408_10
18831958
# 401| v401_15(void) = ExitFunction :
1959+
1960+
# 417| void nested_array_designators()
1961+
# 417| Block 0
1962+
# 417| v417_1(void) = EnterFunction :
1963+
# 417| m417_2(unknown) = AliasedDefinition :
1964+
# 417| m417_3(unknown) = InitializeNonLocal :
1965+
# 417| m417_4(unknown) = Chi : total:m417_2, partial:m417_3
1966+
# 418| r418_1(glval<int[1][2]>) = VariableAddress[x] :
1967+
# 418| m418_2(int[1][2]) = Uninitialized[x] : &:r418_1
1968+
# 418| r418_3(int) = Constant[0] :
1969+
# 418| r418_4(glval<int[2]>) = PointerAdd[8] : r418_1, r418_3
1970+
#-----| Goto -> Block 1
1971+
#-----| Goto -> Block 1
1972+
1973+
# 418| Block 1
1974+
# 418| r418_5(int) = Constant[0] :
1975+
# 418| r418_7(glval<int>) = PointerAdd[4] : r418_4, r418_5
1976+
# 418| r418_9(int) = Constant[0] :
1977+
# 418| m418_11(int) = Store[?] : &:r418_7, r418_9
1978+
# 418| m418_13(int[1][2]) = Chi : total:m418_2, partial:m418_11
1979+
# 418| r418_15(int) = Constant[1] :
1980+
# 418| r418_17(glval<int>) = PointerAdd[4] : r418_4, r418_15
1981+
# 418| r418_19(int) = Constant[5678] :
1982+
# 418| m418_21(int) = Store[?] : &:r418_17, r418_19
1983+
# 418| m418_23(int[1][2]) = Chi : total:m418_13, partial:m418_21
1984+
#-----| Goto -> Block 3
1985+
1986+
# 418| Block 1
1987+
# 418| r418_5(int) = Constant[0] :
1988+
# 418| r418_7(glval<int>) = PointerAdd[4] : r418_4, r418_5
1989+
# 418| r418_9(int) = Constant[1234] :
1990+
# 418| m418_11(int) = Store[?] : &:r418_7, r418_9
1991+
# 418| m418_13(int[1][2]) = Chi : total:m418_2, partial:m418_11
1992+
# 418| r418_15(int) = Constant[1] :
1993+
# 418| r418_17(glval<int>) = PointerAdd[4] : r418_4, r418_15
1994+
# 418| r418_19(int) = Constant[0] :
1995+
# 418| m418_21(int) = Store[?] : &:r418_17, r418_19
1996+
# 418| m418_23(int[1][2]) = Chi : total:m418_13, partial:m418_21
1997+
#-----| Goto -> Block 3
1998+
1999+
# 419| Block 3
2000+
# 419| v419_1(void) = NoOp :
2001+
# 417| v417_5(void) = ReturnVoid :
2002+
# 417| v417_6(void) = AliasedUse : m417_3
2003+
# 417| v417_7(void) = ExitFunction :
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
struct Foo { int x[2]; };
2+
void named_designators() {
3+
struct Foo foo = {.x[0] = 1234, .x[1] = 5678};
4+
}
5+
6+
void repeated_designators() {
7+
int x[1] = {[0] = 1234, [0] = 5678};
8+
}

cpp/ql/test/library-tests/ir/ssa/ssa.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,4 +412,8 @@ void vla(int n1, int n2, int n3, bool b1) {
412412
} else {
413413
int b[n2];
414414
}
415-
}
415+
}
416+
417+
void nested_array_designators() {
418+
int x[1][2] = {[0][0] = 1234, [0][1] = 5678};
419+
}

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_consistency.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
ambiguousSuccessors
10+
| ssa.c:3:14:3:16 | Uninitialized: definition of foo | Instruction 'Uninitialized: definition of foo' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:2:6:2:22 | void named_designators() | void named_designators() |
11+
| ssa.c:7:13:7:37 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:6:6:6:25 | void repeated_designators() | void repeated_designators() |
12+
| ssa.cpp:418:16:418:46 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.cpp:417:6:417:29 | void nested_array_designators() | void nested_array_designators() |
1013
unexplainedLoop
1114
unnecessaryPhiInstruction
1215
memoryOperandDefinitionIsUnmodeled

cpp/ql/test/library-tests/ir/ssa/unaliased_ssa_consistency_unsound.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ duplicateChiOperand
77
sideEffectWithoutPrimary
88
instructionWithoutSuccessor
99
ambiguousSuccessors
10+
| ssa.c:3:14:3:16 | Uninitialized: definition of foo | Instruction 'Uninitialized: definition of foo' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:2:6:2:22 | void named_designators() | void named_designators() |
11+
| ssa.c:7:13:7:37 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.c:6:6:6:25 | void repeated_designators() | void repeated_designators() |
12+
| ssa.cpp:418:16:418:46 | PointerAdd: {...} | Instruction 'PointerAdd: {...}' has 2 successors of kind 'Goto' in function '$@'. | ssa.cpp:417:6:417:29 | void nested_array_designators() | void nested_array_designators() |
1013
unexplainedLoop
1114
unnecessaryPhiInstruction
1215
memoryOperandDefinitionIsUnmodeled

0 commit comments

Comments
 (0)