Skip to content

Commit 1b2ff97

Browse files
committed
Add goto and label statement test coverage
1 parent 4f29f2f commit 1b2ff97

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed

tests/driver.sh

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,136 @@ int main() {
25592559
}
25602560
EOF
25612561

2562+
begin_category "Goto statements" "Testing goto and label statements"
2563+
2564+
# label undeclaration
2565+
try_compile_error << EOF
2566+
int main()
2567+
{
2568+
goto label;
2569+
}
2570+
EOF
2571+
2572+
# label redefinition
2573+
try_compile_error << EOF
2574+
int main()
2575+
{
2576+
goto label;
2577+
label:;
2578+
label:;
2579+
}
2580+
EOF
2581+
2582+
# test label namespace
2583+
try_ 1 << EOF
2584+
int main()
2585+
{
2586+
goto label;
2587+
label:;
2588+
int label = 1;
2589+
return label;
2590+
}
2591+
EOF
2592+
2593+
try_ 0 << EOF
2594+
int main() {
2595+
int x = 0;
2596+
goto skip;
2597+
x = 1;
2598+
skip:
2599+
return x; // Should return 0
2600+
}
2601+
EOF
2602+
2603+
# Forward reference
2604+
try_compile_error << EOF
2605+
int main()
2606+
{
2607+
goto end;
2608+
return 1;
2609+
end:
2610+
return 0;
2611+
}
2612+
EOF
2613+
2614+
# Simple loop
2615+
try_ 10 << EOF
2616+
int main()
2617+
{
2618+
int vars0;
2619+
2620+
vars0 = 0;
2621+
BB1:;
2622+
if (!(vars0 < 10)) goto BB6;
2623+
vars0++;
2624+
goto BB1;
2625+
BB6:;
2626+
return vars0;
2627+
}
2628+
EOF
2629+
2630+
# Complex loop
2631+
ans="0
2632+
0012345678910123456789201234567893012345678940123456789
2633+
1
2634+
0012345678910123456789201234567893012345678940123456789
2635+
3
2636+
0012345678910123456789201234567893012345678940123456789
2637+
4
2638+
0012345678910123456789201234567893012345678940123456789
2639+
5
2640+
0012345678910123456789201234567893012345678940123456789
2641+
6
2642+
0012345678910123456789201234567893012345678940123456789
2643+
7
2644+
0012345678910123456789201234567893012345678940123456789
2645+
8
2646+
0012345678910123456789201234567893012345678940123456789
2647+
9
2648+
0012345678910123456789201234567893012345678940123456789"
2649+
try_output 0 "$ans" << EOF
2650+
int main()
2651+
{
2652+
int vars0;
2653+
int vars1;
2654+
int vars2;
2655+
int vars3;
2656+
2657+
vars0 = 0;
2658+
BB1:;
2659+
if (!(vars0 < 10)) goto BB47;
2660+
if (vars0 == 2) goto BB45;
2661+
printf("%d\n", vars0);
2662+
vars1 = 0;
2663+
BB10:;
2664+
if (!(vars1 < 10)) goto BB27;
2665+
if (vars1 == 5) goto BB27;
2666+
printf("%d", vars1);
2667+
vars2 = 0;
2668+
BB19:;
2669+
if (!(vars2 < 10)) goto BB25;
2670+
printf("%d", vars2);
2671+
vars2++;
2672+
goto BB19;
2673+
BB25:;
2674+
vars1++;
2675+
goto BB10;
2676+
BB27:;
2677+
printf("\n");
2678+
vars3 = 5;
2679+
BB29:;
2680+
if (vars3 == 2) goto BB29;
2681+
if (vars3 == 3) goto BB45;
2682+
vars3--;
2683+
if (vars3 > 0) goto BB29;
2684+
BB45:;
2685+
vars0++;
2686+
goto BB1;
2687+
BB47:;
2688+
return 0;
2689+
}
2690+
EOF
2691+
25622692
# Category: Function-like Macros
25632693
begin_category "Function-like Macros" "Testing function-like macros and variadic macros"
25642694

0 commit comments

Comments
 (0)