Skip to content

Commit

Permalink
Merge branch 'merge_stable_convert' into merge_stable
Browse files Browse the repository at this point in the history
Conflicts:
	src/access.d
	src/aggregate.d
	src/aliasthis.d
	src/apply.d
	src/argtypes.d
	src/arrayop.d
	src/arraytypes.d
	src/attrib.d
	src/builtin.d
	src/canthrow.d
	src/clone.d
	src/cond.d
	src/constfold.d
	src/cppmangle.d
	src/ctfeexpr.d
	src/dcast.d
	src/dclass.d
	src/declaration.d
	src/declaration.h
	src/delegatize.d
	src/denum.d
	src/dimport.d
	src/dinifile.d
	src/dinterpret.d
	src/dmacro.d
	src/dmangle.d
	src/dmodule.d
	src/doc.d
	src/dscope.d
	src/dstruct.d
	src/dsymbol.d
	src/dtemplate.d
	src/dunittest.d
	src/dversion.d
	src/errors.d
	src/escape.d
	src/expression.d
	src/func.d
	src/globals.d
	src/hdrgen.d
	src/identifier.d
	src/init.d
	src/inline.d
	src/json.d
	src/lexer.d
	src/lib.d
	src/link.d
	src/magicport.json
	src/mars.d
	src/mtype.d
	src/nogc.d
	src/nspace.d
	src/objc.d
	src/opover.d
	src/optimize.d
	src/parse.d
	src/root/file.d
	src/root/filename.d
	src/root/man.d
	src/root/outbuffer.d
	src/root/speller.d
	src/sapply.d
	src/sideeffect.d
	src/statement.d
	src/staticassert.d
	src/target.d
	src/tokens.d
	src/traits.d
	src/visitor.d
	test/runnable/sdtor.d
  • Loading branch information
9rnsr committed Sep 24, 2015
2 parents cf7204e + 8f1188a commit 61c91dc
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 86 deletions.
6 changes: 6 additions & 0 deletions changelog.dd
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,9 @@ Macros:
STDMODREF = <a href="phobos/std_$1.html">$2</a>
XREF = <a href="phobos/std_$1.html#$2">$2</a>
CXREF = <a href="phobos/core_$1.html#$2">$2</a>

BUGZILLA = <a href="https://issues.dlang.org/show_bug.cgi?id=$0">Bugzilla $0</a>
PULL_REQUEST = $(LINK2 https://github.com/D-Programming-Language/$1/pull/$2, $1#$2)
DMDPR = $(PULL_REQUEST dmd,$1)

BOOKTABLE = <table><caption>$1</caption>$+</table>
14 changes: 2 additions & 12 deletions src/backend/cod2.c
Original file line number Diff line number Diff line change
Expand Up @@ -5083,14 +5083,9 @@ code *cddctor(elem *e,regm_t *pretregs)
*/
usednteh |= EHcleanup;
if (config.exe == EX_NT)
{
usednteh |= NTEHcleanup | NTEH_try;
{ usednteh |= NTEHcleanup | NTEH_try;
nteh_usevars();
}
else
{
usednteh |= EHtry;
}
assert(*pretregs == 0);
code cs;
cs.Iop = ESCAPE | ESCdctor;
Expand Down Expand Up @@ -5126,14 +5121,9 @@ code *cdddtor(elem *e,regm_t *pretregs)
*/
usednteh |= EHcleanup;
if (config.exe == EX_NT)
{
usednteh |= NTEHcleanup | NTEH_try;
{ usednteh |= NTEHcleanup | NTEH_try;
nteh_usevars();
}
else
{
usednteh |= EHtry;
}

code cs;
cs.Iop = ESCAPE | ESCddtor;
Expand Down
15 changes: 14 additions & 1 deletion src/clone.d
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ extern (C++) FuncDeclaration buildOpAssign(StructDeclaration sd, Scope* sc)
fparams.push(new Parameter(STCnodtor, sd.type, Id.p, null));
auto tf = new TypeFunction(fparams, sd.handleType(), 0, LINKd, stc | STCref);
auto fop = new FuncDeclaration(declLoc, Loc(), Id.assign, stc, tf);
fop.storage_class |= STCinference;

Expression e = null;
if (stc & STCdisable)
{
Expand Down Expand Up @@ -283,7 +285,8 @@ extern (C++) FuncDeclaration buildOpAssign(StructDeclaration sd, Scope* sc)
sc2.linkage = LINKd;
fop.semantic(sc2);
fop.semantic2(sc2);
fop.semantic3(sc2);
// Bugzilla 15044: fop->semantic3 isn't run here for lazy forward reference resolution.

sc2.pop();
if (global.endGagging(errors)) // if errors happened
{
Expand Down Expand Up @@ -735,6 +738,8 @@ extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* sc)
StructDeclaration sdv = (cast(TypeStruct)tv).sym;
if (!sdv.postblit)
continue;
sdv.postblit.functionSemantic();

stc = mergeFuncAttrs(stc, sdv.postblit);
stc = mergeFuncAttrs(stc, sdv.dtor);
if (stc & STCdisable)
Expand Down Expand Up @@ -779,6 +784,8 @@ extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* sc)
*/
if (!sdv.dtor)
continue;
sdv.dtor.functionSemantic();

ex = new ThisExp(loc);
ex = new DotVarExp(loc, ex, v, 0);
if (v.type.toBasetype().ty == Tstruct)
Expand Down Expand Up @@ -816,6 +823,7 @@ extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* sc)
{
//printf("Building __fieldPostBlit()\n");
auto dd = new PostBlitDeclaration(declLoc, Loc(), stc, Id.__fieldPostblit);
dd.storage_class |= STCinference;
dd.fbody = a ? new CompoundStatement(loc, a) : null;
sd.postblits.shift(dd);
sd.members.push(dd);
Expand Down Expand Up @@ -847,6 +855,7 @@ extern (C++) FuncDeclaration buildPostBlit(StructDeclaration sd, Scope* sc)
e = Expression.combine(e, ex);
}
auto dd = new PostBlitDeclaration(declLoc, Loc(), stc, Id.__aggrPostblit);
dd.storage_class |= STCinference;
dd.fbody = new ExpStatement(loc, e);
sd.members.push(dd);
dd.semantic(sc);
Expand Down Expand Up @@ -889,6 +898,8 @@ extern (C++) FuncDeclaration buildDtor(AggregateDeclaration ad, Scope* sc)
StructDeclaration sdv = (cast(TypeStruct)tv).sym;
if (!sdv.dtor)
continue;
sdv.dtor.functionSemantic();

stc = mergeFuncAttrs(stc, sdv.dtor);
if (stc & STCdisable)
{
Expand Down Expand Up @@ -932,6 +943,7 @@ extern (C++) FuncDeclaration buildDtor(AggregateDeclaration ad, Scope* sc)
{
//printf("Building __fieldDtor()\n");
auto dd = new DtorDeclaration(declLoc, Loc(), stc, Id.__fieldDtor);
dd.storage_class |= STCinference;
dd.fbody = new ExpStatement(loc, e);
ad.dtors.shift(dd);
ad.members.push(dd);
Expand Down Expand Up @@ -963,6 +975,7 @@ extern (C++) FuncDeclaration buildDtor(AggregateDeclaration ad, Scope* sc)
e = Expression.combine(ex, e);
}
auto dd = new DtorDeclaration(declLoc, Loc(), stc, Id.__aggrDtor);
dd.storage_class |= STCinference;
dd.fbody = new ExpStatement(loc, e);
ad.members.push(dd);
dd.semantic(sc);
Expand Down
28 changes: 28 additions & 0 deletions src/dclass.d
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,34 @@ public:
semanticRun = PASSsemanticdone;
//printf("-ClassDeclaration::semantic(%s), type = %p\n", toChars(), type);
//members->print();

version (none) // FIXME
{
LafterSizeok:
// The additions of special member functions should have its own
// sub-semantic analysis pass, and have to be deferred sometimes.
// See the case in compilable/test14838.d
for (size_t i = 0; i < fields.dim; i++)
{
VarDeclaration v = fields[i];
Type tb = v.type.baseElemOf();
if (tb.ty != Tstruct)
continue;
StructDeclaration sd = (cast(TypeStruct)tb).sym;
if (sd.semanticRun >= PASSsemanticdone)
continue;

sc2.pop();

_scope = scx ? scx : sc.copy();
_scope.setNoFree();
_scope._module.addDeferredSemantic(this);

//printf("\tdeferring %s\n", toChars());
return;
}
}

/* Look for special member functions.
* They must be in this class, not in a base class.
*/
Expand Down
1 change: 1 addition & 0 deletions src/declaration.d
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ enum STCnogc = (1L << 42); // @nogc
enum STCvolatile = (1L << 43); // destined for volatile in the back end
enum STCreturn = (1L << 44); // 'return ref' for function parameters
enum STCautoref = (1L << 45); // Mark for the already deduced 'auto ref' parameter
enum STCinference = (1L << 46); // do attribute inference

enum STC_TYPECTOR = (STCconst | STCimmutable | STCshared | STCwild);
enum STC_FUNCATTR = (STCref | STCnothrow | STCnogc | STCpure | STCproperty | STCsafe | STCtrusted | STCsystem);
Expand Down
1 change: 1 addition & 0 deletions src/declaration.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ enum PINLINE;
#define STCvolatile 0x80000000000LL // destined for volatile in the back end
#define STCreturn 0x100000000000LL // 'return ref' for function parameters
#define STCautoref 0x200000000000LL // Mark for the already deduced 'auto ref' parameter
#define STCinference 0x400000000000LL // do attribute inference

const StorageClass STCStorageClass = (STCauto | STCscope | STCstatic | STCextern | STCconst | STCfinal |
STCabstract | STCsynchronized | STCdeprecated | STCoverride | STClazy | STCalias |
Expand Down
36 changes: 33 additions & 3 deletions src/func.d
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ public:
* the function body.
*/
TemplateInstance ti;
if (fbody && (isFuncLiteralDeclaration() || (inferRetType && !isCtorDeclaration()) || isInstantiated() && !isVirtualMethod() && !(ti = parent.isTemplateInstance(), ti && !ti.isTemplateMixin() && ti.tempdecl.ident != ident)))
if (fbody && (isFuncLiteralDeclaration() || (storage_class & STCinference) || (inferRetType && !isCtorDeclaration()) || isInstantiated() && !isVirtualMethod() && !(ti = parent.isTemplateInstance(), ti && !ti.isTemplateMixin() && ti.tempdecl.ident != ident)))
{
if (f.purity == PUREimpure) // purity not specified
flags |= FUNCFLAGpurityInprocess;
Expand Down Expand Up @@ -1300,7 +1300,7 @@ public:
{
VarDeclaration argptr = null;
VarDeclaration _arguments = null;
int nerrors = global.errors;

if (!parent)
{
if (global.errors)
Expand All @@ -1315,6 +1315,29 @@ public:
//printf("storage class = x%x %x\n", sc->stc, storage_class);
//{ static int x; if (++x == 2) *(char*)0=0; }
//printf("\tlinkage = %d\n", sc->linkage);

if (ident == Id.assign && !inuse)
{
if (storage_class & STCinference)
{
/* Bugzilla 15044: For generated opAssign function, any errors
* from its body need to be gagged.
*/
uint oldErrors = global.startGagging();
++inuse;
semantic3(sc);
--inuse;
if (global.endGagging(oldErrors)) // if errors happened
{
// Disable generated opAssign, because some members forbid identity assignment.
storage_class |= STCdisable;
fbody = null; // remove fbody which contains the error
semantic3Errors = false;
}
return;
}
}

//printf(" sc->incontract = %d\n", (sc->flags & SCOPEcontract));
if (semanticRun >= PASSsemantic3)
return;
Expand All @@ -1330,6 +1353,9 @@ public:
error("has no function body with return type inference");
return;
}

uint oldErrors = global.errors;

if (frequire)
{
for (size_t i = 0; i < foverrides.dim; i++)
Expand Down Expand Up @@ -2172,7 +2198,7 @@ public:
* Otherwise, error gagging should be temporarily ungagged by functionSemantic3.
*/
semanticRun = PASSsemantic3done;
semantic3Errors = (global.errors != nerrors) || (fbody && fbody.isErrorStatement());
semantic3Errors = (global.errors != oldErrors) || (fbody && fbody.isErrorStatement());
if (type.ty == Terror)
errors = true;
//printf("-FuncDeclaration::semantic3('%s.%s', sc = %p, loc = %s)\n", parent->toChars(), toChars(), sc, loc.toChars());
Expand Down Expand Up @@ -2215,6 +2241,10 @@ public:
else
return functionSemantic3();
}

if (storage_class & STCinference)
return functionSemantic3();

return true;
}

Expand Down
28 changes: 28 additions & 0 deletions test/compilable/test15056.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
nothrow:

version (Windows)
{
version (LP_64)
import core.stdc.stdlib;
else
// doesn't currently work b/c SEH remains present even in nothrow code
void* alloca(size_t) { return null; }
}
else
import core.stdc.stdlib;

struct S
{
~this() nothrow {}
}

S foo(void* p = alloca(1234))
{
return S();
}

int main()
{
foo();
return 0;
}
32 changes: 32 additions & 0 deletions test/fail_compilation/fail15044.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail15044.d(30): Error: function fail15044.V.opAssign is not callable because it is annotated with @disable
---
*/

struct S
{
void opAssign(S) {}
}

struct V
{
// `s` has opAssign, so struct V needs to generate member-wise opAssign.
// But S.opAssign is not callable on const object, so V.opAssign should be
// @disable.
const S s;

// Here, the initializer of x is evaluated in V.semantic2. But
// V.opAssign.semantic3 is not yet invoked, so its attribute should be
// lazily inferred in functionSemantic even though it's non-instantiated function.
enum int x = ()
{
// Here, the initializer of x is evaluated in V.semantic2, and
// V.opAssign.semantic3 is not yet invoked in this time.
// Therefore its @disable attribute needs to be inferred by
// functionSemantic, even though it's non-instantiated function.
V v;
v = v;
}();
}
Loading

0 comments on commit 61c91dc

Please sign in to comment.