News for hackers. Stuff that matters.
Re:Defining the Undefinedness of C (2015) [pdf] by iainmerrick on Wednesday July 26, 2017 @11:48AM (#14857224)
Yes, I'd say those are similar. Systems languages, no mandatory GC.

That Friendly C proposal is terrific, I'd dearly love to use that. Basically, use sane and conservative optimizations for most code, with the option of using aggressive optimizations for hotspots. Kind of similar to Rust -- mostly safe by default, more dangerous stuff available when you need it.

Re:Defining the Undefinedness of C (2015) [pdf] by raphlinus on Wednesday July 26, 2017 @11:51AM (#14857250)
The Friendly C idea seems to be basically dead. For an update of what Regehr is pursuing now, see https://blog.regehr.org/archives/1520 (Undefined Behavior in 2017).
Re:Defining the Undefinedness of C (2015) [pdf] by masklinn on Wednesday July 26, 2017 @12:03PM (#14857414)
IIRC Safe Rust has no UB, `unsafe` does, according to the Nomicon:

* Dereferencing null or dangling pointers

* Reading uninitialized memory

* Breaking the pointer aliasing rules

* Producing invalid primitive values:

- dangling/null references

- a bool that isn't 0 or 1

- an undefined enum discriminant

- a char outside the ranges [0x0, 0xD7FF] and [0xE000, 0x10FFFF]

- A non-utf8 str

* Unwinding into another language

* Causing a data race

These are all guarantees unsafe code must uphold or there are no guarantees anymore.

IIRC LLVM IR also has UBs.

Re:Defining the Undefinedness of C (2015) [pdf] by iainmerrick on Wednesday July 26, 2017 @12:09PM (#14857475)
I wonder if it's possible to sneak UB into normal "safe" Rust code, by leveraging LLVM optimizations?
Re:Defining the Undefinedness of C (2015) [pdf] by kibwen on Wednesday July 26, 2017 @12:44PM (#14857809)
Yes, though those are considered bugs in the Rust compiler. As the goal of Rust is to forbid memory unsafety in safe code, the Rust developers accept the burden of working around LLVM-related UB (which sometimes is quite difficult, see e.g. this longstanding UB bug related to how LLVM translates certain numeric casts: https://github.com/rust-lang/rust/issues/10184 ).
Re:Defining the Undefinedness of C (2015) [pdf] by Manishearth on Wednesday July 26, 2017 @12:35PM (#14857727)
Assuming no compiler bugs, no.

UB isn't something "caused" by optimizations, it's something that exists in the code before optimizations, optimizations can just trigger nasal demons. So you shouldn't be able to write UB in safe Rust assuming no compiler bugs.

(And assuming that any unsafe libraries being leveraged are bug free)

Re:Defining the Undefinedness of C (2015) [pdf] by bbatha on Wednesday July 26, 2017 @12:32PM (#14857703)
Its totally possible, but its considered a compiler bug if it does happen. In the same way that its possible to segfault java if there's a bug in the jit. There's an on going project to verify the semantics of the Rust language and its safe abstractions[0] which should make it easier to choose which optimizations are legal.

0: http://plv.mpi-sws.org/rustbelt/