RFC: feature for static safety
Martin Uecker proposes using UBSan trapping mode with -O2 and `[[gnu::warning("UNSAFE")]] void __builtin_trap()` to statically prove safety properties.
Martin Uecker proposes a novel technique for statically verifying safety properties by combining Undefined Behavior Sanitizer (UBSan) in trapping mode with GCC’s -O2 optimization and a __builtin_trap declaration. This method aims to identify remaining edge cases that sanitizers might miss, thereby ensuring program safety.
- proposer
Proposes using UBSan trapping mode with a `__builtin_trap` declaration and -O2 optimization to statically identify and fix remaining safety issues.
“What happens is that the sanitizer annotates the program with __builtin_trap() where there is a potential problem, while the optimizer then removes all traps it can show to be unreachable.”
In Details
This RFC explores a technique to leverage GCC's UBSan and optimization passes to statically prove safety properties. By enabling UBSan traps and applying aggressive optimization, unreachable traps are eliminated, leaving behind only verifiable issues or false positives. This approach aims to complement traditional sanitization and fuzzing by providing a stronger guarantee against undefined behavior and safety violations, particularly for critical code segments.
- UBSan
- Undefined Behavior Sanitizer. A runtime instrumentation tool that detects various types of undefined behavior in C/C++ code.
- trap
- In this context, a trap refers to a signal or exception raised by the program, often used to halt execution when an error or critical condition is detected.
- optimization
- The process by which a compiler transforms code to improve its performance (speed, size, power consumption) while preserving its functional behavior.
- statically prove
- To mathematically demonstrate a property of a program without executing it, typically through analysis of its source code or intermediate representations.
- __builtin_trap
- A GCC built-in function that causes the program to trap (terminate abnormally), usually used for indicating unrecoverable errors or unexercised code paths.