www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Bug 72] New: Wrong code generated (segmentation fault) when class

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


           Summary: Wrong code generated (segmentation fault) when class
                    (in one file) inherits from class (in another file)
                    with interface
    Classification: Unclassified
           Product: GDC
           Version: 4.7.x
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
        AssignedTo: ibuclaw gdcproject.org
        ReportedBy: power pobox.sk


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

public interface ScreenI {
  public void initSDL();
  public void clear();
}

public class Screen3D: ScreenI {
 public:
  static int width = 640;
  static int height = 480;

  public void initSDL() {
    resized(width, height); // segfault here
  }

  public void resized(int width, int height) {
    this.width = width;
    this.height = height;
  }

  public void clear() {
  }
}
----------------
File main.d:
----------------
module main;

private import screen3d;

public class Screen: Screen3D {
  public override void resized(int width, int height) {
    super.resized(width, height);
  }

  public override void clear() {
  }
}

private:
Screen screen1;

public int main(string[] args) {
  screen1 = new Screen;
  ScreenI screen2 = screen1;
  screen2.initSDL();
  return 0;
}
----------------

When the example is compiled as two sepparate files, it segfaults.
When the example is merged into one file, it works.

In disassembly the difference between working and segfaulting version is
following:
In working version, the method initSDL in the interface of the class Screen is
a reference to a thunk function which subtracts 8 (in 32-bit code) from first
parameter and then calls the initSDL method in class Screen3D.
In segfaulting version, the method initSDL in the interface of the class Screen
is a reference to the initSDL method in class Screen3D.

I tested it on 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 also tried GCC-4.8-MinGW-GDC-.7z and
gcc-4.6.1-tdm-1-gdc-9841510e8ba6-20120109.7z (both from
https://bitbucket.org/goshawk/gdc/downloads) - I didn't manage to create an
executable, but the assembly/disassembly shows the same wrong code.

I tried the latest DMD (2.063.2) and it generates correct code.

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