[executable semantics] silence known, and detect new, crashes (#312)

* Add assertion to detect UB in interpreter.cpp

This change, applied to 6e5070d ("Adapting jsiek's executable semantics tooling
for commit. (#237)"), causes the if2.6c test to segfault.  Becase the assertion
fires only when `stmt == nullptr` and no code has permission to change `stmt`
(it is `const`) before it is dereferenced in the `switch`, and nothiing in
`PrintStatement` is supposed to exit the program, the assertion is a valid
change that detects a bug.

The crash was originally manifest in 29a5994 ("Executable Semantics: 1st-class
stacks (#296)").

* Temporarily disable the if2 test pending #311

See https://github.com/carbon-language/carbon-lang/issues/311

* [executable semantics] Record exit code on expected error.

This will prevent a final segfault from sneaking by, detected as a passing test.
A more principled follow-up commit would bottleneck detected error exit
reporting and have it write something to std::cerr that can be recognized.
This commit is contained in:
Dave Abrahams
2021-02-27 18:52:22 -08:00
committed by GitHub
parent 2205fd52ce
commit 2afbfd6146
10 changed files with 15 additions and 3 deletions
@@ -4,6 +4,7 @@
#include "executable_semantics/interpreter/interpreter.h"
#include <cassert>
#include <iostream>
#include <iterator>
#include <map>
@@ -744,7 +745,8 @@ auto IsBlockAct(Action* act) -> bool {
void StepStmt() {
Frame* frame = state->stack.Top();
Action* act = frame->todo.Top();
Statement* stmt = act->u.stmt;
Statement* const stmt = act->u.stmt;
assert(stmt != nullptr && "null statement!");
std::cout << "--- step stmt ";
PrintStatement(stmt, 1);
std::cout << " --->" << std::endl;