www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Issue 2584] New: GDC on ARM does not honor volatile

reply d-bugmail puremagic.com writes:
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.


-- 
Jan 13 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584






Sorry. Please disregard for now. I'm seeing conflicting results.


-- 
Jan 13 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584






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


-- 
Jan 13 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
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



CEST ---
Closing this since volatile is deprecated.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 09 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584


Manu <turkeyman gmail.com> changed:

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




 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: -------
Oct 10 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584






 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: -------
Oct 10 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584


Iain Buclaw <ibuclaw ubuntu.com> changed:

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



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

        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: -------
Oct 10 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584





 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: -------
Oct 10 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2584






 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: -------
Oct 10 2012