diff --git a/src/internals/tactIRBuilder.ts b/src/internals/tactIRBuilder.ts index bdcfabb9..3a09e134 100644 --- a/src/internals/tactIRBuilder.ts +++ b/src/internals/tactIRBuilder.ts @@ -229,9 +229,8 @@ export class AstMapper { break; case "statement_while": case "statement_until": - stmt.statements.forEach((s) => this.processStmt(s)); - break; case "statement_repeat": + case "statement_foreach": stmt.statements.forEach((s) => this.processStmt(s)); break; default: @@ -626,7 +625,8 @@ export class TactIRBuilder { } else if ( stmt.kind == "statement_while" || stmt.kind == "statement_until" || - stmt.kind == "statement_repeat" + stmt.kind == "statement_repeat" || + stmt.kind == "statement_foreach" ) { // Create an edge from the current node (loop condition) back to the start of the loop body, // and from the end of the loop body back to the current node to represent the loop's cycle. diff --git a/test/contracts/loops-4.cfg.dot b/test/contracts/loops-4.cfg.dot new file mode 100644 index 00000000..43cd0200 --- /dev/null +++ b/test/contracts/loops-4.cfg.dot @@ -0,0 +1,10 @@ +digraph "loops-4" { + node [shape=box]; + subgraph "cluster_test" { + label="test"; + "test_141" [label="let m: map = emptyMap()"]; + "test_142" [label="foreach ((k, v) of m)"]; + "test_141" -> "test_142"; + "test_142" -> "test_142"; + } +} diff --git a/test/contracts/loops-4.cfg.json b/test/contracts/loops-4.cfg.json new file mode 100644 index 00000000..6afa254a --- /dev/null +++ b/test/contracts/loops-4.cfg.json @@ -0,0 +1,44 @@ +{ + "projectName": "loops-4", + "functions": [ + { + "name": "test", + "cfg": { + "nodes": [ + { + "id": 141, + "stmtID": 29445, + "srcEdges": [], + "dstEdges": [ + 143 + ] + }, + { + "id": 142, + "stmtID": 29449, + "srcEdges": [ + 143, + 144 + ], + "dstEdges": [ + 144 + ] + } + ], + "edges": [ + { + "id": 143, + "src": 141, + "dst": 142 + }, + { + "id": 144, + "src": 142, + "dst": 142 + } + ] + } + } + ], + "contracts": [] +} \ No newline at end of file diff --git a/test/contracts/loops-4.expected.out b/test/contracts/loops-4.expected.out new file mode 100644 index 00000000..eb6802b9 --- /dev/null +++ b/test/contracts/loops-4.expected.out @@ -0,0 +1,8 @@ +test/contracts/loops-4.tact:2:5: + 1 | fun test() { +> 2 | let m: map = emptyMap(); + ^ + 3 | foreach (k, v in m) { +Read-only variable +Help: Consider creating a constant instead +See: https://nowarp.github.io/docs/misti/docs/detectors/ReadOnlyVariables \ No newline at end of file diff --git a/test/contracts/loops-4.tact b/test/contracts/loops-4.tact new file mode 100644 index 00000000..a93a1905 --- /dev/null +++ b/test/contracts/loops-4.tact @@ -0,0 +1,5 @@ +fun test() { + let m: map = emptyMap(); + foreach (k, v in m) { + } +} diff --git a/test/contracts/messages-1.cfg.dot b/test/contracts/messages-1.cfg.dot index 8728dc8f..29ef4bde 100644 --- a/test/contracts/messages-1.cfg.dot +++ b/test/contracts/messages-1.cfg.dot @@ -1,13 +1,13 @@ digraph "messages-1" { node [shape=box]; - subgraph "cluster_A__receive_internal_comment_31172_increment" { - label="A__receive_internal_comment_31172_increment"; - "A__receive_internal_comment_31172_increment_142" [label="self.val = self.val + 1"]; - "A__receive_internal_comment_31172_increment_143" [label="self.reply(M{value: self.val}.toCell())"]; - "A__receive_internal_comment_31172_increment_142" -> "A__receive_internal_comment_31172_increment_143"; + subgraph "cluster_A__receive_internal_comment_34250_increment" { + label="A__receive_internal_comment_34250_increment"; + "A__receive_internal_comment_34250_increment_142" [label="self.val = self.val + 1"]; + "A__receive_internal_comment_34250_increment_143" [label="self.reply(M{value: self.val}.toCell())"]; + "A__receive_internal_comment_34250_increment_142" -> "A__receive_internal_comment_34250_increment_143"; } - subgraph "cluster_A__receive_internal_comment_31187_query" { - label="A__receive_internal_comment_31187_query"; - "A__receive_internal_comment_31187_query_145" [label="self.reply(M{value: self.val}.toCell())"]; + subgraph "cluster_A__receive_internal_comment_34265_query" { + label="A__receive_internal_comment_34265_query"; + "A__receive_internal_comment_34265_query_145" [label="self.reply(M{value: self.val}.toCell())"]; } } diff --git a/test/contracts/messages-1.cfg.json b/test/contracts/messages-1.cfg.json index 08c0fa11..6c0dc5e5 100644 --- a/test/contracts/messages-1.cfg.json +++ b/test/contracts/messages-1.cfg.json @@ -6,12 +6,12 @@ "name": "A", "methods": [ { - "name": "A.receive_internal_comment_29473_increment", + "name": "A.receive_internal_comment_32551_increment", "cfg": { "nodes": [ { "id": 142, - "stmtID": 29459, + "stmtID": 32537, "srcEdges": [], "dstEdges": [ 144 @@ -19,7 +19,7 @@ }, { "id": 143, - "stmtID": 29472, + "stmtID": 32550, "srcEdges": [ 144 ], @@ -36,12 +36,12 @@ } }, { - "name": "A.receive_internal_comment_29488_query", + "name": "A.receive_internal_comment_32566_query", "cfg": { "nodes": [ { "id": 145, - "stmtID": 29487, + "stmtID": 32565, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/never-accessed-1.cfg.json b/test/contracts/never-accessed-1.cfg.json index 6d6339f0..d1538d41 100644 --- a/test/contracts/never-accessed-1.cfg.json +++ b/test/contracts/never-accessed-1.cfg.json @@ -7,7 +7,7 @@ "nodes": [ { "id": 141, - "stmtID": 32841, + "stmtID": 35919, "srcEdges": [], "dstEdges": [ 143 @@ -15,7 +15,7 @@ }, { "id": 142, - "stmtID": 32846, + "stmtID": 35924, "srcEdges": [ 143 ], @@ -25,7 +25,7 @@ }, { "id": 144, - "stmtID": 32845, + "stmtID": 35923, "srcEdges": [ 145 ], @@ -35,7 +35,7 @@ }, { "id": 146, - "stmtID": 32848, + "stmtID": 35926, "srcEdges": [ 147 ], diff --git a/test/contracts/never-accessed-2.cfg.dot b/test/contracts/never-accessed-2.cfg.dot index 7ec95662..9c7c975a 100644 --- a/test/contracts/never-accessed-2.cfg.dot +++ b/test/contracts/never-accessed-2.cfg.dot @@ -1,8 +1,8 @@ digraph "never-accessed-2" { node [shape=box]; - subgraph "cluster_FieldTest__init_37609" { - label="FieldTest__init_37609"; - "FieldTest__init_37609_142" [label="self.f1 = sender()"]; + subgraph "cluster_FieldTest__init_40687" { + label="FieldTest__init_40687"; + "FieldTest__init_40687_142" [label="self.f1 = sender()"]; } subgraph "cluster_FieldTest__use_f1" { label="FieldTest__use_f1"; diff --git a/test/contracts/never-accessed-2.cfg.json b/test/contracts/never-accessed-2.cfg.json index 067b58c6..adfa7486 100644 --- a/test/contracts/never-accessed-2.cfg.json +++ b/test/contracts/never-accessed-2.cfg.json @@ -6,12 +6,12 @@ "name": "FieldTest", "methods": [ { - "name": "FieldTest.init_35939", + "name": "FieldTest.init_39017", "cfg": { "nodes": [ { "id": 142, - "stmtID": 35930, + "stmtID": 39008, "srcEdges": [], "dstEdges": [] } @@ -25,7 +25,7 @@ "nodes": [ { "id": 143, - "stmtID": 35937, + "stmtID": 39015, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/never-accessed-3.cfg.dot b/test/contracts/never-accessed-3.cfg.dot index 381c212f..15fa81cf 100644 --- a/test/contracts/never-accessed-3.cfg.dot +++ b/test/contracts/never-accessed-3.cfg.dot @@ -1,7 +1,7 @@ digraph "never-accessed-3" { node [shape=box]; - subgraph "cluster_FieldTest__init_40925" { - label="FieldTest__init_40925"; - "FieldTest__init_40925_141" [label="self.f1 = sender()"]; + subgraph "cluster_FieldTest__init_44003" { + label="FieldTest__init_44003"; + "FieldTest__init_44003_141" [label="self.f1 = sender()"]; } } diff --git a/test/contracts/never-accessed-3.cfg.json b/test/contracts/never-accessed-3.cfg.json index cc1de1c5..a59d12d1 100644 --- a/test/contracts/never-accessed-3.cfg.json +++ b/test/contracts/never-accessed-3.cfg.json @@ -6,12 +6,12 @@ "name": "FieldTest", "methods": [ { - "name": "FieldTest.init_39267", + "name": "FieldTest.init_42345", "cfg": { "nodes": [ { "id": 141, - "stmtID": 39265, + "stmtID": 42343, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/never-accessed-4.cfg.json b/test/contracts/never-accessed-4.cfg.json index d9cdedcc..191e483a 100644 --- a/test/contracts/never-accessed-4.cfg.json +++ b/test/contracts/never-accessed-4.cfg.json @@ -11,7 +11,7 @@ "nodes": [ { "id": 141, - "stmtID": 42601, + "stmtID": 45679, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/readonly-1.cfg.json b/test/contracts/readonly-1.cfg.json index 370d6526..2235cd21 100644 --- a/test/contracts/readonly-1.cfg.json +++ b/test/contracts/readonly-1.cfg.json @@ -7,7 +7,7 @@ "nodes": [ { "id": 141, - "stmtID": 45935, + "stmtID": 49013, "srcEdges": [], "dstEdges": [ 143 @@ -15,7 +15,7 @@ }, { "id": 142, - "stmtID": 45939, + "stmtID": 49017, "srcEdges": [ 143 ], @@ -25,7 +25,7 @@ }, { "id": 144, - "stmtID": 45943, + "stmtID": 49021, "srcEdges": [ 145 ], @@ -35,7 +35,7 @@ }, { "id": 146, - "stmtID": 45950, + "stmtID": 49028, "srcEdges": [ 147 ], @@ -45,7 +45,7 @@ }, { "id": 148, - "stmtID": 45949, + "stmtID": 49027, "srcEdges": [ 149 ], @@ -55,7 +55,7 @@ }, { "id": 150, - "stmtID": 45952, + "stmtID": 49030, "srcEdges": [ 151 ], diff --git a/test/contracts/readonly-2.cfg.json b/test/contracts/readonly-2.cfg.json index f17e6ef0..efc16d56 100644 --- a/test/contracts/readonly-2.cfg.json +++ b/test/contracts/readonly-2.cfg.json @@ -7,7 +7,7 @@ "nodes": [ { "id": 141, - "stmtID": 49035, + "stmtID": 52113, "srcEdges": [], "dstEdges": [ 143 @@ -15,7 +15,7 @@ }, { "id": 142, - "stmtID": 49039, + "stmtID": 52117, "srcEdges": [ 143 ], @@ -25,7 +25,7 @@ }, { "id": 144, - "stmtID": 49041, + "stmtID": 52119, "srcEdges": [ 145 ], diff --git a/test/contracts/traits-1.cfg.json b/test/contracts/traits-1.cfg.json index d01a3e46..6aafbb1e 100644 --- a/test/contracts/traits-1.cfg.json +++ b/test/contracts/traits-1.cfg.json @@ -11,7 +11,7 @@ "nodes": [ { "id": 141, - "stmtID": 52120, + "stmtID": 55198, "srcEdges": [], "dstEdges": [] } diff --git a/test/contracts/unbound-loop-1.cfg.json b/test/contracts/unbound-loop-1.cfg.json index 8b4fba6f..dff36518 100644 --- a/test/contracts/unbound-loop-1.cfg.json +++ b/test/contracts/unbound-loop-1.cfg.json @@ -7,7 +7,7 @@ "nodes": [ { "id": 141, - "stmtID": 55687, + "stmtID": 58765, "srcEdges": [], "dstEdges": [ 143 @@ -15,7 +15,7 @@ }, { "id": 142, - "stmtID": 55691, + "stmtID": 58769, "srcEdges": [ 143, 144 @@ -27,7 +27,7 @@ }, { "id": 145, - "stmtID": 55693, + "stmtID": 58771, "srcEdges": [ 146 ], diff --git a/test/contracts/unbound-loop-2.cfg.json b/test/contracts/unbound-loop-2.cfg.json index 82f3e172..1cabeaad 100644 --- a/test/contracts/unbound-loop-2.cfg.json +++ b/test/contracts/unbound-loop-2.cfg.json @@ -7,7 +7,7 @@ "nodes": [ { "id": 141, - "stmtID": 58765, + "stmtID": 61843, "srcEdges": [], "dstEdges": [ 143 @@ -15,7 +15,7 @@ }, { "id": 142, - "stmtID": 58769, + "stmtID": 61847, "srcEdges": [ 143, 144 @@ -27,7 +27,7 @@ }, { "id": 145, - "stmtID": 58771, + "stmtID": 61849, "srcEdges": [ 146 ], diff --git a/test/contracts/unbound-loop-3.cfg.json b/test/contracts/unbound-loop-3.cfg.json index dbd4c361..2031e59b 100644 --- a/test/contracts/unbound-loop-3.cfg.json +++ b/test/contracts/unbound-loop-3.cfg.json @@ -7,7 +7,7 @@ "nodes": [ { "id": 141, - "stmtID": 61843, + "stmtID": 64921, "srcEdges": [], "dstEdges": [ 143 @@ -15,7 +15,7 @@ }, { "id": 142, - "stmtID": 61850, + "stmtID": 64928, "srcEdges": [ 143, 146 @@ -27,7 +27,7 @@ }, { "id": 144, - "stmtID": 61849, + "stmtID": 64927, "srcEdges": [ 145 ], @@ -37,7 +37,7 @@ }, { "id": 147, - "stmtID": 61852, + "stmtID": 64930, "srcEdges": [ 148 ], diff --git a/test/contracts/unbound-loop-4.cfg.json b/test/contracts/unbound-loop-4.cfg.json index 5fb7186b..8a8643aa 100644 --- a/test/contracts/unbound-loop-4.cfg.json +++ b/test/contracts/unbound-loop-4.cfg.json @@ -14,7 +14,7 @@ "nodes": [ { "id": 142, - "stmtID": 64932, + "stmtID": 68010, "srcEdges": [], "dstEdges": [ 144 @@ -22,7 +22,7 @@ }, { "id": 143, - "stmtID": 64940, + "stmtID": 68018, "srcEdges": [ 144, 147 @@ -34,7 +34,7 @@ }, { "id": 145, - "stmtID": 64939, + "stmtID": 68017, "srcEdges": [ 146 ], @@ -44,7 +44,7 @@ }, { "id": 148, - "stmtID": 64942, + "stmtID": 68020, "srcEdges": [ 149 ], diff --git a/test/contracts/zero-address.cfg.dot b/test/contracts/zero-address.cfg.dot index 7a3291db..39f47974 100644 --- a/test/contracts/zero-address.cfg.dot +++ b/test/contracts/zero-address.cfg.dot @@ -1,7 +1,7 @@ digraph "zero-address" { node [shape=box]; - subgraph "cluster_SampleContract__init_69679" { - label="SampleContract__init_69679"; - "SampleContract__init_69679_141" [label="newAddress(1, 0)"]; + subgraph "cluster_SampleContract__init_72757" { + label="SampleContract__init_72757"; + "SampleContract__init_72757_141" [label="newAddress(1, 0)"]; } } diff --git a/test/contracts/zero-address.cfg.json b/test/contracts/zero-address.cfg.json index fdbf4a1e..dfebe9ef 100644 --- a/test/contracts/zero-address.cfg.json +++ b/test/contracts/zero-address.cfg.json @@ -6,12 +6,12 @@ "name": "SampleContract", "methods": [ { - "name": "SampleContract.init_68025", + "name": "SampleContract.init_71103", "cfg": { "nodes": [ { "id": 141, - "stmtID": 68023, + "stmtID": 71101, "srcEdges": [], "dstEdges": [] }