Thread overview
[Issue 7965] New: Invalid outer function scope pointer in some cases
Apr 22, 2012
Denis
Jun 17, 2012
Nils
Jun 18, 2012
Kenji Hara
Jul 02, 2012
Denis Shelomovskij
Jul 02, 2012
Denis Shelomovskij
Jul 02, 2012
Kenji Hara
Jul 08, 2012
Walter Bright
Nov 08, 2012
Denis Shelomovskij
April 22, 2012
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


--- Comment #0 from Denis <verylonglogin.reg@gmail.com> 2012-04-22 10:43:01 MSD ---
---
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: -------
June 17, 2012
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


--- Comment #1 from Nils <mailme+d@nilsb.dyndns.org> 2012-06-17 16:50:24 PDT ---
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: -------
June 18, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965


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

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


--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-18 06:45:33 PDT ---
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: -------
June 21, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965



--- Comment #3 from github-bugzilla@puremagic.com 2012-06-21 12:35:20 PDT ---
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 Merge pull request #1014 from 9rnsr/fix7965

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: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965



--- Comment #4 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-07-02 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: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965



--- Comment #5 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-07-02 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: -------
July 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965



--- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> 2012-07-02 08:37:57 PDT ---
(In reply to comment #5)
> 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: -------
July 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965



--- Comment #7 from github-bugzilla@puremagic.com 2012-07-08 12:36:55 PDT ---
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 Merge pull request #1034 from 9rnsr/fix7965

More fix for issue 7965

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 08, 2012
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: -------
November 08, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=7965


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

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


--- Comment #8 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-11-08 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: -------