assume, assert, enforce, @safe
Daniel Gibson via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 31 08:37:22 PDT 2014
Am 31.07.2014 17:26, schrieb Artur Skawina via Digitalmars-d:
> On 07/31/14 15:44, Daniel Gibson via Digitalmars-d wrote:
>> And don't forget this (rather old) case: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=8537
>> (I really don't get why anyone would want such an optimization: I want an optimizer to use clever inlining, use SSE etc where it makes sense and stuff like that - but not to remove code I wrote.)
>
> That is actually not a bug, but a perfectly valid optimization. The
> compiler isn't clairvoyant and can not know that some data that you
> wrote, but never read back, matters.
I don't want the compiler to care about that. When I tell it to write
something, I want it to do that, even if it might look like nonsense (if
anything, it could create a warning).
>
> The solution is to tell the compiler that you really need that newly
> (over-)written data. Eg
>
> asm {"" : : "m" (*cast(typeof(password[0])[9999999]*)password.ptr); }
inline asm is not portable
>
> (yes, stdizing compiler barriers would be a good idea)
C11 defines a memset_s which is guaranteed not to be optimized away..
that's 9 years after that bugreport and will probably never be supported
by MSVC (they don't even support C99).
One could write a memset_s oneself.. that does a memset, reads the data
and writes a char of it or something to a global variable (hoping that
the compiler won't optimize that to "just set that variable to 0").
The thing is: I don't want a compiler to remove code I wrote just
because it "thinks" it's superfluous.
It could tell me about it as a warning, but it shouldn't just silently
do it. If removing code makes my code faster, I can do it myself.
Cheers,
Daniel
More information about the Digitalmars-d
mailing list