On Thursday, 31 July 2014 at 15:26:27 UTC, Artur Skawina via Digitalmars-d wrote:
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

Any idea how dead store removal interacts with the modern C(++) memory model? Another thread could hold a reference to the memory being written to.

Reply via email to