Bug 5930 – cas doesn't work when used in code compiled with -D
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
druntime
Product
D
Version
D2
Platform
x86
OS
All
Creation time
2011-05-05T12:03:00Z
Last change time
2012-05-20T12:21:43Z
Keywords
pull
Assigned to
nobody
Creator
jsancio
Comments
Comment #0 by jsancio — 2011-05-05T12:03:54Z
$ cat cas_test.d
import core.atomic;
import std.exception;
import std.stdio;
unittest
{
shared bool init = false;
writefln("init = %s", init);
enforce(cas(&init, false, true));
writefln("init = %s", init);
}
void main() {}
$ dmd -unittest cas_test.d && ./cas_test
init = false
init = true
$ dmd -unittest -D cas_test.d && ./cas_test
init = false
object.Exception@cas_test.d(9): Enforcement failed
----------------
./cas_test(_D3std9exception7bailOutFAyaixAaZv+0x5b) [0x80a0dcb]
./cas_test(_D3std9exception45__T7enforceTbVAyaa10_6361735f746573742e64Vi9Z7enforceFbLAxaZb+0x2b) [0x80985ff]
./cas_test(_D8cas_test11__unittest1FZv+0x39) [0x80954dd]
./cas_test(_D8cas_test9__modtestFZv+0x8) [0x80987bc]
./cas_test(_D4core7runtime18runModuleUnitTestsUZb16__foreachbody247MFKPS6object10ModuleInfoZi+0x24) [0x80a3e1c]
./cas_test(_D6object10ModuleInfo7opApplyFMDFKPS6object10ModuleInfoZiZi+0x46) [0x809a872]
./cas_test(runModuleUnitTests+0x87) [0x80a3d37]
./cas_test(_D2rt6dmain24mainUiPPaZi6runAllMFZv+0x20) [0x809b718]
./cas_test(_D2rt6dmain24mainUiPPaZi7tryExecMFMDFZvZv+0x20) [0x809b678]
./cas_test(main+0x94) [0x809b624]
/lib/i386-linux-gnu/libc.so.6(__libc_start_main+0xe7) [0x126e37]
./cas_test() [0x80953f1]
-------------------------
Does this have to do with core/atomic.d having version(D_Doc) bool cas(...)(...) {return false; } ?
The work around is not to use object files compiled with the -D flag!
Comment #1 by sean — 2011-05-06T10:46:30Z
Yep. This is because core.atomic has stub functions for documentation purposes inside version(D_Ddoc) blocks. There was some talk about Phobos and Druntime moving to a different convention for documentation though. I'll see about fixing this for 2.054, since 2.053 is almost in the can.
Comment #2 by r.sagitario — 2011-05-06T23:31:50Z
phobos now uses version StdDdoc instead of D_Ddoc to fix similar issues.
Grep tells me core.atomic is the only module in druntime that uses version(D_ddoc).
What needs to be done is:
- add -version=DruntimeDdoc or similar to DOCFMT in the makefiles
- use version(DruntimeDdoc) instead of version(D_Ddoc)
*** Issue 7528 has been marked as a duplicate of this issue. ***
Comment #5 by opantm+spam — 2012-02-23T01:10:34Z
(In reply to comment #4)
> *** Issue 7528 has been marked as a duplicate of this issue. ***
As mentioned in 7528, this also has the unpleasant side-effect that attempting to use atomic operations (through core.atomic.atomicOp) silently results in incorrect behaviour, as the operations do nothing and return init.
Comment #6 by opantm+spam — 2012-03-21T13:59:41Z
This bug really needs to get fixed for 2.059. It causes incorrect code to be generated and code to silently fail, in ways that may be difficult to track down and occur rarely (namely, when atomicOp is used).
Comment #7 by ricochet1k — 2012-03-22T13:02:14Z
Wouldn't it be better to put a "static assert(false);" in the body of those Ddoc function stubs instead of "return false;"? Then it would become immediately obvious what is wrong if they are used.