Skip to content

Commit ef8d95f

Browse files
committed
C++: Add IR test that shows dataflow regression after frontend update
1 parent 40eab18 commit ef8d95f

File tree

4 files changed

+169
-0
lines changed

4 files changed

+169
-0
lines changed

cpp/ql/test/library-tests/ir/ir/PrintAST.expected

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,76 @@ complex.c:
17281728
# 144| Type = [LongDoubleType] long double
17291729
# 144| ValueCategory = prvalue
17301730
# 145| getStmt(72): [ReturnStmt] return ...
1731+
ir.c:
1732+
# 5| [TopLevelFunction] int getX(MyCoords*)
1733+
# 5| <params>:
1734+
# 5| getParameter(0): [Parameter] coords
1735+
# 5| Type = [PointerType] MyCoords *
1736+
# 7| [TopLevelFunction] void MyCoordsTest(int)
1737+
# 7| <params>:
1738+
# 7| getParameter(0): [Parameter] pos
1739+
# 7| Type = [IntType] int
1740+
# 7| getEntryPoint(): [BlockStmt] { ... }
1741+
# 8| getStmt(0): [DeclStmt] declaration
1742+
# 8| getDeclarationEntry(0): [VariableDeclarationEntry] definition of coords
1743+
# 8| Type = [CTypedefType] MyCoords
1744+
# 8| getVariable().getInitializer(): [Initializer] initializer for coords
1745+
# 8| getExpr(): [ClassAggregateLiteral] {...}
1746+
# 8| Type = [Struct] (unnamed class/struct/union)
1747+
# 8| ValueCategory = prvalue
1748+
# 8| getAFieldExpr(x): [Literal] 0
1749+
# 8| Type = [IntType] int
1750+
# 8| Value = [Literal] 0
1751+
# 8| ValueCategory = prvalue
1752+
# 9| getStmt(1): [ExprStmt] ExprStmt
1753+
# 9| getExpr(): [AssignExpr] ... = ...
1754+
# 9| Type = [IntType] int
1755+
# 9| ValueCategory = prvalue
1756+
# 9| getLValue(): [ValueFieldAccess] x
1757+
# 9| Type = [IntType] int
1758+
# 9| ValueCategory = lvalue
1759+
# 9| getQualifier(): [VariableAccess] coords
1760+
# 9| Type = [CTypedefType] MyCoords
1761+
# 9| ValueCategory = lvalue
1762+
# 9| getRValue(): [AssignExpr] ... = ...
1763+
# 9| Type = [IntType] int
1764+
# 9| ValueCategory = prvalue
1765+
# 9| getLValue(): [ValueFieldAccess] y
1766+
# 9| Type = [IntType] int
1767+
# 9| ValueCategory = lvalue
1768+
# 9| getQualifier(): [VariableAccess] coords
1769+
# 9| Type = [CTypedefType] MyCoords
1770+
# 9| ValueCategory = lvalue
1771+
# 9| getRValue(): [AddExpr] ... + ...
1772+
# 9| Type = [IntType] int
1773+
# 9| ValueCategory = prvalue
1774+
# 9| getLeftOperand(): [VariableAccess] pos
1775+
# 9| Type = [IntType] int
1776+
# 9| ValueCategory = prvalue(load)
1777+
# 9| getRightOperand(): [Literal] 1
1778+
# 9| Type = [IntType] int
1779+
# 9| Value = [Literal] 1
1780+
# 9| ValueCategory = prvalue
1781+
# 10| getStmt(2): [ExprStmt] ExprStmt
1782+
# 10| getExpr(): [AssignExpr] ... = ...
1783+
# 10| Type = [IntType] int
1784+
# 10| ValueCategory = prvalue
1785+
# 10| getLValue(): [ValueFieldAccess] x
1786+
# 10| Type = [IntType] int
1787+
# 10| ValueCategory = lvalue
1788+
# 10| getQualifier(): [VariableAccess] coords
1789+
# 10| Type = [CTypedefType] MyCoords
1790+
# 10| ValueCategory = lvalue
1791+
# 10| getRValue(): [FunctionCall] call to getX
1792+
# 10| Type = [IntType] int
1793+
# 10| ValueCategory = prvalue
1794+
# 10| getArgument(0): [AddressOfExpr] & ...
1795+
# 10| Type = [PointerType] MyCoords *
1796+
# 10| ValueCategory = prvalue
1797+
# 10| getOperand(): [VariableAccess] coords
1798+
# 10| Type = [CTypedefType] MyCoords
1799+
# 10| ValueCategory = lvalue
1800+
# 11| getStmt(3): [ReturnStmt] return ...
17311801
ir.cpp:
17321802
# 1| [TopLevelFunction] void Constants()
17331803
# 1| <params>:

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
typedef struct {
2+
int x, y;
3+
} MyCoords;
4+
5+
int getX(MyCoords *coords);
6+
7+
void MyCoordsTest(int pos) {
8+
MyCoords coords = {0};
9+
coords.x = coords.y = pos + 1;
10+
coords.x = getX(&coords);
11+
}

cpp/ql/test/library-tests/ir/ir/operand_locations.expected

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,52 @@
932932
| file://:0:0:0:0 | Unary | r0_20 |
933933
| file://:0:0:0:0 | Unary | r0_21 |
934934
| file://:0:0:0:0 | Unary | r0_21 |
935+
| ir.c:7:6:7:17 | ChiPartial | partial:m7_3 |
936+
| ir.c:7:6:7:17 | ChiTotal | total:m7_2 |
937+
| ir.c:7:6:7:17 | SideEffect | ~m10_6 |
938+
| ir.c:7:23:7:25 | Address | &:r7_5 |
939+
| ir.c:8:12:8:17 | Address | &:r8_1 |
940+
| ir.c:8:12:8:17 | Unary | r8_1 |
941+
| ir.c:8:12:8:17 | Unary | r8_1 |
942+
| ir.c:8:20:8:23 | Address | &:r8_3 |
943+
| ir.c:8:20:8:23 | Address | &:r8_7 |
944+
| ir.c:8:20:8:23 | ChiPartial | partial:m8_9 |
945+
| ir.c:8:20:8:23 | ChiTotal | total:m8_6 |
946+
| ir.c:8:20:8:23 | StoreValue | r8_8 |
947+
| ir.c:8:22:8:22 | ChiPartial | partial:m8_5 |
948+
| ir.c:8:22:8:22 | ChiTotal | total:m8_2 |
949+
| ir.c:8:22:8:22 | StoreValue | r8_4 |
950+
| ir.c:9:3:9:8 | Unary | r9_10 |
951+
| ir.c:9:3:9:31 | ChiPartial | partial:m9_12 |
952+
| ir.c:9:3:9:31 | ChiTotal | total:m9_8 |
953+
| ir.c:9:10:9:10 | Address | &:r9_11 |
954+
| ir.c:9:14:9:19 | Unary | r9_5 |
955+
| ir.c:9:14:9:31 | ChiPartial | partial:m9_7 |
956+
| ir.c:9:14:9:31 | ChiTotal | total:m8_10 |
957+
| ir.c:9:14:9:31 | StoreValue | r9_9 |
958+
| ir.c:9:21:9:21 | Address | &:r9_6 |
959+
| ir.c:9:25:9:27 | Address | &:r9_1 |
960+
| ir.c:9:25:9:27 | Left | r9_2 |
961+
| ir.c:9:25:9:27 | Load | m7_6 |
962+
| ir.c:9:25:9:31 | StoreValue | r9_4 |
963+
| ir.c:9:25:9:31 | Unary | r9_4 |
964+
| ir.c:9:31:9:31 | Right | r9_3 |
965+
| ir.c:10:3:10:8 | Unary | r10_10 |
966+
| ir.c:10:3:10:26 | ChiPartial | partial:m10_12 |
967+
| ir.c:10:3:10:26 | ChiTotal | total:m10_9 |
968+
| ir.c:10:10:10:10 | Address | &:r10_11 |
969+
| ir.c:10:14:10:17 | CallTarget | func:r10_1 |
970+
| ir.c:10:14:10:17 | ChiPartial | partial:m10_5 |
971+
| ir.c:10:14:10:17 | ChiTotal | total:m7_4 |
972+
| ir.c:10:14:10:17 | SideEffect | ~m7_4 |
973+
| ir.c:10:14:10:17 | StoreValue | r10_4 |
974+
| ir.c:10:19:10:25 | Address | &:r10_3 |
975+
| ir.c:10:19:10:25 | Address | &:r10_3 |
976+
| ir.c:10:19:10:25 | Arg(0) | 0:r10_3 |
977+
| ir.c:10:19:10:25 | ChiPartial | partial:m10_8 |
978+
| ir.c:10:19:10:25 | ChiTotal | total:m9_13 |
979+
| ir.c:10:19:10:25 | SideEffect | ~m9_13 |
980+
| ir.c:10:20:10:25 | Unary | r10_2 |
935981
| ir.cpp:1:6:1:14 | ChiPartial | partial:m1_3 |
936982
| ir.cpp:1:6:1:14 | ChiTotal | total:m1_2 |
937983
| ir.cpp:1:6:1:14 | SideEffect | m1_3 |

cpp/ql/test/library-tests/ir/ir/raw_ir.expected

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,48 @@ complex.c:
724724
# 58| v58_5(void) = AliasedUse : ~m?
725725
# 58| v58_6(void) = ExitFunction :
726726

727+
ir.c:
728+
# 7| void MyCoordsTest(int)
729+
# 7| Block 0
730+
# 7| v7_1(void) = EnterFunction :
731+
# 7| mu7_2(unknown) = AliasedDefinition :
732+
# 7| mu7_3(unknown) = InitializeNonLocal :
733+
# 7| r7_4(glval<int>) = VariableAddress[pos] :
734+
# 7| mu7_5(int) = InitializeParameter[pos] : &:r7_4
735+
# 8| r8_1(glval<(unnamed class/struct/union)>) = VariableAddress[coords] :
736+
# 8| mu8_2((unnamed class/struct/union)) = Uninitialized[coords] : &:r8_1
737+
# 8| r8_3(glval<int>) = FieldAddress[x] : r8_1
738+
# 8| r8_4(int) = Constant[0] :
739+
# 8| mu8_5(int) = Store[?] : &:r8_3, r8_4
740+
# 8| r8_6(glval<int>) = FieldAddress[y] : r8_1
741+
# 8| r8_7(int) = Constant[0] :
742+
# 8| mu8_8(int) = Store[?] : &:r8_6, r8_7
743+
# 9| r9_1(glval<int>) = VariableAddress[pos] :
744+
# 9| r9_2(int) = Load[pos] : &:r9_1, ~m?
745+
# 9| r9_3(int) = Constant[1] :
746+
# 9| r9_4(int) = Add : r9_2, r9_3
747+
# 9| r9_5(glval<(unnamed class/struct/union)>) = VariableAddress[coords] :
748+
# 9| r9_6(glval<int>) = FieldAddress[y] : r9_5
749+
# 9| mu9_7(int) = Store[?] : &:r9_6, r9_4
750+
# 9| r9_8(int) = CopyValue : r9_4
751+
# 9| r9_9(glval<(unnamed class/struct/union)>) = VariableAddress[coords] :
752+
# 9| r9_10(glval<int>) = FieldAddress[x] : r9_9
753+
# 9| mu9_11(int) = Store[?] : &:r9_10, r9_8
754+
# 10| r10_1(glval<unknown>) = FunctionAddress[getX] :
755+
# 10| r10_2(glval<(unnamed class/struct/union)>) = VariableAddress[coords] :
756+
# 10| r10_3(struct <unnamed> *) = CopyValue : r10_2
757+
# 10| r10_4(int) = Call[getX] : func:r10_1, 0:r10_3
758+
# 10| mu10_5(unknown) = ^CallSideEffect : ~m?
759+
# 10| v10_6(void) = ^BufferReadSideEffect[0] : &:r10_3, ~m?
760+
# 10| mu10_7(unknown) = ^BufferMayWriteSideEffect[0] : &:r10_3
761+
# 10| r10_8(glval<(unnamed class/struct/union)>) = VariableAddress[coords] :
762+
# 10| r10_9(glval<int>) = FieldAddress[x] : r10_8
763+
# 10| mu10_10(int) = Store[?] : &:r10_9, r10_4
764+
# 11| v11_1(void) = NoOp :
765+
# 7| v7_6(void) = ReturnVoid :
766+
# 7| v7_7(void) = AliasedUse : ~m?
767+
# 7| v7_8(void) = ExitFunction :
768+
727769
ir.cpp:
728770
# 1| void Constants()
729771
# 1| Block 0

0 commit comments

Comments
 (0)