SoylentNews
SoylentNews is people
https://soylentnews.org/

Title    Undefined Behavior != Unsafe Programming
Date    Thursday February 16 2017, @03:36PM
Author    cmn32480
Topic   
from the for-all-you-code-writing-types-out-there dept.
https://soylentnews.org/article.pl?sid=17/02/16/0233242

Phoenix666 writes:

John Regehr, Professor of Computer Science, University of Utah, writes:

Undefined behavior (UB) in C and C++ is a clear and present danger to developers, especially when they are writing code that will execute near a trust boundary. A less well-known kind of undefined behavior exists in the intermediate representation (IR) for most optimizing, ahead-of-time compilers. For example, LLVM IR has undef and poison in addition to true explodes-in-your-face C-style UB. When people become aware of this, a typical reaction is: "Ugh, why? LLVM IR is just as bad as C!" This piece explains why that is not the correct reaction.

Undefined behavior is the result of a design decision: the refusal to systematically trap program errors at one particular level of a system. The responsibility for avoiding these errors is delegated to a higher level of abstraction. For example, it is obvious that a safe programming language can be compiled to machine code, and it is also obvious that the unsafety of machine code in no way compromises the high-level guarantees made by the language implementation. Swift and Rust are compiled to LLVM IR; some of their safety guarantees are enforced by dynamic checks in the emitted code, other guarantees are made through type checking and have no representation at the LLVM level. Either way, UB at the LLVM level is not a problem for, and cannot be detected by, code in the safe subsets of Swift and Rust. Even C can be used safely if some tool in the development environment ensures that it will not execute UB. The L4.verified project does exactly this.


Original Submission

Links

  1. "Phoenix666" - https://soylentnews.org/~Phoenix666/
  2. "writes" - http://blog.regehr.org/archives/1467
  3. "undef" - http://llvm.org/docs/LangRef.html#undefined-values
  4. "poison" - http://llvm.org/docs/LangRef.html#poison-values
  5. "L4.verified" - https://ts.data61.csiro.au/projects/TS/l4.verified/
  6. "Original Submission" - https://soylentnews.org/submit.pl?op=viewsub&subid=18604

© Copyright 2024 - SoylentNews, All Rights Reserved

printed from SoylentNews, Undefined Behavior != Unsafe Programming on 2024-04-24 10:54:30