本文主要是介绍红薯nbsp;57nbsp;个让nbsp;Cnbsp;编译器崩溃的代码,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我不清楚你是否很高兴看到你的程序会让编译器崩溃的情况,反正我很喜欢,相当于发现了编译器的 bug。
本文列出 57 段代码以及相应的编译器版本和编译参数,在这个环境下对代码进行编译会导致编译器崩溃。
1 : Crashes Clang 2.6 at -O0:
01 | #pragma pack(1) |
02 | struct S1 { |
03 | int f0; |
04 | char f2 |
05 | }; |
06 | struct { |
07 | struct S1 f0 |
08 | } |
09 | a[] = { 0 } |
10 | ; |
C2 : Crashes Clang 2.6 at -O2:
01 | struct S0 { |
02 | int f0:1; |
03 | int f4 |
04 | } |
05 | a; |
06 | void |
07 | fn1 () { |
08 | struct S0 b[][1][1] = { 0 }; |
09 | b[0][0][0] = a; |
10 | } |
C3 : Crashes Clang 2.6 at -O2:
01 | unsigned short a; |
02 | int b; |
03 | char c; |
04 | short |
05 | fn1 () { |
06 | return 1 / a; |
07 | } |
08 | void |
09 | fn2 () { |
10 | b = fn1 (); |
11 | char d = b; |
12 | c = d % 3; |
13 | } |
C4 : Crashes Clang 2.6 at -O3:
01 | int a, b, c, d, e; |
02 | #pragma pack(1) |
03 | struct S0 { |
04 | int f0:14; |
05 | int f1:13; |
06 | int f2:28; |
07 | int f3:23; |
08 | int f4:12 |
09 | }; |
10 | void fn1 ( struct S0); |
11 | void |
12 | fn2 () { |
13 | int f; |
14 | lbl_2311: |
15 | ; |
16 | struct S0 g = { 0, 0, 1 }; |
17 | fn1 (g); |
18 | b && e; |
19 | for (; c;) { |
20 | if (d) |
21 | goto lbl_2311; |
22 | f = a && 1 ? 0 : 1; |
23 | g.f4 = f; |
24 | } |
25 | } |
C5 : Crashes Clang 2.6 at -O2:
01 | int crc32_context, g_2 = 0, g_5; |
02 | int g_8; |
03 | int *g_39, *g_371; |
04 | int g_81; |
05 | int func_1_l_15 ; |
06 | static short safe_add_func_int16_t_s_s ( short si1, int si2 ) { |
07 | return si1 > 67 ? si1 : si1 + si2; |
08 | } |
09 | |
10 | static int func_1 ( |
11 | int l_462 = 0; |
12 | g_2 = 0; |
13 | for ( ; |
14 | g_2 < 12; |
15 | g_2 = safe_add_func_int16_t_s_s ( g_2, 5 ) ) |
16 | g_5 = 1; |
17 | for ( ; |
18 | g_5; |
19 | ++g_5 ) |
20 | g_8 = 1; |
21 | for ( ; |
22 | g_8 >= 0; |
23 | g_8 = g_8 - 1 ) |
24 | func_1_l_15 = 1; |
25 | for ( ; |
26 | func_1_l_15; |
27 | func_1_l_15 = if ( g_8 ) break ; |
28 | } |
29 | g_371 = &l_462; |
30 | int *l_128 = &g_81; |
31 | *l_128 = *g_39; |
32 | } |
33 | *g_371 = |
34 | } |
35 | return 0; |
36 | } |
37 | int main ( |
38 | func_1 ( |
39 | crc32_context = g_2; |
40 | crc32_context += g_5; |
41 | } |
C6 : Crashes Clang 2.6 at -O0:
01 | #pragma pack(1) |
02 | struct S2 { |
03 | int f1; |
04 | short f4 |
05 | }; |
06 | struct S3 { |
07 | struct S2 f1; |
08 | int f3:14 |
09 | }; |
10 | struct { |
11 | struct S3 f3 |
12 | } |
13 | a = { 0, 0, 0 }; |
C7 : Crashes Clang 2.6 at -O1:
01 | int *a; |
02 | static int **b; |
03 | int c, d, e; |
04 | void |
05 | fn1 () { |
06 | d = &b == c; |
07 | for (;;) { |
08 | int **f = &a; |
09 | if (e) { |
10 | } else |
11 | b = f; |
12 | if (**b) |
13 | continue ; |
14 | **f; |
15 | } |
16 | } |
C8 : Crashes Clang 2.6 at -O1:
01 | #pragma pack(1) |
02 | struct S0 { |
03 | int f3; |
04 | char f4 |
05 | }; |
06 | struct { |
07 | struct S0 f6; |
08 | int f8 |
09 | } |
10 | a = { 0, 0, 0 }; |
C9 : Crashes Clang 2.6 at -O2:
01 | struct S0 { |
02 | int f0; |
03 | int f1; |
04 | short f3; |
05 | int f7; |
06 | int f8 |
07 | } |
08 | b; |
09 | int a, c, d, e, f; |
10 | void |
11 | fn1 ( struct S0 p1) { |
12 | d++; |
13 | c = p1.f8; |
14 | e = 0; |
15 | a = p1.f7; |
16 | } |
17 | void |
18 | fn2 () { |
19 | e = 0; |
20 | for (; e; e++) { |
21 | if (d) |
22 | for (;;) { |
23 | } |
24 | --f; |
25 | } |
26 | fn1 (b); |
27 | } |
C10 : Crashes Clang 2.6 at -O1:
01 | union U2 { |
02 | int f0; |
03 | unsigned short f2 |
04 | } |
05 | b; |
06 | static int a = 1; |
07 | void |
08 | fn1 ( int p1, unsigned short p2) { |
09 | } |
10 | int fn2 ( union U2); |
11 | union U2 fn3 (); |
12 | static unsigned long long |
13 | fn5 () { |
14 | fn1 (b.f2, b.f0); |
15 | return 0; |
16 | } |
17 | static char |
18 | fn4 () { |
19 | fn5 (); |
20 | return 0; |
21 | } |
22 | int |
23 | main () { |
24 | a || fn2 (fn3 (fn4 () ) ); |
25 | } |
C11 : Crashes Clang 2.7 at -O1:
01 | int *a; |
02 | static int **b; |
03 | int c, d, e; |
04 | void |
05 | fn1 () { |
06 | d = &b == c; |
07 | for (;;) { |
08 | int **f = &a; |
09 | if (e) { |
10 | } else |
11 | b = f; |
12 | if (**b) |
13 | continue ; |
14 | **f; |
15 | } |
16 | } |
C12 : Crashes Clang 2.7 at -O0:
1 | char a; |
2 | unsigned char b; |
3 | int c; |
4 | void |
5 | fn1 () { |
6 | (b ^= c) != a; |
7 | } |
C13 : Crashes Clang 2.7 at -O2:
1 | int a, b; |
2 | void fn1 (); |
3 | void |
4 | fn2 ( short p1) { |
5 | short c; |
6 | c = (65532 | 3) + p1; |
7 | fn1 (c && 1); |
8 | b = (0 == p1) * a; |
9 | } |
C14 : Crashes GCC 3.2.0 at -O1:
1 | void |
2 | fn1 () { |
3 | struct S0 *a; |
4 | struct S0 *b, *c = &a; |
5 | struct S0 **d = &c; |
6 | if (&b == &a) { |
7 | } |
8 | } |
C15 : Crashes GCC 3.2.0 at -O3:
01 | volatile int a, b, c, i; |
02 | char d; |
03 | void |
04 | fn1 () { |
05 | int e; |
06 | { |
07 | for (;; c++) { |
08 | int f[50] = { }; |
09 | if (b) { |
10 | { |
11 | 0; |
12 | { |
13 | { |
14 | int g = a, h = d; |
15 | e = h ? g : g / 0; |
16 | } |
17 | } |
18 | a = e; |
19 | } |
20 | } |
21 | } |
22 | } |
23 | } |
24 | void |
25 | main () { |
26 | i = 0 / 0; |
27 | a; |
28 | } |
C16 : Crashes GCC 3.2.0 at -O3:
01 | int a, c; |
02 | volatile int b; |
03 | void |
04 | fn1 () { |
05 | b; |
06 | for (;;) |
07 | break ; |
08 | int d = b, e = a; |
09 | c = a ? d : d % 0; |
10 | } |
11 | void |
12 | fn2 () { |
13 | if (0 % 0) |
14 | b; |
15 | } |
C17 : Crashes GCC 3.2.0 at -O2:
01 | union U1 { |
02 | int f0; |
03 | char f1 |
04 | }; |
05 | void |
06 | fn1 ( union U1 p1) { |
07 | p1.f1 = 0; |
08 | for (; p1.f1;) { |
09 | } |
10 | } |
C18 : Crashes GCC 3.2.0 at -O1:
1 | int a, b; |
2 | void |
3 | fn1 () { |
4 | b = 4294967290UL <= a | b; |
5 | } |
C19 : Crashes GCC 3.2.0 at -O3:
01 | int a, b, c; |
02 | int |
03 | fn1 ( int p1, int p2) { |
04 | return p1 - p2; |
05 | } |
06 | void |
07 | fn2 () { |
08 | int d; |
09 | int **e; |
10 | int ***f = &e; |
11 | d = a && b ? a : a % 0; |
12 | if (fn1 (f == 0, 2) ) |
13 | c = ***f; |
14 | } |
C20 : Crashes GCC 3.3.0 at -O3:
01 | int a, b, d; |
02 | struct S0 { |
03 | int f3 |
04 | }; |
05 | int * volatile c; |
06 | void fn1 ( struct S0); |
07 | void |
08 | fn2 () { |
09 | int e; |
10 | struct S0 **f; |
11 | struct S0 ***g = &f; |
12 | (a && b && b ? 0 : b) > (&c && 0); |
13 | e = 0 == g; |
14 | d = e >> 1; |
15 | for (;;) |
16 | fn1 (***g); |
17 | } |
C21 : Crashes GCC 3.4.0 at -O3:
01 | int a, b; |
02 | struct U0 { |
03 | char f0; |
04 | int f2 |
05 | }; |
06 | void |
07 | fn1 () { |
08 | struct U0 c; |
09 | for (; c.f0 != 1; c.f0 = c.f0 + a) |
10 | b -= 1; |
11 | } |
C22 : Crashes GCC 3.4.0 at -O3:
01 | int a, b, d, e; |
02 | struct S0 { |
03 | int f3 |
04 | }; |
05 | int *c; |
06 | void fn1 ( struct S0); |
07 | void |
08 | fn2 () { |
09 | struct S0 **f; |
10 | struct S0 ***g = &f; |
11 | (a && b && b ? 0 : b) > (&c == d); |
12 | e = 1 < (0 == g); |
13 | for (;;) |
14 | fn1 (***g); |
15 | } |
C23 : Crashes GCC 4.0.0 at -O2:
1 | int ***a; |
2 | int b; |
3 | int *c; |
4 | void |
5 | main () { |
6 | if (&c == a) |
7 | b = 0 == *a; |
8 | } |
C24 : Crashes GCC 4.0.0 at -O2:
1 | int a[][0]; |
2 | int * const b = &a[0][1]; |
3 | int |
4 | fn1 () { |
5 | return *b; |
6 | } |
C25 : Crashes GCC 4.0.0 at -O0:
1 | int a, b; |
2 | unsigned char c; |
3 | void |
4 | fn1 () { |
5 | (0 >= a & (0 || b) ) > c; |
6 | } |
C26 : Crashes GCC 4.0.0 at -O1:
01 | struct { |
02 | int f9:1 |
03 | } |
04 | a; |
05 | const int b[] = { 0 }; |
06 | void fn1 (); |
07 | void |
08 | main () { |
09 | for (;;) { |
10 | a.f9 = b[0]; |
11 | fn1 (); |
12 | } |
13 | } |
C27 : Crashes GCC 4.0.0 at -O0:
1 | int a, c; |
2 | unsigned char b; |
3 | void |
4 | fn1 () { |
5 | b > (c > 0 & 0 < a); |
6 | } |
C28 : Crashes GCC 4.0.0 at -O2:
01 | int **a[][0]; |
02 | static int *** const b = &a[0][1]; |
03 | void fn1 (); |
04 | int |
05 | fn2 () { |
06 | return ***b; |
07 | fn1 (); |
08 | } |
09 | void |
10 | fn1 () { |
11 | **b; |
12 | } |
C29 : Crashes GCC 4.1.0 at -O1:
1 | volatile int ***a; |
2 | int b; |
3 | int **c; |
4 | void |
5 | fn1 () { |
6 | if (&c == a) |
7 | b = 0 == *a; |
8 | } |
C30 : Crashes GCC 4.1.0 at -O1:
01 | struct { |
02 | int f0; |
03 | int f2 |
04 | } |
05 | a; |
06 | int b; |
07 | void |
08 | fn1 () { |
09 | a.f2 = 0; |
10 | int *c[] = { 0, 0, 0, 0, &a.f0, 0, 0, 0, &a.f0 }; |
11 | b = *c[4]; |
12 | } |
C31 : Crashes GCC 4.1.0 at -O2:
1 | int a, b; |
2 | unsigned c; |
3 | void |
4 | fn1 () { |
5 | for (; c <= 0;) |
6 | if (b < c) |
7 | a = 1 && c; |
8 | } |
C32 : Crashes GCC 4.1.0 at -O1:
1 | unsigned a; |
2 | int b; |
3 | void |
4 | main () { |
5 | unsigned c = 4294967295; |
6 | int d = c; |
7 | b = a <= d || a; |
8 | } |
C33 : Crashes GCC 4.1.0 at -O1:
1 | const volatile long a; |
2 | void |
3 | main () { |
4 | printf ( "%d\n" , ( int ) a); |
5 | } |
C34 : Crashes GCC 4.1.0 at -O3:
01 | int a, b; |
02 | union U1 { |
03 | int f0; |
04 | int f1 |
05 | }; |
06 | void |
07 | fn1 () { |
08 | union U1 c = { 1 }; |
09 | int d = 1; |
10 | if ( (c.f1 & a ? c.f1 : 1 - a) ^ d) { |
11 | } else |
12 | b = 0; |
13 | } |
C35 : Crashes GCC 4.2.0 at -O1:
1 | volatile int ***a; |
2 | int b; |
3 | int **c; |
4 | void |
5 | fn1 () { |
6 | if (&c == a) |
7 | b = 0 == *a; |
8 | } |
C36 : Crashes GCC 4.2.0 at -O1:
1 | struct S2 { |
2 | volatile int f5:1; |
3 | int f6 |
4 | }; |
5 | static struct S2 a; |
6 | void |
7 | main () { |
8 | printf ( "%d\n" , a.f5); |
9 | } |
C37 : Crashes GCC 4.3.0 at -O1:
01 | long long *a; |
02 | int b; |
03 | void |
04 | fn1 () { |
05 | long long **c = &a; |
06 | int d = 7; |
07 | lbl_2890: { |
08 | long long **e = &a; |
09 | b = (e == c) < d; |
10 | d = 0; |
11 | goto lbl_2890; |
12 | } |
13 | } |
C38 : Crashes GCC 4.3.0 at -O2:
1 | struct S2 { |
2 | volatile int f5:1; |
3 | int f6 |
4 | }; |
5 | static struct S2 a; |
6 | void |
7 | main () { |
8 | printf ( "%d\n" , a.f5); |
9 | } |
C39 : Crashes GCC 4.3.0 at -O3:
01 | int a; |
02 | short b; |
03 | void |
04 | fn1 () { |
05 | int c[0]; |
06 | for (;;) { |
07 | a = c[0]; |
08 | b = 0; |
09 | for (; b < 7; b += 1) |
10 | c[b] = 0; |
11 | } |
12 | } |
C40 : Crashes GCC 4.3.0 at -O1:
1 | volatile int **a; |
2 | int *b; |
3 | void |
4 | fn1 () { |
5 | if (a == &b) |
6 | **a; |
7 | } |
C41 : Crashes GCC 4.3.0 at -O3:
01 | int a, b, c, d, e, f; |
02 | void |
03 | fn1 () { |
04 | char g; |
05 | lbl_120: |
06 | if (b || e >= 0 & d >= 0 || a) |
07 | return ; |
08 | g = f < 0 ? 1 : f; |
09 | d = g == 0 || ( char ) f == 0 && g == 1 ? 0 : 0 % 0; |
10 | if (c) |
11 | goto lbl_120; |
12 | } |
C42 : Crashes Intel CC 12.0.5 at -O1:
01 | struct U0 { |
02 | int f0 |
03 | } |
04 | a; |
05 | struct U0 |
06 | fn1 () { |
07 | return a; |
08 | } |
09 | void |
10 | main () { |
11 | 0 > a.f0; |
12 | fn1 (); |
13 | } |
C43 : Crashes Open64 4.2.4 at -O3:
01 | int a; |
02 | int *b; |
03 | unsigned c; |
04 | void |
05 | fn1 () { |
06 | for (; a; a--) |
07 | if (*b) { |
08 | c = 0; |
09 | for (; c >= 5; c++) { |
10 | } |
11 | } |
12 | } |
C44 : Crashes Open64 4.2.4 at -O3:
1 | short a; |
2 | void |
3 | fn1 () { |
4 | long b; |
5 | b = 44067713550; |
6 | a |= b; |
7 | } |
C45 : Crashes Open64 4.2.4 at -O3:
1 | volatile int a; |
2 | void |
3 | fn1 () { |
4 | int b = 1; |
5 | a || b--; |
6 | } |
C46 : Crashes Open64 4.2.4 at -O2:
01 | int a, b; |
02 | void fn1 (); |
03 | void fn2 (); |
04 | void |
05 | fn3 () { |
06 | fn2 (); |
07 | fn1 (); |
08 | } |
09 | void |
10 | fn2 () { |
11 | if (1) { |
12 | } else |
13 | for (;; b++) { |
14 | int c = 0; |
15 | int *d = &a; |
16 | int **e = &d; |
17 | *e = &c; |
18 | *d = 0; |
19 | *d |= 0; |
20 | } |
21 | } |
C47 : Crashes Open64 4.2.4 at -O3:
01 | struct S0 { |
02 | int f1:1 |
03 | }; |
04 | int a, b; |
05 | void |
06 | fn1 () { |
07 | for (; b;) { |
08 | struct S0 c = { }; |
09 | if (1) { |
10 | c = c; |
11 | a = c.f1; |
12 | } |
13 | } |
14 | } |
C48 : Crashes Open64 4.2.4 at -O3:
01 | int a, b; |
02 | int |
03 | fn1 () { |
04 | int *c = &b; |
05 | a = 0; |
06 | for (; a >= -26; --a) { |
07 | unsigned d = 18446744073709551615; |
08 | int *e = &b; |
09 | *e &= d; |
10 | } |
11 | return *c; |
12 | } |
C49 : Crashes Open64 4.2.4 at -O3:
01 | static int a, c, d; |
02 | int b; |
03 | int *e; |
04 | void |
05 | fn1 () { |
06 | for (; a; a += 1) { |
07 | b = 0; |
08 | for (; b > -16; --b) |
09 | for (; c;) { |
10 | int *f = &d; |
11 | *f = 0; |
12 | } *e = 0; |
13 | } |
14 | } |
C50 : Crashes Sun CC 5.11 at -xO4:
01 | unsigned char a, d; |
02 | struct { |
03 | int f2 |
04 | } |
05 | b; |
06 | int c, e; |
07 | void |
08 | fn1 (p1) { |
09 | } |
10 | void |
11 | fn2 () { |
12 | c = 0; |
13 | for (; c <= 0;) |
14 | e = b.f2; |
15 | fn1 (0); |
16 | b = b; |
17 | d = -a; |
18 | } |
C51 : Crashes Sun CC 5.11 at -fast:
01 | int a, c; |
02 | int b[1]; |
03 | void |
04 | fn1 () { |
05 | short d; |
06 | for (; a; a -= 1) { |
07 | d = b1 = b1; |
08 | b[0] = 0; |
09 | } |
10 | } |
C52 : Crashes Sun CC 5.11 at -xO4:
01 | int a, b, d; |
02 | short c; |
03 | int |
04 | fn1 (p1) { |
05 | return a ? 0 : p1; |
06 | } |
07 | void |
08 | fn2 () { |
09 | int e = 0; |
10 | for (;;) { |
11 | c = 0; |
12 | d = fn1 (e ^ ~~c); |
13 | d && b; |
14 | } |
15 | } |
C53 : Crashes Sun CC 5.11 at -fast:
01 | long a; |
02 | int b, d; |
03 | int *c; |
04 | void |
05 | fn1 () { |
06 | int *e; |
07 | for (;; b--) |
08 | for (; d;) { |
09 | *c = 0; |
10 | *c &= (&e != 1) / a; |
11 | } |
12 | } |
C54 : Crashes Sun CC 5.11 at -xO0:
1 | #pragma pack(1) |
2 | struct { |
3 | int f3:1; |
4 | int f4:16 |
5 | } |
6 | a = { 1, 0 }; |
C55 : Crashes Sun CC 5.11 at -xO3:
01 | int a, c; |
02 | static int b = 1; |
03 | void fn1 (); |
04 | void |
05 | fn2 () { |
06 | for (; a; a--) { |
07 | c = 0; |
08 | for (; c != 1;) { |
09 | if (b) |
10 | break ; |
11 | fn1 (); |
12 | } |
13 | } |
14 | } |
C56 : Crashes Sun CC 5.11 at -xO4:
01 | #pragma pack(1) |
02 | struct S0 { |
03 | int f1; |
04 | int f3:1 |
05 | } |
06 | a; |
07 | void |
08 | fn1 ( struct S0 p1) { |
09 | p1.f3 = 0; |
10 | } |
11 | void |
12 | fn2 () { |
13 | fn1 (a); |
14 | } |
C57 : Crashes Sun CC 5.11 at -fast:
01 | int a, c, d, e, f, g, h, i, j, k; |
02 | volatile int b; |
03 | int |
04 | fn1 () { |
05 | for (; d; d = a) { |
06 | int *l = &c; |
07 | c = -3; |
08 | for (; c > -23; --c) |
09 | if (k) { |
10 | if (*l) |
11 | continue ; |
12 | return b; |
13 | } |
14 | for (; i; ++i) { |
15 | j = 0; |
16 | g = h; |
17 | for (; f <= 1; f += 1) { |
18 | } |
19 | } |
20 | } |
21 | return e; |
22 | } |
这篇关于红薯nbsp;57nbsp;个让nbsp;Cnbsp;编译器崩溃的代码的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!