Bug 18597 – more unsafe unaligned pointer errors

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-12T09:59:05Z
Last change time
2018-03-23T03:40:33Z
Keywords
safe
Assigned to
No Owner
Creator
Walter Bright
See also
https://issues.dlang.org/show_bug.cgi?id=15399

Comments

Comment #0 by bugzilla — 2018-03-12T09:59:05Z
[email protected] writes: //////////////////////////////// test.d //////////////////////////////// @safe: struct Victim { bool alive = true; ~this() { alive = false; } } align(1) struct Unaligned { align(1): ubyte filler; Victim* p; } pragma(msg, Unaligned.sizeof); void main() { enum N = 100; Unaligned[N] hosts; foreach (n; 0..N) { version (original) hosts[n].p = new Victim; else version (variation1) hosts[n] = Unaligned(0, new Victim); else version (variation2) { Unaligned u = { p: new Victim }; hosts[n] = u; } else static assert(false); assert(hosts[n].p.alive); } // Unaligned.p is invisible to the GC due to alignment void trustedCollect() @trusted { import core.memory; GC.collect(); } trustedCollect(); foreach (n; 0..N) assert(hosts[n].p.alive); // Dangling pointer! } //////////////////////////////////////////////////////////////////////// These should all fail with the same error: dmd -version=original test.d dmd -version=variation1 test.d dmd -version=variation2 test.d The different versions effectively do the same thing, just with different syntax.
Comment #1 by ag0aep6g — 2018-03-12T10:07:19Z
(In reply to Walter Bright from comment #0) > ag0aep6g@[...].com writes: Please don't give away people's email addresses like that. It doesn't matter too much for me, because that's my D address, but generally it's not a nice thing to do.
Comment #2 by bugzilla — 2018-03-13T06:10:47Z
(In reply to ag0aep6g from comment #1) > (In reply to Walter Bright from comment #0) > > ag0aep6g@[...].com writes: > > Please don't give away people's email addresses like that. It doesn't matter > too much for me, because that's my D address, but generally it's not a nice > thing to do. Sorry about that, but I just copy pasted from the public page: https://issues.dlang.org/show_bug.cgi?id=15399 I.e. your email address appears with every comment you write, including the one this is in reply to. You might want to check your bugzilla profile.
Comment #3 by bugzilla — 2018-03-13T07:40:38Z
Comment #4 by ag0aep6g — 2018-03-13T11:22:37Z
(In reply to Walter Bright from comment #2) > (In reply to ag0aep6g from comment #1) [...] > Sorry about that, but I just copy pasted from the public page: [...] > I.e. your email address appears with every comment you write, including the > one this is in reply to. You might want to check your bugzilla profile. Huh. I thought I had set the name properly. Sorry for lashing out. Bugzilla didn't already make it public, though. It's smart enough to remove the domain part in replies and on truly public pages (i.e. when you're not logged in). But then again, <https://forum.dlang.org/group/issues> shows all Bugzilla activity to the public, including everyone's addresses. So that's that.
Comment #5 by github-bugzilla — 2018-03-23T03:40:32Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/3afbfb2c1b6328c18bdfd1f122091a74e22f9d69 fix Issue 18597 - more unsafe unaligned pointer errors https://github.com/dlang/dmd/commit/a0764d9ea0e7b3132d0a362b2f32a6e74e6e76e0 Merge pull request #8019 from WalterBright/fix18597 fix Issue 18597 - more unsafe unaligned pointer errors merged-on-behalf-of: Mike Franklin <[email protected]>