Thread overview
[Issue 2584] New: GDC on ARM does not honor volatile
Jan 13, 2009
d-bugmail
Jan 13, 2009
d-bugmail
Jan 13, 2009
d-bugmail
Oct 10, 2012
Manu
Oct 10, 2012
Iain Buclaw
Oct 10, 2012
Iain Buclaw
Oct 10, 2012
Manu
Oct 10, 2012
Iain Buclaw
January 13, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2584

           Summary: GDC on ARM does not honor volatile
           Product: DGCC aka GDC
           Version: unspecified
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: major
          Priority: P2
         Component: glue layer
        AssignedTo: dvdfrdmn@users.sf.net
        ReportedBy: default_357-line@yahoo.de


In GDC on ARM, the following code

struct Test {
  uint* ptr;
  uint write(uint i) { volatile (*ptr) = i; return i; }
}

void main() {
  Test test; test.ptr = cast(uint*) 0xDEAD_BEEF;
  test.write(0); test.write(0); test.write(0);
  return;
}

generates this assembly: http://paste.dprogramming.com/dpep5uc3 .

Note how the 0 is only stored once, not thrice, in blatant violation of the volatile.


-- 

January 13, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2584





------- Comment #1 from default_357-line@yahoo.de  2009-01-13 05:31 -------
Sorry. Please disregard for now. I'm seeing conflicting results.


-- 

January 13, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2584





------- Comment #2 from default_357-line@yahoo.de  2009-01-13 05:44 -------
Right. Here we go. I had testcased it incorrectly.

The code to reproduce the error is


struct Test {
  uint* ptr;
  uint write(uint i) { volatile (*ptr) = i; return i; }
  static Test opCall() { // it has to be returned by a function call, otherwise
the error doesn't happen
    Test res;
    res.ptr = cast(uint*) 0xDEAF_D00D;
    return res;
  }
}

void main() {
  auto mat = Test();
  asm { "@baz"; }; // added to make sure it's the correct assembly this time
  mat.write(0); mat.write(0); mat.write(0);
  return;
}

And the assembly is here http://paste.dprogramming.com/dpag1p5d


-- 

October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2584


Alex Rønne Petersen <alex@lycus.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |alex@lycus.org
         Resolution|                            |INVALID


--- Comment #3 from Alex Rønne Petersen <alex@lycus.org> 2012-10-10 02:00:38 CEST ---
Closing this since volatile is deprecated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2584


Manu <turkeyman@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |turkeyman@gmail.com


--- Comment #4 from Manu <turkeyman@gmail.com> 2012-10-10 01:25:21 PDT ---
(In reply to comment #3)
> Closing this since volatile is deprecated.

Really? It's still important... What's the work-around?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2584



--- Comment #5 from Iain Buclaw <ibuclaw@ubuntu.com> 2012-10-10 02:27:48 PDT ---
(In reply to comment #4)
> (In reply to comment #3)
> > Closing this since volatile is deprecated.
> 
> Really? It's still important... What's the work-around?

It is indeed important.  It's also now unreplicable. http://paste.dprogramming.com/dpsuffnm

Gonna put this down to a bug in gcc-4.1 that has since been fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2584


Iain Buclaw <ibuclaw@ubuntu.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED


--- Comment #6 from Iain Buclaw <ibuclaw@ubuntu.com> 2012-10-10 02:37:40 PDT ---
Note:

The D2-way of doing this is by using shared.


struct Test {
  shared uint* ptr;
  uint write(uint i) { (*ptr) = i; return i; }
}

void main() {
  Test test; test.ptr = cast(uint*) 0xDEAD_BEEF;
  test.write(0); test.write(0); test.write(0);
  return;
}


Also guarantees that (*ptr) is stored thrice also.

----
_Dmain:
        .fnstart
        ldr     r3, .L6
        @baz
        mov     r0, #0
        str     r0, [r3]
        str     r0, [r3]
        str     r0, [r3]
        bx      lr
        .fnend



Regards,
Iain

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2584



--- Comment #7 from Manu <turkeyman@gmail.com> 2012-10-10 02:57:56 PDT ---
(In reply to comment #6)
> Note:
> 
> The D2-way of doing this is by using shared.

Really? I thought it was nothing more than a type-safety marker. So shared actually makes a variable volatile?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 10, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2584



--- Comment #8 from Iain Buclaw <ibuclaw@ubuntu.com> 2012-10-10 03:32:04 PDT ---
(In reply to comment #7)
> (In reply to comment #6)
> > Note:
> > 
> > The D2-way of doing this is by using shared.
> 
> Really? I thought it was nothing more than a type-safety marker. So shared actually makes a variable volatile?

Not the variable, but it's type is qualified as volatile, this produces subtly different codegen (IIRC volatile on the var would mean it is loaded thrice also). Given it's use in atomics, and that data-depending ordering is essential. I felt this to be important.  Similarly for immutable, which sets the type as being const qualified.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------