[Bug 84] Writes to struct members marked as shared are not volatile

gdc-bugzilla at gdcproject.org gdc-bugzilla at gdcproject.org
Sun Nov 10 01:18:22 PST 2013


http://bugzilla.gdcproject.org/show_bug.cgi?id=84

--- Comment #1 from Johannes Pfau <johannespfau at gmail.com> 2013-11-10 09:18:22 GMT ---
In the generated ASM it looks like at least part of the problem is that the
struct is loaded into a register. Of course, then volatile has no effect.
Quoting from c-decl.c:

--------------------------------------
    /* If a type has volatile components, it should be stored in memory.
       Otherwise, the fact that those components are volatile
       will be ignored, and would even crash the compiler.
       Of course, this only makes sense on  VAR,PARM, and RESULT decl's.   */
    if (C_TYPE_FIELDS_VOLATILE (TREE_TYPE (decl))
    && (TREE_CODE (decl) == VAR_DECL ||  TREE_CODE (decl) == PARM_DECL
      || TREE_CODE (decl) == RESULT_DECL))
      {
    /* It is not an error for a structure with volatile fields to
       be declared register, but reset DECL_REGISTER since it
       cannot actually go in a register.  */
    int was_reg = C_DECL_REGISTER (decl);
    C_DECL_REGISTER (decl) = 0;
    DECL_REGISTER (decl) = 0;
    c_mark_addressable (decl);
    C_DECL_REGISTER (decl) = was_reg;
      } 
--------------------------------------


Also not working:
--------------------------------------
shared struct Register
{
    size_t a;
}

Register* reg = cast(Register*)0xFFDDCCAA;

void main()
{
     for(size_t i = 0; i < 10; i++)
         reg.a = i;
}
--------------------------------------


Working:
--------------------------------------
shared struct Register //Also working without shared here
{
    size_t a;
}

shared(Register*) reg = cast(shared(Register*))0xFFDDCCAA;

void main()
{
     for(size_t i = 0; i < 10; i++)
         reg.a = i;
}
--------------------------------------

-- 
Configure bugmail: http://bugzilla.gdcproject.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are watching all bug changes.


More information about the D.gnu mailing list