www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7965] New: Invalid outer function scope pointer in some cases

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7965

           Summary: Invalid outer function scope pointer in some cases
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: verylonglogin.reg gmail.com



---
---
import std.stdio;

void main() {
    int i;
    writeln("Real &i: ", &i); // Prints 12FE44

    void nested() {
        writeln("Fake &i: ", &i); // Prints FFFFFFF0
        i = 0; // Access Violation
    }

    struct LocalS {
        // `S s;` or `S s = void;` fields also causes this bug
        // for `struct S { int unused = 0; }`
        int unused = 0;
        void f() { nested(); }
    }

    LocalS ls;
    ls.f();
}
---

Because of this bug things like `map!nestedPred("a b".splitter(" "))` give us
`Access Violation` so it's major.

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


Nils <mailme+d nilsb.dyndns.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mailme+d nilsb.dyndns.org



Seems to me that the default initializer for nested structs misses the context
pointer.

---
void main() {
    int x;
    struct S {
        char y;
        void boom() {x = 42;} // makes the struct nested
    }
    S s;
    s.boom();
}
---

There's no crash with an int y, probably because then the struct is considered
to be "all zeros", and is given special treatment. It crashes anyway when y is
explicitly initialized to 0, because the "all zeros" recognizer isn't that
smart
<https://github.com/D-Programming-Language/dmd/blob/aa7939aefcf61d6a44f2d4df15157427f7725fc0/src/struct.c#L532>.
There's no crash if s is initialized to S() or {}.
S.init.boom() crashes, too, of course.

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull



https://github.com/D-Programming-Language/dmd/pull/1014

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




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/6b7f7445209c853ca8a33d4dd80c185b0d09250f
fix Issue 7965 - Invalid outer function scope pointer in some cases

https://github.com/D-Programming-Language/dmd/commit/0b1ffa8feecf90fbef22b8172a62653e4cba4056


Issue 7965 - Invalid outer function scope pointer in some cases

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




12:15:37 MSD ---
I think this bug may be fixed when `std.algorithm` will work.
Example mentioned in this issue description (now fails):
---
import std.array;
import std.algorithm;

void main() {
    string s = "x";
    auto arr = map!(a => (s ~= "y", s ~ a ~ a))("a b".splitter(" ")).array();
    assert(arr == ["xyaa", "xyybb"]);
}
---

A bit reduced case:
---
import std.algorithm;

void main() {
    string s = "x";
    auto f = map!(a => s)("a b".splitter(" ")).front;
}
---

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




12:43:33 MSD ---
Reduced test-case:
---
struct S
{
    string str;
    uint unused1, unused2 = 0;
}

auto f(alias fun)()
{
    struct Result
    {
        S s;

        this(S _s) { s = _s; }

        void g() { assert(fun(s.str) == "xa"); }
    }

    return Result(S("a"));
}

void main() {
    string s = "x";
    f!(a => s ~= a)().g();
    assert(s == "xa");
}
---

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





 Reduced test-case:
 ---
 struct S
 {
     string str;
     uint unused1, unused2 = 0;
 }
 
 auto f(alias fun)()
 {
     struct Result
     {
         S s;
 
         this(S _s) { s = _s; }
 
         void g() { assert(fun(s.str) == "xa"); }
     }
 
     return Result(S("a"));
 }
 
 void main() {
     string s = "x";
     f!(a => s ~= a)().g();
     assert(s == "xa");
 }
 ---
Thanks for your work and good test case! https://github.com/D-Programming-Language/dmd/pull/1034 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 02 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7965




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/0a612679713182d571f9eaa140dc93451c623d06
fix Issue 7965 more, all nested structs should be initialized by
StructLiteralExp, not __init.

https://github.com/D-Programming-Language/dmd/commit/51b5b6e09f77eacaffc48fb3c4255e2929832915


More fix for issue 7965

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED


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


Denis Shelomovskij <verylonglogin.reg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrei metalanguage.com



18:57:40 MSK ---
*** Issue 5641 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2012