A C++ implementation that detects undefined behavior?

后端 未结 10 1368
没有蜡笔的小新
没有蜡笔的小新 2020-11-27 14:13

A huge number of operations in C++ result in undefined behavior, where the spec is completely mute about what the program\'s behavior ought to be and allows for anything to

10条回答
  •  眼角桃花
    2020-11-27 14:39

    You might want to read about SAFECode.

    This is a research project from the University of Illinois, the goal is stated on the front page (linked above):

    The purpose of the SAFECode project is to enable program safety without garbage collection and with minimal run-time checks using static analysis when possible and run-time checks when necessary. SAFECode defines a code representation with minimal semantic restrictions designed to enable static enforcement of safety, using aggressive compiler techniques developed in this project.

    What is really interesting to me is the elimination of the runtime checks whenever the program can be proved to be correct statically, for example:

    int array[N];
    for (i = 0; i != N; ++i) { array[i] = 0; }
    

    Should not incur any more overhead than the regular version.

    In a lighter fashion, Clang has some guarantees about undefined behavior too as far as I recall, but I cannot get my hands on it...

提交回复
热议问题