source: src/tests/fallthrough.c@ e2c70ab

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since e2c70ab was e2c70ab, checked in by Rob Schluntz <rschlunt@…>, 8 years ago

Add fallthrough test cases

  • Property mode set to 100644
File size: 1.8 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2018 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// fallthrough.c --
8//
9// Author : Rob Schluntz
10// Created On : Wed Mar 14 10:06:25 2018
11// Last Modified By : Rob Schluntz
12// Last Modified On : Wed Mar 14 10:32:12 2018
13// Update Count : 2
14//
15
16void test(int choice) {
17 choose ( choice ) {
18 case 1:
19 printf("case 1\n");
20 fallthru;
21 case 2:
22 printf("case 2\n");
23 fallthru;
24 printf("did not fallthru\n");
25 if ( 7 ) fallthru common2;
26 fallthru common1;
27 case 3:
28 printf("case 3\n");
29 fallthru default;
30 fallthru common1;
31 common1:
32 printf("common1\n");
33 /* break */
34 case 4:
35 printf("case 4\n");
36 fallthru common2;
37 case 5:
38 printf("case 5\n");
39 fallthru common2;
40 fallthru default;
41 case 6:
42 printf("case 6\n");
43 fallthru common2;
44 common2:
45 printf("common2\n");
46 /* break */
47 default:
48 printf("default\n");
49 fallthru;
50 }
51
52#if ERR1
53 // ERROR: fallthrough must be enclosed in switch or choose
54 fallthru;
55 // ERROR: fallthrough must be enclosed in switch or choose
56 fallthru common4;
57 // ERROR: fallthrough must be enclosed in switch or choose
58 fallthru default;
59 choose ( 3 ) {
60 case 2:
61 for ( ;; ) {
62 choose ( 2 ) {
63 case 1:
64 // ERROR: default is later, but in a different switch
65 fallthru default;
66 // ERROR: common3 is later, but not at the same level as a case clause
67 fallthru common3;
68 }
69 common3: ;
70 }
71 default:
72 case 1:
73 common4:
74 // ERROR: attempt to jump up with fallthrough
75 if ( 7 ) fallthru common4;
76 // ERROR: attempt to jump up with fallthrough
77 fallthru default;
78 }
79#endif
80}
81
82int main() {
83 test(1);
84 test(5);
85}
86
87// Local Variables: //
88// tab-width: 4 //
89// compile-command: "cfa dtor-early-exit" //
90// End: //
Note: See TracBrowser for help on using the repository browser.