Bug 6670 – cast(shared(const(int)))a is not an lvalue

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Mac OS X
Creation time
2011-09-14T11:50:00Z
Last change time
2012-10-28T09:40:25Z
Assigned to
yebblies
Creator
peter.alexander.au

Comments

Comment #0 by peter.alexander.au — 2011-09-14T11:50:41Z
This program causes DMD 2.055 to seg fault. import std.concurrency; void main() { int a; atomicOp!"+="(a, 1); } It didn't seg fault in DMD 2.053 (haven't tested DMD 2.054).
Comment #1 by peter.alexander.au — 2011-09-14T13:49:26Z
Actually, this is probably related to http://d.puremagic.com/issues/show_bug.cgi?id=6669 core.atomic uses a lot of inline asm, and atomicOp just causes those functions to be instantiated, triggering the other seg fault.
Comment #2 by braddr — 2011-09-17T20:09:02Z
I'm not seeing a dmd crash with this bug (much like not seeing the crash in bug 6669), but I am seeing something odd: import std.concurrency; void main() { int a; atomicOp!"+="(a, 1); } yields: ./../../druntime/import/core/atomic.di(108): Error: cast(shared(const(int)))val is not an lvalue s/std.concurrency/core.atomic/ And it builds.
Comment #3 by braddr — 2011-09-17T21:01:43Z
My current reduction: template isMutable(T) { enum isMutable = !is(T == const) && !is(T == immutable); } unittest { static assert(isMutable!(shared const(int)[])); } int atomicLoad( ref const shared int val ) { return 0; } void main() { int a; atomicLoad(a); } $ dmd bug6670.d bug6670.d(20): Error: cast(shared(const(int)))a is not an lvalue Not sure why the unused isMutable template is required, nor why the unittest block is required when -unittest isn't part of the dmd arguments, but they are and without them the code compiles. Don or Daniel, either of you want to take this? I took it because I originally thought it was a iasm or backend bug, which are areas I'm more familiar with.
Comment #4 by yebblies — 2011-09-17T22:26:19Z
Urrgh. Reduced test case: shared(const(int)[]) g; int atomicLoad( ref const shared int val ) { return 0; } void main() { int a; atomicLoad(a); } Due to issue 5493, ref is completely ignored when looking at parameter type matching. Therefore int matches const(shared(int)), when it really shouldn't. This gets turned into cast(const(shared(int)))a The compiler then optimizes cast(const(shared(int)))a, which it shouldn't do when an lvalue is required. (like bug 2521) Finally, a bug in CastExp::optimize uses constOf rather than addMod(MODconst)/implicitConvTo>=MATCHconst to see if the cast can be ignored, and constOf's wacky behaviour interacts with the previous usage of shared(const(int)) in the declaration of g. So yeah, no segfault, and nothing to do with inline asm. This bug is probably a dupe of bug 6669 and you've had the pleasure of discovering a new one!
Comment #5 by braddr — 2011-10-17T20:37:35Z
Updating the description based on where this bug report has evolved. Reassigning to yebblies since he's done the investigation. Also lowering to critical from regression since I'm pretty sure it's not actually a regression. Please correct me if I'm wrong.
Comment #6 by lovelydear — 2012-04-27T14:59:30Z
With 2.059, none of the examples compile. PS E:\DigitalMars\dmd2\samples> dmd -c bug.d bug.d(14): Error: function bug.atomicLoad (ref shared(const(int)) val) is not callable using argument types (int)
Comment #7 by yebblies — 2012-10-28T09:40:25Z
All of the contributing bugs seem to have been fixed.