News for hackers. Stuff that matters.
Re:PLOS2021: ISO-C became unusable for operating systems by astrange on Wednesday October 06, 2021 @08:03PM (#28780044)
> The compiler should optimize without changing the semantic of the code, even if it contains undefined/unspecified behavior.

That is what it does. "Undefined behavior" is a lack of semantics, so it is preserving semantics when it leaves those paths out. You can make a "defined C" with `-fsanitize-trap=undefined`, but C was never a high level assembler, and performance is critical for C users too.

Re:PLOS2021: ISO-C became unusable for operating systems by Asooka on Wednesday October 06, 2021 @08:17PM (#28780149)
C was always a high-level assembler. UB was meant to be "this cannot be defined portably, refer to your CPU's documentation". What do you gain by making C unusable by default? Just make it 5% slower by default, but possible to reason about and give people the option to shoot themselves in the foot. I don't know what more you need than the creator of the language telling you "this is not possible to implement sanely".
Re:PLOS2021: ISO-C became unusable for operating systems by tsukikage on Thursday October 07, 2021 @06:33AM (#28784508)
> UB was meant to be "this cannot be defined portably, refer to your CPU's documentation"

You're probably thinking of implementation-defined behaviour, which is the term for behaviour that, although not fully specified by the standard, is a valid behaviour for the program.

Undefined behaviour is different. From the article: "Undefined behavior gives the implementor license not to catch certain program errors that are difficult to diagnose."

Many people don't notice the distinction, and their intuition about what compilers should do with their code matches implementation-defined behaviour; and therefore they complain when, for UB, it does not behave this way.

There is a very strong argument for reclassifying many specific UBs as implementation-defined behaviours, but that's a rather different conversation from "the compiler should always do something sensible when encountering UB".

Re:PLOS2021: ISO-C became unusable for operating systems by pcwalton on Wednesday October 06, 2021 @08:20PM (#28780166)
Even assuming the 5% number were correct (depending on how expansive your definition of UB is, it may not be), asking everyone who doesn't adjust their compiler flags to accept a 5% slowdown for some theoretical benefits is at odds with economic reality.
Re:PLOS2021: ISO-C became unusable for operating systems by vyodaiken on Wednesday October 06, 2021 @08:38PM (#28780307)
Maybe you should tell the Linux developers that they are making a mistake.
Re:PLOS2021: ISO-C became unusable for operating systems by Asooka on Thursday October 07, 2021 @06:08AM (#28784340)
Even assuming the 5% number were correct (depending on how expansive your optimisations with UB assumptions are, it may not be), asking everyone who doesn't adjust their compiler flags to accept their programs being silently miscompiled for some theoretical benefits is at odds with economic reality.
Re:PLOS2021: ISO-C became unusable for operating systems by pcwalton on Thursday October 07, 2021 @04:57PM (#28791962)
Times like this I wish I were allowed to say exactly how much money a 1% fleet-wide loss in performance costs a big tech company.
Re:PLOS2021: ISO-C became unusable for operating systems by vyodaiken on Friday October 08, 2021 @09:25AM (#28799011)
A) there is no evidence such phenomena - especially in net- are due to unsafe optimizations, b) those companies dont need to shift their costs to other users
Re:PLOS2021: ISO-C became unusable for operating systems by naasking on Thursday October 07, 2021 @09:28AM (#28785965)
> "Undefined behavior" is a lack of semantics, so it is preserving semantics when it leaves those paths out.

It's not preserving semantics, it's inferring a valid program from an invalid one, but since the programmer entered an invalid program, unilaterally deciding that the valid program was the intended program seems dubious at best. These should really be errors, or warnings at the very least.