www.digitalmars.com         C & C++   DMDScript  

D.gnu - [Bug 179] New: invalid code generation with -O2 for method returning

Date: Fri, 17 Apr 2015 18:18:01 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"

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

            Bug ID: 179
           Summary: invalid code generation with -O2 for method returning
                    ref
           Product: GDC
           Version: 4.9.x
          Hardware: x86
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: Normal
         Component: gdc
          Assignee: ibuclaw gdcproject.org
          Reporter: ketmar ketmar.no-ip.org

the following code works with -O0, but segfaults with -O2.

the expected output (-O0 is ok):
emit: me=B743FFF8
addS: me=B743FFF8

output with -O2:
emit: me=B73ECFF8
addS: me=BFAC86B8

the thing is that both addresses MUST be the same, and they are with -O0. but
with -O2 second address is completely wrong.


this works:
# gdc -o z00_gdc -O0 z00.d && ./z00_gdc
and this segfaults:
# gdc -o z00_gdc -O2 z00.d && ./z00_gdc


the code:
=== z00.d ===
import std.stdio;

struct Signal(Args...) {
private:
  RestrictedSignal!(Args) mRestricted;

public:
  alias restricted this;

  void emit (Args args)  trusted { mRestricted.mImpl.emit(args); }
   property ref RestrictedSignal!(Args) restricted ()  trusted { return
mRestricted; }
}


struct RestrictedSignal(Args...) {
private:
  SignalImpl mImpl;

public:
  void connect(string method, ClassType) (ClassType obj)  trusted
  //if (is(ClassType == class) && __traits(compiles, {void delegate (Args) dg =
mixin("&obj."~method);}))
  {
    mImpl.addSlot(obj, cast(void delegate ())mixin("&obj."~method));
  }
}

private struct SignalImpl {
   disable this (this);
   disable void opAssign (SignalImpl other);

  void emit(Args...) (Args args) {
    writeln("emit: me=", &this);
  }

  void addSlot (Object obj, void delegate () dg) {
    writeln("addS: me=", &this);
  }
}


class MyObject {
  ref RestrictedSignal!(string, int) valueChanged () { return valueChangedSg; }
  private Signal!(string, int) valueChangedSg;

   property void value (int v) {
    valueChangedSg.emit("setting new value", v);
  }
}

class Observer {
  void watch (string msg, int i) {}
}

void main () {
  auto a = new MyObject;
  auto o = new Observer;

  a.value = 3;
  a.valueChanged.connect!"watch"(o);
}

-- 
You are receiving this mail because:
You are watching all bug changes.
Apr 17 2015