From 3a0f75d959bd8e875a7d7767caed8ae3fa94ee8e Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Wed, 28 Mar 2018 17:45:44 +0300 Subject: [PATCH] Fix Issue 18474 - Postblit not working in shared structs --- src/dmd/dsymbolsem.d | 9 +++++++++ src/dmd/expressionsem.d | 2 ++ test/compilable/test18474.d | 15 +++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 test/compilable/test18474.d diff --git a/src/dmd/dsymbolsem.d b/src/dmd/dsymbolsem.d index 869d4e59051f..7893fc70a0ef 100644 --- a/src/dmd/dsymbolsem.d +++ b/src/dmd/dsymbolsem.d @@ -242,10 +242,17 @@ private extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* postblitCalls.push(new OnScopeStatement(loc, TOK.onScopeFailure, new ExpStatement(loc, ex))); } + void checkShared() + { + if (sd.type.isShared()) + stc |= STC.shared_; + } + // Build our own "postblit" which executes a, but only if needed. if (postblitCalls.dim || (stc & STC.disable)) { //printf("Building __fieldPostBlit()\n"); + checkShared(); auto dd = new PostBlitDeclaration(declLoc, Loc.initial, stc, Id.__fieldPostblit); dd.generated = true; dd.storage_class |= STC.inference; @@ -283,6 +290,8 @@ private extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* ex = new CallExp(loc, ex); e = Expression.combine(e, ex); } + + checkShared(); auto dd = new PostBlitDeclaration(declLoc, Loc.initial, stc, Id.__aggrPostblit); dd.generated = true; dd.storage_class |= STC.inference; diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index efb1546db83f..e5d19aaf0812 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -6750,6 +6750,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor */ Expression e = e1x.copy(); e.type = e.type.mutableOf(); + if (e.type.isShared && !sd.type.isShared) + e.type = e.type.unSharedOf(); e = new BlitExp(exp.loc, e, e2x); e = new DotVarExp(exp.loc, e, sd.postblit, false); e = new CallExp(exp.loc, e); diff --git a/test/compilable/test18474.d b/test/compilable/test18474.d new file mode 100644 index 000000000000..454e9c507f33 --- /dev/null +++ b/test/compilable/test18474.d @@ -0,0 +1,15 @@ +shared struct A +{ + this(this); +} + +struct B +{ + A a; +} + +void main() +{ + shared B b1; + auto b2 = b1; +}