assume, assert, enforce, @safe

Artur Skawina via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 31 08:26:11 PDT 2014


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.

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); }

(yes, stdizing compiler barriers would be a good idea)

artur


More information about the Digitalmars-d mailing list