Skip to content
This repository was archived by the owner on Jun 20, 2019. It is now read-only.

Commit d8b53e8

Browse files
authored
Merge pull request #591 from ibuclaw/vsafeon
Fix inference of 'scope' for parameters for inferable functions
2 parents 854323e + d219cbf commit d8b53e8

File tree

6 files changed

+51
-48
lines changed

6 files changed

+51
-48
lines changed

gcc/d/dfrontend/dtemplate.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2313,9 +2313,9 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
23132313
Expressions *fargs;
23142314
// result
23152315
Match *m;
2316-
int property; // 0: unintialized
2317-
// 1: seen @property
2318-
// 2: not @property
2316+
int property; // 0: unintialized
2317+
// 1: seen @property
2318+
// 2: not @property
23192319
size_t ov_index;
23202320
TemplateDeclaration *td_best;
23212321
TemplateInstance *ti_best;
@@ -2324,13 +2324,12 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
23242324

23252325
static int fp(void *param, Dsymbol *s)
23262326
{
2327-
if (!s->errors)
2328-
{
2329-
if (FuncDeclaration *fd = s->isFuncDeclaration())
2330-
return ((ParamDeduce *)param)->applyFunction(fd);
2331-
if (TemplateDeclaration *td = s->isTemplateDeclaration())
2332-
return ((ParamDeduce *)param)->applyTemplate(td);
2333-
}
2327+
if (s->errors)
2328+
return 0;
2329+
if (FuncDeclaration *fd = s->isFuncDeclaration())
2330+
return ((ParamDeduce *)param)->applyFunction(fd);
2331+
if (TemplateDeclaration *td = s->isTemplateDeclaration())
2332+
return ((ParamDeduce *)param)->applyTemplate(td);
23342333
return 0;
23352334
}
23362335

@@ -2750,7 +2749,8 @@ void functionResolve(Match *m, Dsymbol *dstart, Loc loc, Scope *sc,
27502749
* Now instantiate the template.
27512750
*/
27522751
assert(p.td_best->_scope);
2753-
if (!sc) sc = p.td_best->_scope; // workaround for Type::aliasthisOf
2752+
if (!sc)
2753+
sc = p.td_best->_scope; // workaround for Type::aliasthisOf
27542754

27552755
TemplateInstance *ti = new TemplateInstance(loc, p.td_best, p.ti_best->tiargs);
27562756
ti->semantic(sc, fargs);

gcc/d/dfrontend/expressionsem.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,15 @@ class ExpressionSemanticVisitor : public Visitor
981981
return;
982982
}
983983

984-
// Bugzilla 11581: With the syntax `new T[edim]` or `thisexp.new T[edim]`,
985-
// T should be analyzed first and edim should go into arguments iff it's
986-
// not a tuple.
987-
Expression *edim = NULL;
988-
if (!exp->arguments && exp->newtype->ty == Tsarray)
989-
{
990-
edim = ((TypeSArray *)exp->newtype)->dim;
991-
exp->newtype = ((TypeNext *)exp->newtype)->next;
992-
}
984+
// Bugzilla 11581: With the syntax `new T[edim]` or `thisexp.new T[edim]`,
985+
// T should be analyzed first and edim should go into arguments iff it's
986+
// not a tuple.
987+
Expression *edim = NULL;
988+
if (!exp->arguments && exp->newtype->ty == Tsarray)
989+
{
990+
edim = ((TypeSArray *)exp->newtype)->dim;
991+
exp->newtype = ((TypeNext *)exp->newtype)->next;
992+
}
993993

994994
ClassDeclaration *cdthis = NULL;
995995
if (exp->thisexp)

gcc/d/dfrontend/func.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,10 @@ static void initInferAttributes(FuncDeclaration *fd)
433433

434434
if (!fd->isVirtual() || fd->introducing)
435435
fd->flags |= FUNCFLAGreturnInprocess;
436+
437+
// Initialize for inferring STCscope
438+
if (global.params.vsafe)
439+
fd->flags |= FUNCFLAGinferScope;
436440
}
437441

438442
// Do the semantic analysis on the external interface to the function.
@@ -1576,7 +1580,7 @@ void FuncDeclaration::semantic3(Scope *sc)
15761580
stc |= STCparameter;
15771581
if (f->varargs == 2 && i + 1 == nparams)
15781582
stc |= STCvariadic;
1579-
if (flags & FUNCFLAGinferScope)
1583+
if (flags & FUNCFLAGinferScope && !(fparam->storageClass & STCscope))
15801584
stc |= STCmaybescope;
15811585
stc |= fparam->storageClass & (STCin | STCout | STCref | STCreturn | STCscope | STClazy | STCfinal | STC_TYPECTOR | STCnodtor);
15821586
v->storage_class = stc;
@@ -2485,7 +2489,7 @@ VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad
24852489
if (tf->isscope)
24862490
v->storage_class |= STCscope;
24872491
}
2488-
if (flags & FUNCFLAGinferScope)
2492+
if (flags & FUNCFLAGinferScope && !(v->storage_class & STCscope))
24892493
v->storage_class |= STCmaybescope;
24902494

24912495
v->semantic(sc);
@@ -2511,7 +2515,7 @@ VarDeclaration *FuncDeclaration::declareThis(Scope *sc, AggregateDeclaration *ad
25112515
if (tf->isscope)
25122516
v->storage_class |= STCscope;
25132517
}
2514-
if (flags & FUNCFLAGinferScope)
2518+
if (flags & FUNCFLAGinferScope && !(v->storage_class & STCscope))
25152519
v->storage_class |= STCmaybescope;
25162520

25172521
v->semantic(sc);

gcc/d/dfrontend/mtype.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6048,8 +6048,7 @@ MATCH TypeFunction::callMatch(Type *tthis, Expressions *args, int flag)
60486048
{
60496049
if (MODimplicitConv(t->mod, mod))
60506050
match = MATCHconst;
6051-
else if ((mod & MODwild)
6052-
&& MODimplicitConv(t->mod, (mod & ~MODwild) | MODconst))
6051+
else if ((mod & MODwild) && MODimplicitConv(t->mod, (mod & ~MODwild) | MODconst))
60536052
{
60546053
match = MATCHconst;
60556054
}
@@ -6223,12 +6222,12 @@ MATCH TypeFunction::callMatch(Type *tthis, Expressions *args, int flag)
62236222

62246223
switch (tb->ty)
62256224
{
6226-
case Tsarray:
6227-
tsa = (TypeSArray *)tb;
6228-
sz = tsa->dim->toInteger();
6229-
if (sz != nargs - u)
6230-
goto Nomatch;
6231-
case Tarray:
6225+
case Tsarray:
6226+
tsa = (TypeSArray *)tb;
6227+
sz = tsa->dim->toInteger();
6228+
if (sz != nargs - u)
6229+
goto Nomatch;
6230+
case Tarray:
62326231
{
62336232
TypeArray *ta = (TypeArray *)tb;
62346233
for (; u < nargs; u++)
@@ -6263,13 +6262,13 @@ MATCH TypeFunction::callMatch(Type *tthis, Expressions *args, int flag)
62636262
}
62646263
goto Ldone;
62656264
}
6266-
case Tclass:
6267-
// Should see if there's a constructor match?
6268-
// Or just leave it ambiguous?
6269-
goto Ldone;
6265+
case Tclass:
6266+
// Should see if there's a constructor match?
6267+
// Or just leave it ambiguous?
6268+
goto Ldone;
62706269

6271-
default:
6272-
goto Nomatch;
6270+
default:
6271+
goto Nomatch;
62736272
}
62746273
}
62756274
goto Nomatch;

libphobos/libdruntime/core/runtime.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ extern (C) bool runModuleUnitTests()
491491
// First frame is LibBacktrace ctor. Second is signal handler, but include that for now
492492
bt.__ctor(1);
493493

494-
foreach(size_t i, const(char[]) msg; bt)
494+
foreach (size_t i, const(char[]) msg; bt)
495495
fprintf(stderr, "%s\n", msg.ptr ? msg.ptr : "???");
496496
}
497497

libphobos/libdruntime/gcc/backtrace.d

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static if (BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC)
153153
/*
154154
* The callback type used with the opApply overload which returns a SymbolOrError
155155
*/
156-
private alias scope int delegate(ref size_t, ref SymbolOrError) ApplyCallback;
156+
private alias int delegate(ref size_t, ref SymbolOrError) ApplyCallback;
157157

158158
/*
159159
* Passed to syminfoCallback, pcinfoCallback and pcinfoErrorCallback
@@ -228,20 +228,20 @@ static if (BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC)
228228

229229
override int opApply(scope int delegate(ref const(char[])) dg) const
230230
{
231-
return opApply((ref size_t, ref const(char[]) buf)
231+
return opApply( (ref size_t, ref const(char[]) buf)
232232
{
233233
return dg(buf);
234234
});
235235
}
236236

237237
override int opApply(scope int delegate(ref size_t, ref const(char[])) dg) const
238238
{
239-
return opApply((ref size_t i, ref SymbolOrError sym)
239+
return opApply( (ref size_t i, ref SymbolOrError sym)
240240
{
241-
char[512] buffer = '\0';
242-
char[] msg;
243-
if (sym.errnum != 0)
244-
{
241+
char[512] buffer = '\0';
242+
char[] msg;
243+
if (sym.errnum != 0)
244+
{
245245
auto retval = snprintf(buffer.ptr, buffer.length,
246246
"libbacktrace error: '%s' errno: %d", sym.msg, sym.errnum);
247247
if (retval >= buffer.length)
@@ -257,7 +257,7 @@ static if (BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC)
257257
});
258258
}
259259

260-
int opApply(ApplyCallback dg) const
260+
int opApply(scope ApplyCallback dg) const
261261
{
262262
//If backtrace_simple produced an error report it and exit
263263
if (!state || error != 0)
@@ -352,7 +352,7 @@ else
352352

353353
override int opApply(scope int delegate(ref const(char[])) dg) const
354354
{
355-
return opApply((ref size_t, ref const(char[]) buf)
355+
return opApply( (ref size_t, ref const(char[]) buf)
356356
{
357357
return dg(buf);
358358
});
@@ -485,7 +485,7 @@ struct SymbolInfo
485485
* Format one output line for symbol sym.
486486
* Returns a slice of fixbuf.
487487
*/
488-
char[] formatLine(const SymbolInfo sym, ref char[512] fixbuf)
488+
char[] formatLine(const SymbolInfo sym, return ref char[512] fixbuf)
489489
{
490490
import core.demangle, core.stdc.config;
491491
import core.stdc.stdio : snprintf, printf;

0 commit comments

Comments
 (0)