[Bug 74] New: Wrong code generated (incorrect offset to static array)

gdc-bugzilla at gdcproject.org gdc-bugzilla at gdcproject.org
Thu Aug 8 11:07:35 PDT 2013


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

             Bug #: 74
           Summary: Wrong code generated (incorrect offset to static
                    array)
    Classification: Unclassified
           Product: GDC
           Version: 4.7.x
          Platform: ARM
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
        AssignedTo: ibuclaw at gdcproject.org
        ReportedBy: power at pobox.sk


Created attachment 48
  --> http://bugzilla.gdcproject.org/attachment.cgi?id=48
Result of: objdump -S -r test.o

Reduced example:
----------------
File colors.d:
----------------
module colors;

public class Colors {
  public static void getColor(int j, ref float[4] color) {
    color[0] = 0.7;
    color[1] = 0.6;
    color[2] = 0.5;
    color[3] = 0.8;
  }
}
----------------
File test.d:
----------------
module test;

private import colors;

public class Test {
  public static float[2] testData2 = [2.7, 2.6];
  private:
  static float[4*4][2][6] testColors;
  public static float[2] testData3;

  public static void prepare() {
    foreach (k; 0..6) {
      float[4] currentColor;

      Colors.getColor(k, currentColor);
      testColors[k][0] = currentColor ~ currentColor ~ currentColor ~
currentColor;

      Colors.getColor(k, currentColor);
      testColors[k][1] = currentColor ~ currentColor ~ currentColor ~
currentColor;
    }
  }

  public static float[2] spData = [1.7, 1.6];
}
----------------
File main.d:
----------------
module main;

private import test;
private import std.stdio;
private import std.conv;

public int main(string[] argv) {
    Test.prepare();
    writeln(to!string(Test.testData2[0]));
    return 0;
}
----------------

When the example is executed it should print 2.7 (and exit), but when I compile
it for ARM and run it, it prints 0.7, because the value gets overwritten in the
prepare method.

I'm using a GDC crosscompiler for ARM linux (running on x64 linux) - gcc
version 4.7.3 with gdc commit e63f8a7a5657684c0f2c3d2fd1a9c33eec0208c0 (last
commit in gdc-4.7 branch before merging D 2.063).

I couldn't reproduce the error on x86 and x64.

The result of "objdump -S -r test.o" is in the attachment.
In line 26 is an instruction which loads an offset from memory - relocation:
  10:    e59f31dc     ldr    r3, [pc, #476]    ; 1f4
<_D4test4Test7prepareFZv+0x1f4>

In lines 188 and 189 is the relocation:
 1f4:    00000050     .word    0x00000050
            1f4: R_ARM_TLS_LE32    _D4test4Test10testColorsG6G2G16f

The value in line 188 is 0x50, but it should be 0x40.

This bug appears in some specific conditions (e.g. when I add a writeln
statement into test.d, the bug disappears).

-- 
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