导读:本文由犹他州大学的计算机系的 John Regehr 整理。
虽然我不清楚到底有多少人喜欢看让编译器崩溃的程序,但这篇文章就是给这些的人(包括我)。我们讨论编译器Bug测试案例的论文就包括很多这种崩溃型的Bug。下文是就是这些 C 语言代码段,由工具逐字输出,代码格式上肯定会有些问题。(代码段后面申明了对应被崩溃的编译器,有读者问为什么没有 MSVC 编译器的,Regehr 回复说他们并没有测试MSVC 。)
看完这些程序,我们就能总结出什么东西吗?这很难说…… 很多 C 语言代码段是不容易看出来有问题,如果了解其中问题,我们需要知道一个特定编译器内部解析代码的细节。
C1 : Crashes Clang 2.6 at -O0:
1
2
3
4
5
6
7
8
9
10
|
C2 : Crashes Clang 2.6 at -O2:
1
2
3
4
5
6
7
8
9
10
|
C3 : Crashes Clang 2.6 at -O2:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
C4 : Crashes Clang 2.6 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
C5 : Crashes Clang 2.6 at -O2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
C6 : Crashes Clang 2.6 at -O0:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
C7 : Crashes Clang 2.6 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
C8 : Crashes Clang 2.6 at -O1:
1
2
3
4
5
6
7
8
9
10
|
C9 : Crashes Clang 2.6 at -O2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
C10 : Crashes Clang 2.6 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
C11 : Crashes Clang 2.7 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
C12 : Crashes Clang 2.7 at -O0:
1
2
3
4
5
6
7
|
C13 : Crashes Clang 2.7 at -O2:
1
2
3
4
5
6
7
8
9
|
C14 : Crashes GCC 3.2.0 at -O1:
1
2
3
4
5
6
7
8
|
C15 : Crashes GCC 3.2.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
C16 : Crashes GCC 3.2.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
C17 : Crashes GCC 3.2.0 at -O2:
1
2
3
4
5
6
7
8
9
10
|
C18 : Crashes GCC 3.2.0 at -O1:
1
2
3
4
5
|
C19 : Crashes GCC 3.2.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
C20 : Crashes GCC 3.3.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
C21 : Crashes GCC 3.4.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
|
C22 : Crashes GCC 3.4.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
C23 : Crashes GCC 4.0.0 at -O2:
1
2
3
4
5
6
7
8
|
C24 : Crashes GCC 4.0.0 at -O2:
1
2
3
4
5
6
|
C25 : Crashes GCC 4.0.0 at -O0:
1
2
3
4
5
6
|
C26 : Crashes GCC 4.0.0 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
C27 : Crashes GCC 4.0.0 at -O0:
1
2
3
4
5
6
|
C28 : Crashes GCC 4.0.0 at -O2:
1
2
3
4
5
6
7
8
9
10
11
12
|
C29 : Crashes GCC 4.1.0 at -O1:
1
2
3
4
5
6
7
8
|
C30 : Crashes GCC 4.1.0 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
|
C31 : Crashes GCC 4.1.0 at -O2:
1
2
3
4
5
6
7
8
|
C32 : Crashes GCC 4.1.0 at -O1:
1
2
3
4
5
6
7
8
|
C33 : Crashes GCC 4.1.0 at -O1:
1
2
3
4
5
|
C34 : Crashes GCC 4.1.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
C35 : Crashes GCC 4.2.0 at -O1:
1
2
3
4
5
6
7
8
|
C36 : Crashes GCC 4.2.0 at -O1:
1
2
3
4
5
6
7
8
9
|
C37 : Crashes GCC 4.3.0 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
C38 : Crashes GCC 4.3.0 at -O2:
1
2
3
4
5
6
7
8
9
|
C39 : Crashes GCC 4.3.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
|
C40 : Crashes GCC 4.3.0 at -O1:
1
2
3
4
5
6
7
|
C41 : Crashes GCC 4.3.0 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
|
C42 : Crashes Intel CC 12.0.5 at -O1:
1
2
3
4
5
6
7
8
9
10
11
12
13
|
C43 : Crashes Open64 4.2.4 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
|
C44 : Crashes Open64 4.2.4 at -O3:
1
2
3
4
5
6
7
|
C45 : Crashes Open64 4.2.4 at -O3:
1
2
3
4
5
6
|
C46 : Crashes Open64 4.2.4 at -O2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
C47 : Crashes Open64 4.2.4 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
C48 : Crashes Open64 4.2.4 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
|
C49 : Crashes Open64 4.2.4 at -O3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
C50 : Crashes Sun CC 5.11 at -xO4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
C51 : Crashes Sun CC 5.11 at -fast:
1
2
3
4
5
6
7
8
9
10
|
C52 : Crashes Sun CC 5.11 at -xO4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
C53 : Crashes Sun CC 5.11 at -fast:
1
2
3
4
5
6
7
8
9
10
11
12
|
C54 : Crashes Sun CC 5.11 at -xO0:
1
2
3
4
5
6
|
C55 : Crashes Sun CC 5.11 at -xO3:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
C56 : Crashes Sun CC 5.11 at -xO4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
C57 : Crashes Sun CC 5.11 at -fast:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
关于译(作)者:
黄利民:伯乐在线联合创始人,关注互联网和IT。