Compilers like all software, would also be prone to bugs, logical errors.
像所有软件一样的编译器也容易出错,逻辑错误。
How does one validate the output generated by the compiler. Typically, my question is(are)
如何验证编译器生成的输出。通常,我的问题是(是)
-
How to validate that the machine code generated is correct?
如何验证生成的机器代码是否正确?
-
How to ensure that the machine code generated is according to the language specification.
如何确保生成的机器代码符合语言规范。
-
Does it make sense to just pick an open source project (in C if one is also writing a compiler in C) to just compile it through the "compiler". In that case also, how do judge that the compiler is behaving as expected.
选择一个开源项目(在C中,如果还在C中编写编译器)只是通过“编译器”编译它是否有意义。在这种情况下,如何判断编译器的行为是否符合预期。
-
Are there any formal test cases (literature) provided by the language standards committee that a "language complying" compiler has to satisfy?
是否有语言标准委员会提供的“语言符合”编译器必须满足的正式测试用例(文献)?
-
What are the sure "give aways" that the problem in a program compiled by a compiler is a compiler bug and not a program bug.
什么是“赠送”,编译器编译的程序中的问题是编译器错误而不是程序错误。
- Any examples where mainstream compilers get confused and compile the code wrong?
- 主流编译器混淆并编译代码错误的任何例子?
Links to any literature would be appreciated.
任何文献的链接将不胜感激。
7 个解决方案
#1
There are several compiler test suites out there. We've had some luck using the Plum Hall test suite for a C compiler. It consists of a large set of C code specifically written to test against the language standard. It verifies that the compiler can handle the language syntax and semantics.
那里有几个编译器测试套件。我们运用Plum Hall测试套件来运行C编译器。它由一组专门编写的C代码组成,用于测试语言标准。它验证编译器可以处理语言语法和语义。
#2
Good test suites for real languages are expensive to create and maintain. There's a reason that the Plum Hall test suite, which is industry standard for ANSI C, is so bloody expensive.
用于实际语言的良好测试套件的创建和维护成本很高。 Plum Hall测试套件是ANSI C的行业标准,因此非常昂贵。
George Necula's translation validation is a brilliant idea but also quite expensive to implement.
George Necula的翻译验证是一个绝妙的想法,但实施起来也相当昂贵。
The one thing that's cheap and easy is this: maintain a suite of regression tests, and every time you fix a bug in your compiler, put a suitable test into your regression suites. With compilers, it's unbelievable how easy it is to keep reintroducing the same bug over and over. Disciplined additions to your regression suite will prevent that, and they don't cost much.
这是一件便宜又简单的事情:维护一套回归测试,每次修复编译器中的错误时,都要在回归套件中加入合适的测试。有了编译器,令人难以置信的是,一遍又一遍地重新引入相同的bug是多么容易。对您的回归套件进行有纪律的补充可以防止这种情况发生,并且它们不会花费太多。
#3
The general practice is to create a large set of small programs that each demonstrate one aspects of the compiler. These will include both program that compile and ones that shouldn't. General the ASM coming out the back end is not checked but rather the program is run and it's output checked. As for how to make sure there are no bugs in the test cases: make them small, as in 5-10 lines each.
通常的做法是创建一大组小程序,每个程序都演示编译器的一个方面。这些将包括编译的程序和不应编译的程序。一般情况下,不会检查后端出现的ASM,而是运行程序并检查输出。至于如何确保测试用例中没有错误:将它们缩小,如每个5-10行。
These test suites can be very large as in hundreds to thousands of tests (for example: an out of date test suite for the D programming language) and generally include one or more test cases for every bug ever reported.
这些测试套件可能非常大,如数百到数千个测试(例如:D编程语言的过时测试套件),并且通常包括针对所报告的每个错误的一个或多个测试用例。
#4
For the idea to compile a big open source project:
为了编译一个大型开源项目的想法:
You could take a project that itself has a test suite. Then you compile the project and its test suite and see if the tests pass. To validate these results you compile project and test suite with an other compiler, and run the tests again.
您可以选择一个本身就有测试套件的项目。然后编译项目及其测试套件,看看测试是否通过。要验证这些结果,请使用其他编译器编译项目和测试套件,然后再次运行测试。
#5
The Eiffel compiler is open source and has an extensive library of test cases and internal design contracts.
Eiffel编译器是开源的,具有广泛的测试用例和内部设计合同库。
#6
There was an earlier question related to this for C, but it comes down to a carefully written compiler test suite.
之前有一个与C相关的问题,但它归结为一个精心编写的编译器测试套件。
As to when compilers get the code wrong, I've hit that often enough in my professional career, thanks. It's happened less and less over time, but I found a bug in MS C++ compilers targeting CLI this week.
至于编译器何时错误地编写代码,我在职业生涯中经常遇到这种情况,谢谢。它随着时间的推移越来越少,但我发现本周针对CLI的MS C ++编译器中存在一个错误。
#7
GCC has a quite large test suite (https://gcc.gnu.org/onlinedocs/gccint/Testsuites.html#Testsuites). It is available on the SCM : https://github.com/gcc-mirror/gcc/tree/master/gcc/testsuite
GCC有一个非常大的测试套件(https://gcc.gnu.org/onlinedocs/gccint/Testsuites.html#Testsuites)。它可以在SCM上找到:https://github.com/gcc-mirror/gcc/tree/master/gcc/testsuite
#1
There are several compiler test suites out there. We've had some luck using the Plum Hall test suite for a C compiler. It consists of a large set of C code specifically written to test against the language standard. It verifies that the compiler can handle the language syntax and semantics.
那里有几个编译器测试套件。我们运用Plum Hall测试套件来运行C编译器。它由一组专门编写的C代码组成,用于测试语言标准。它验证编译器可以处理语言语法和语义。
#2
Good test suites for real languages are expensive to create and maintain. There's a reason that the Plum Hall test suite, which is industry standard for ANSI C, is so bloody expensive.
用于实际语言的良好测试套件的创建和维护成本很高。 Plum Hall测试套件是ANSI C的行业标准,因此非常昂贵。
George Necula's translation validation is a brilliant idea but also quite expensive to implement.
George Necula的翻译验证是一个绝妙的想法,但实施起来也相当昂贵。
The one thing that's cheap and easy is this: maintain a suite of regression tests, and every time you fix a bug in your compiler, put a suitable test into your regression suites. With compilers, it's unbelievable how easy it is to keep reintroducing the same bug over and over. Disciplined additions to your regression suite will prevent that, and they don't cost much.
这是一件便宜又简单的事情:维护一套回归测试,每次修复编译器中的错误时,都要在回归套件中加入合适的测试。有了编译器,令人难以置信的是,一遍又一遍地重新引入相同的bug是多么容易。对您的回归套件进行有纪律的补充可以防止这种情况发生,并且它们不会花费太多。
#3
The general practice is to create a large set of small programs that each demonstrate one aspects of the compiler. These will include both program that compile and ones that shouldn't. General the ASM coming out the back end is not checked but rather the program is run and it's output checked. As for how to make sure there are no bugs in the test cases: make them small, as in 5-10 lines each.
通常的做法是创建一大组小程序,每个程序都演示编译器的一个方面。这些将包括编译的程序和不应编译的程序。一般情况下,不会检查后端出现的ASM,而是运行程序并检查输出。至于如何确保测试用例中没有错误:将它们缩小,如每个5-10行。
These test suites can be very large as in hundreds to thousands of tests (for example: an out of date test suite for the D programming language) and generally include one or more test cases for every bug ever reported.
这些测试套件可能非常大,如数百到数千个测试(例如:D编程语言的过时测试套件),并且通常包括针对所报告的每个错误的一个或多个测试用例。
#4
For the idea to compile a big open source project:
为了编译一个大型开源项目的想法:
You could take a project that itself has a test suite. Then you compile the project and its test suite and see if the tests pass. To validate these results you compile project and test suite with an other compiler, and run the tests again.
您可以选择一个本身就有测试套件的项目。然后编译项目及其测试套件,看看测试是否通过。要验证这些结果,请使用其他编译器编译项目和测试套件,然后再次运行测试。
#5
The Eiffel compiler is open source and has an extensive library of test cases and internal design contracts.
Eiffel编译器是开源的,具有广泛的测试用例和内部设计合同库。
#6
There was an earlier question related to this for C, but it comes down to a carefully written compiler test suite.
之前有一个与C相关的问题,但它归结为一个精心编写的编译器测试套件。
As to when compilers get the code wrong, I've hit that often enough in my professional career, thanks. It's happened less and less over time, but I found a bug in MS C++ compilers targeting CLI this week.
至于编译器何时错误地编写代码,我在职业生涯中经常遇到这种情况,谢谢。它随着时间的推移越来越少,但我发现本周针对CLI的MS C ++编译器中存在一个错误。
#7
GCC has a quite large test suite (https://gcc.gnu.org/onlinedocs/gccint/Testsuites.html#Testsuites). It is available on the SCM : https://github.com/gcc-mirror/gcc/tree/master/gcc/testsuite
GCC有一个非常大的测试套件(https://gcc.gnu.org/onlinedocs/gccint/Testsuites.html#Testsuites)。它可以在SCM上找到:https://github.com/gcc-mirror/gcc/tree/master/gcc/testsuite