diff --git a/src/test/run-make/graphviz-flowgraph/Makefile b/src/test/run-make/graphviz-flowgraph/Makefile index fedcc89cd42..09440949177 100644 --- a/src/test/run-make/graphviz-flowgraph/Makefile +++ b/src/test/run-make/graphviz-flowgraph/Makefile @@ -2,7 +2,8 @@ FILES=f00.rs f01.rs f02.rs f03.rs f04.rs f05.rs f06.rs f07.rs \ f08.rs f09.rs f10.rs f11.rs f12.rs f13.rs f14.rs f15.rs \ - f16.rs f17.rs f18.rs f19.rs f20.rs f21.rs f22.rs + f16.rs f17.rs f18.rs f19.rs f20.rs f21.rs f22.rs f23.rs \ + f24.rs f25.rs # all: $(patsubst %.rs,$(TMPDIR)/%.dot,$(FILES)) $(patsubst %.rs,$(TMPDIR)/%.pp,$(FILES)) diff --git a/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot new file mode 100644 index 00000000000..876957a0689 --- /dev/null +++ b/src/test/run-make/graphviz-flowgraph/f23.dot-expected.dot @@ -0,0 +1,93 @@ +digraph block { + N0[label="entry"]; + N1[label="exit"]; + N2[label="expr 23"]; + N3[label="local mut x"]; + N4[label="expr 23"]; + N5[label="local mut y"]; + N6[label="expr 23"]; + N7[label="local mut z"]; + N8[label="(dummy_node)"]; + N9[label="expr x"]; + N10[label="expr 0"]; + N11[label="expr x > 0"]; + N12[label="expr while x > 0 {\l x -= 1;\l while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N13[label="expr 1"]; + N14[label="expr x"]; + N15[label="expr x -= 1"]; + N16[label="(dummy_node)"]; + N17[label="expr y"]; + N18[label="expr 0"]; + N19[label="expr y > 0"]; + N20[label="expr while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l"]; + N21[label="expr 1"]; + N22[label="expr y"]; + N23[label="expr y -= 1"]; + N24[label="(dummy_node)"]; + N25[label="expr z"]; + N26[label="expr 0"]; + N27[label="expr z > 0"]; + N28[label="expr while z > 0 { z -= 1; }"]; + N29[label="expr 1"]; + N30[label="expr z"]; + N31[label="expr z -= 1"]; + N32[label="block { z -= 1; }"]; + N33[label="expr x"]; + N34[label="expr 10"]; + N35[label="expr x > 10"]; + N36[label="expr return"]; + N37[label="(dummy_node)"]; + N38[label="expr \"unreachable\""]; + N39[label="block { return; \"unreachable\"; }"]; + N40[label="expr if x > 10 { return; \"unreachable\"; }"]; + N41[label="block { y -= 1; while z > 0 { z -= 1; } if x > 10 { return; \"unreachable\"; } }"]; + N42[label="block {\l x -= 1;\l while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N43[label="block {\l let mut x = 23;\l let mut y = 23;\l let mut z = 23;\l while x > 0 {\l x -= 1;\l while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l }\l}\l"]; + N0 -> N2; + N2 -> N3; + N3 -> N4; + N4 -> N5; + N5 -> N6; + N6 -> N7; + N7 -> N8; + N8 -> N9; + N9 -> N10; + N10 -> N11; + N11 -> N12; + N11 -> N13; + N13 -> N14; + N14 -> N15; + N15 -> N16; + N16 -> N17; + N17 -> N18; + N18 -> N19; + N19 -> N20; + N19 -> N21; + N21 -> N22; + N22 -> N23; + N23 -> N24; + N24 -> N25; + N25 -> N26; + N26 -> N27; + N27 -> N28; + N27 -> N29; + N29 -> N30; + N30 -> N31; + N31 -> N32; + N32 -> N24; + N28 -> N33; + N33 -> N34; + N34 -> N35; + N35 -> N36; + N36 -> N1[label="exiting scope_0 expr while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l,\lexiting scope_1 expr while x > 0 {\l x -= 1;\l while y > 0 {\l y -= 1;\l while z > 0 { z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N37 -> N38; + N38 -> N39; + N35 -> N40; + N39 -> N40; + N40 -> N41; + N41 -> N16; + N20 -> N42; + N42 -> N8; + N12 -> N43; + N43 -> N1; +} diff --git a/src/test/run-make/graphviz-flowgraph/f23.rs b/src/test/run-make/graphviz-flowgraph/f23.rs new file mode 100644 index 00000000000..52341a3fbd4 --- /dev/null +++ b/src/test/run-make/graphviz-flowgraph/f23.rs @@ -0,0 +1,31 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[allow(unreachable_code)] +pub fn expr_while_23() { + let mut x = 23; + let mut y = 23; + let mut z = 23; + + while x > 0 { + x -= 1; + + while y > 0 { + y -= 1; + + while z > 0 { z -= 1; } + + if x > 10 { + return; + "unreachable"; + } + } + } +} diff --git a/src/test/run-make/graphviz-flowgraph/f24.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f24.dot-expected.dot new file mode 100644 index 00000000000..2558998be6e --- /dev/null +++ b/src/test/run-make/graphviz-flowgraph/f24.dot-expected.dot @@ -0,0 +1,123 @@ +digraph block { + N0[label="entry"]; + N1[label="exit"]; + N2[label="expr 24"]; + N3[label="local mut x"]; + N4[label="expr 24"]; + N5[label="local mut y"]; + N6[label="expr 24"]; + N7[label="local mut z"]; + N8[label="(dummy_node)"]; + N9[label="expr loop {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N10[label="expr x"]; + N11[label="expr 0"]; + N12[label="expr x == 0"]; + N13[label="expr break"]; + N14[label="(dummy_node)"]; + N15[label="expr \"unreachable\""]; + N16[label="block { break ; \"unreachable\"; }"]; + N17[label="expr if x == 0 { break ; \"unreachable\"; }"]; + N18[label="expr 1"]; + N19[label="expr x"]; + N20[label="expr x -= 1"]; + N21[label="(dummy_node)"]; + N22[label="expr loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l"]; + N23[label="expr y"]; + N24[label="expr 0"]; + N25[label="expr y == 0"]; + N26[label="expr break"]; + N27[label="(dummy_node)"]; + N28[label="expr \"unreachable\""]; + N29[label="block { break ; \"unreachable\"; }"]; + N30[label="expr if y == 0 { break ; \"unreachable\"; }"]; + N31[label="expr 1"]; + N32[label="expr y"]; + N33[label="expr y -= 1"]; + N34[label="(dummy_node)"]; + N35[label="expr loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }"]; + N36[label="expr z"]; + N37[label="expr 0"]; + N38[label="expr z == 0"]; + N39[label="expr break"]; + N40[label="(dummy_node)"]; + N41[label="expr \"unreachable\""]; + N42[label="block { break ; \"unreachable\"; }"]; + N43[label="expr if z == 0 { break ; \"unreachable\"; }"]; + N44[label="expr 1"]; + N45[label="expr z"]; + N46[label="expr z -= 1"]; + N47[label="block { if z == 0 { break ; \"unreachable\"; } z -= 1; }"]; + N48[label="expr x"]; + N49[label="expr 10"]; + N50[label="expr x > 10"]; + N51[label="expr return"]; + N52[label="(dummy_node)"]; + N53[label="expr \"unreachable\""]; + N54[label="block { return; \"unreachable\"; }"]; + N55[label="expr if x > 10 { return; \"unreachable\"; }"]; + N56[label="block {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l"]; + N57[label="block {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N58[label="block {\l let mut x = 24;\l let mut y = 24;\l let mut z = 24;\l loop {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l }\l}\l"]; + N0 -> N2; + N2 -> N3; + N3 -> N4; + N4 -> N5; + N5 -> N6; + N6 -> N7; + N7 -> N8; + N8 -> N10; + N10 -> N11; + N11 -> N12; + N12 -> N13; + N13 -> N9[label="exiting scope_0 expr break,\lexiting scope_1 stmt break ;,\lexiting scope_2 block { break ; \"unreachable\"; },\lexiting scope_3 expr if x == 0 { break ; \"unreachable\"; },\lexiting scope_4 stmt if x == 0 { break ; \"unreachable\"; },\lexiting scope_5 block {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N14 -> N15; + N15 -> N16; + N12 -> N17; + N16 -> N17; + N17 -> N18; + N18 -> N19; + N19 -> N20; + N20 -> N21; + N21 -> N23; + N23 -> N24; + N24 -> N25; + N25 -> N26; + N26 -> N22[label="exiting scope_0 expr break,\lexiting scope_1 stmt break ;,\lexiting scope_2 block { break ; \"unreachable\"; },\lexiting scope_3 expr if y == 0 { break ; \"unreachable\"; },\lexiting scope_4 stmt if y == 0 { break ; \"unreachable\"; },\lexiting scope_5 block {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l"]; + N27 -> N28; + N28 -> N29; + N25 -> N30; + N29 -> N30; + N30 -> N31; + N31 -> N32; + N32 -> N33; + N33 -> N34; + N34 -> N36; + N36 -> N37; + N37 -> N38; + N38 -> N39; + N39 -> N35[label="exiting scope_0 expr break,\lexiting scope_1 stmt break ;,\lexiting scope_2 block { break ; \"unreachable\"; },\lexiting scope_3 expr if z == 0 { break ; \"unreachable\"; },\lexiting scope_4 stmt if z == 0 { break ; \"unreachable\"; },\lexiting scope_5 block { if z == 0 { break ; \"unreachable\"; } z -= 1; }"]; + N40 -> N41; + N41 -> N42; + N38 -> N43; + N42 -> N43; + N43 -> N44; + N44 -> N45; + N45 -> N46; + N46 -> N47; + N47 -> N34; + N35 -> N48; + N48 -> N49; + N49 -> N50; + N50 -> N51; + N51 -> N1[label="exiting scope_0 expr loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l}\l,\lexiting scope_1 expr loop {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { return; \"unreachable\"; }\l }\l}\l"]; + N52 -> N53; + N53 -> N54; + N50 -> N55; + N54 -> N55; + N55 -> N56; + N56 -> N21; + N22 -> N57; + N57 -> N8; + N9 -> N58; + N58 -> N1; +} diff --git a/src/test/run-make/graphviz-flowgraph/f24.rs b/src/test/run-make/graphviz-flowgraph/f24.rs new file mode 100644 index 00000000000..f796d660a18 --- /dev/null +++ b/src/test/run-make/graphviz-flowgraph/f24.rs @@ -0,0 +1,36 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[allow(unreachable_code)] +pub fn expr_while_24() { + let mut x = 24; + let mut y = 24; + let mut z = 24; + + loop { + if x == 0 { break; "unreachable"; } + x -= 1; + + loop { + if y == 0 { break; "unreachable"; } + y -= 1; + + loop { + if z == 0 { break; "unreachable"; } + z -= 1; + } + + if x > 10 { + return; + "unreachable"; + } + } + } +} diff --git a/src/test/run-make/graphviz-flowgraph/f25.dot-expected.dot b/src/test/run-make/graphviz-flowgraph/f25.dot-expected.dot new file mode 100644 index 00000000000..c393b63546c --- /dev/null +++ b/src/test/run-make/graphviz-flowgraph/f25.dot-expected.dot @@ -0,0 +1,123 @@ +digraph block { + N0[label="entry"]; + N1[label="exit"]; + N2[label="expr 25"]; + N3[label="local mut x"]; + N4[label="expr 25"]; + N5[label="local mut y"]; + N6[label="expr 25"]; + N7[label="local mut z"]; + N8[label="(dummy_node)"]; + N9[label="expr \'a:\l loop {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l \'a:\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l }\l }\l"]; + N10[label="expr x"]; + N11[label="expr 0"]; + N12[label="expr x == 0"]; + N13[label="expr break"]; + N14[label="(dummy_node)"]; + N15[label="expr \"unreachable\""]; + N16[label="block { break ; \"unreachable\"; }"]; + N17[label="expr if x == 0 { break ; \"unreachable\"; }"]; + N18[label="expr 1"]; + N19[label="expr x"]; + N20[label="expr x -= 1"]; + N21[label="(dummy_node)"]; + N22[label="expr \'a:\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l }\l"]; + N23[label="expr y"]; + N24[label="expr 0"]; + N25[label="expr y == 0"]; + N26[label="expr break"]; + N27[label="(dummy_node)"]; + N28[label="expr \"unreachable\""]; + N29[label="block { break ; \"unreachable\"; }"]; + N30[label="expr if y == 0 { break ; \"unreachable\"; }"]; + N31[label="expr 1"]; + N32[label="expr y"]; + N33[label="expr y -= 1"]; + N34[label="(dummy_node)"]; + N35[label="expr \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }"]; + N36[label="expr z"]; + N37[label="expr 0"]; + N38[label="expr z == 0"]; + N39[label="expr break"]; + N40[label="(dummy_node)"]; + N41[label="expr \"unreachable\""]; + N42[label="block { break ; \"unreachable\"; }"]; + N43[label="expr if z == 0 { break ; \"unreachable\"; }"]; + N44[label="expr 1"]; + N45[label="expr z"]; + N46[label="expr z -= 1"]; + N47[label="block { if z == 0 { break ; \"unreachable\"; } z -= 1; }"]; + N48[label="expr x"]; + N49[label="expr 10"]; + N50[label="expr x > 10"]; + N51[label="expr continue \'a"]; + N52[label="(dummy_node)"]; + N53[label="expr \"unreachable\""]; + N54[label="block { continue \'a ; \"unreachable\"; }"]; + N55[label="expr if x > 10 { continue \'a ; \"unreachable\"; }"]; + N56[label="block {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l}\l"]; + N57[label="block {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l \'a:\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l }\l}\l"]; + N58[label="block {\l let mut x = 25;\l let mut y = 25;\l let mut z = 25;\l \'a:\l loop {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l \'a:\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l }\l }\l}\l"]; + N0 -> N2; + N2 -> N3; + N3 -> N4; + N4 -> N5; + N5 -> N6; + N6 -> N7; + N7 -> N8; + N8 -> N10; + N10 -> N11; + N11 -> N12; + N12 -> N13; + N13 -> N9[label="exiting scope_0 expr break,\lexiting scope_1 stmt break ;,\lexiting scope_2 block { break ; \"unreachable\"; },\lexiting scope_3 expr if x == 0 { break ; \"unreachable\"; },\lexiting scope_4 stmt if x == 0 { break ; \"unreachable\"; },\lexiting scope_5 block {\l if x == 0 { break ; \"unreachable\"; }\l x -= 1;\l \'a:\l loop {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l }\l}\l"]; + N14 -> N15; + N15 -> N16; + N12 -> N17; + N16 -> N17; + N17 -> N18; + N18 -> N19; + N19 -> N20; + N20 -> N21; + N21 -> N23; + N23 -> N24; + N24 -> N25; + N25 -> N26; + N26 -> N22[label="exiting scope_0 expr break,\lexiting scope_1 stmt break ;,\lexiting scope_2 block { break ; \"unreachable\"; },\lexiting scope_3 expr if y == 0 { break ; \"unreachable\"; },\lexiting scope_4 stmt if y == 0 { break ; \"unreachable\"; },\lexiting scope_5 block {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l}\l"]; + N27 -> N28; + N28 -> N29; + N25 -> N30; + N29 -> N30; + N30 -> N31; + N31 -> N32; + N32 -> N33; + N33 -> N34; + N34 -> N36; + N36 -> N37; + N37 -> N38; + N38 -> N39; + N39 -> N35[label="exiting scope_0 expr break,\lexiting scope_1 stmt break ;,\lexiting scope_2 block { break ; \"unreachable\"; },\lexiting scope_3 expr if z == 0 { break ; \"unreachable\"; },\lexiting scope_4 stmt if z == 0 { break ; \"unreachable\"; },\lexiting scope_5 block { if z == 0 { break ; \"unreachable\"; } z -= 1; }"]; + N40 -> N41; + N41 -> N42; + N38 -> N43; + N42 -> N43; + N43 -> N44; + N44 -> N45; + N45 -> N46; + N46 -> N47; + N47 -> N34; + N35 -> N48; + N48 -> N49; + N49 -> N50; + N50 -> N51; + N51 -> N21[label="exiting scope_0 expr continue \'a,\lexiting scope_1 stmt continue \'a ;,\lexiting scope_2 block { continue \'a ; \"unreachable\"; },\lexiting scope_3 expr if x > 10 { continue \'a ; \"unreachable\"; },\lexiting scope_4 block {\l if y == 0 { break ; \"unreachable\"; }\l y -= 1;\l \'a: loop { if z == 0 { break ; \"unreachable\"; } z -= 1; }\l if x > 10 { continue \'a ; \"unreachable\"; }\l}\l"]; + N52 -> N53; + N53 -> N54; + N50 -> N55; + N54 -> N55; + N55 -> N56; + N56 -> N21; + N22 -> N57; + N57 -> N8; + N9 -> N58; + N58 -> N1; +} diff --git a/src/test/run-make/graphviz-flowgraph/f25.rs b/src/test/run-make/graphviz-flowgraph/f25.rs new file mode 100644 index 00000000000..2ee2e48fd10 --- /dev/null +++ b/src/test/run-make/graphviz-flowgraph/f25.rs @@ -0,0 +1,36 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[allow(unreachable_code)] +pub fn expr_while_25() { + let mut x = 25; + let mut y = 25; + let mut z = 25; + + 'a: loop { + if x == 0 { break; "unreachable"; } + x -= 1; + + 'a: loop { + if y == 0 { break; "unreachable"; } + y -= 1; + + 'a: loop { + if z == 0 { break; "unreachable"; } + z -= 1; + } + + if x > 10 { + continue 'a; + "unreachable"; + } + } + } +}