C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Every variable is volatile, everything is laundered, no optimisation

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 27 Aug 2023 09:03:10 -0700
On Sunday, 27 August 2023 06:31:13 PDT Frederick Virchanza Gotham via Std-
Proposals wrote:
> I'm talk specifically about situations where the compiler makes the
>
> determination:
> "That would result in UB and I can therefore take certain
>
> liberties here, such as not bothering to check if the signed integer
> goes from positive to negative"
...
> No that's not what I mean. I'm specifically talking about where the
> compiler performs an optimisation where it detects UB (such as
> neglecting to check if a signed int has incremented from positive to
> negative).

I hear what you're saying, but what you're saying is just not how things work.
You're making an assumption of how compilers work and that's a flawed
assumption.

I mean, under some reading, it's true. The problem is that they are not coded
the way your sentence, as phrased, supposed they are. It's not that they
detected the UB and therefore made an optimisation. If that were the case,
then they could emit warnings for every single possible UB and let the
programmer know. That is clearly not possible, therefore that's clearly not
how they are written.

Instead of being written to detect undefined behaviour, they're written to
operate on defined behaviour. What you're effectively asking for is that they
begin detecting the UB possibilities (all of them) and make them specified.

Moreover, you're not asking that they all have the same behaviour: you're
assuming there's an underlying true behaviour that everyone agrees upon, and
that can be demonstrated not to be true either. This is especially true when
compilers have a choice of which instructions to use but whose behaviour is
only the same within the defined behaviour parameters of the language.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DCAI Cloud Engineering

Received on 2023-08-27 16:03:14