diff options
Diffstat (limited to 'gcc')
39 files changed, 442 insertions, 181 deletions
diff --git a/gcc/d/dmd/MERGE b/gcc/d/dmd/MERGE index d39658a808e..d1e3dc16312 100644 --- a/gcc/d/dmd/MERGE +++ b/gcc/d/dmd/MERGE @@ -1,4 +1,4 @@ -821ed393d428c7db5a48623e77d43f5647d5c6a2 +6203135dcf0112d3211add0cbfb22fecc5df1af4 The first line of this file holds the git revision number of the last merge done from the dlang/dmd repository. diff --git a/gcc/d/dmd/aggregate.h b/gcc/d/dmd/aggregate.h index f27ca0769c9..d91e35ee8c2 100644 --- a/gcc/d/dmd/aggregate.h +++ b/gcc/d/dmd/aggregate.h @@ -159,17 +159,6 @@ struct StructFlags class StructDeclaration : public AggregateDeclaration { public: - bool zeroInit; // !=0 if initialize with 0 fill - bool hasIdentityAssign; // true if has identity opAssign - bool hasBlitAssign; // true if opAssign is a blit - bool hasIdentityEquals; // true if has identity opEquals - bool hasNoFields; // has no fields - bool hasCopyCtor; // copy constructor - // Even if struct is defined as non-root symbol, some built-in operations - // (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo. - // For those, today TypeInfo_Struct is generated in COMDAT. - bool requestTypeInfo; - FuncDeclarations postblits; // Array of postblit functions FuncDeclaration *postblit; // aggregate postblit @@ -179,18 +168,37 @@ public: static FuncDeclaration *xerreq; // object.xopEquals static FuncDeclaration *xerrcmp; // object.xopCmp - structalign_t alignment; // alignment applied outside of the struct - ThreeState ispod; // if struct is POD - // ABI-specific type(s) if the struct can be passed in registers TypeTuple *argTypes; + structalign_t alignment; // alignment applied outside of the struct + ThreeState ispod; // if struct is POD +private: + uint8_t bitFields; +public: static StructDeclaration *create(const Loc &loc, Identifier *id, bool inObject); StructDeclaration *syntaxCopy(Dsymbol *s) override; Dsymbol *search(const Loc &loc, Identifier *ident, int flags = SearchLocalsOnly) override final; const char *kind() const override; void finalizeSize() override final; bool isPOD(); + bool zeroInit() const; // !=0 if initialize with 0 fill + bool zeroInit(bool v); + bool hasIdentityAssign() const; // true if has identity opAssign + bool hasIdentityAssign(bool v); + bool hasBlitAssign() const; // true if opAssign is a blit + bool hasBlitAssign(bool v); + bool hasIdentityEquals() const; // true if has identity opEquals + bool hasIdentityEquals(bool v); + bool hasNoFields() const; // has no fields + bool hasNoFields(bool v); + bool hasCopyCtor() const; // copy constructor + bool hasCopyCtor(bool v); + // Even if struct is defined as non-root symbol, some built-in operations + // (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo. + // For those, today TypeInfo_Struct is generated in COMDAT. + bool requestTypeInfo() const; + bool requestTypeInfo(bool v); StructDeclaration *isStructDeclaration() override final { return this; } void accept(Visitor *v) override { v->visit(this); } diff --git a/gcc/d/dmd/clone.d b/gcc/d/dmd/clone.d index 75a16bd2da4..cf4ccbb955c 100644 --- a/gcc/d/dmd/clone.d +++ b/gcc/d/dmd/clone.d @@ -404,7 +404,12 @@ bool needOpEquals(StructDeclaration sd) { //printf("StructDeclaration::needOpEquals() %s\n", sd.toChars()); if (sd.isUnionDeclaration()) - goto Ldontneed; + { + /* If a union has only one field, treat it like a struct + */ + if (sd.fields.length != 1) + goto Ldontneed; + } if (sd.hasIdentityEquals) goto Lneed; /* If any of the fields has an opEquals, then we @@ -421,7 +426,7 @@ bool needOpEquals(StructDeclaration sd) if (tvbase.ty == Tstruct) { TypeStruct ts = cast(TypeStruct)tvbase; - if (ts.sym.isUnionDeclaration()) + if (ts.sym.isUnionDeclaration() && ts.sym.fields.length != 1) continue; if (needOpEquals(ts.sym)) goto Lneed; diff --git a/gcc/d/dmd/denum.d b/gcc/d/dmd/denum.d index aba290bed05..ef322f13da5 100644 --- a/gcc/d/dmd/denum.d +++ b/gcc/d/dmd/denum.d @@ -54,9 +54,17 @@ extern (C++) final class EnumDeclaration : ScopeDsymbol Expression maxval; Expression minval; Expression defaultval; // default initializer - bool isdeprecated; - bool added; - int inuse; + + // `bool` fields that are compacted into bit fields in a string mixin + private extern (D) static struct BitFields + { + bool isdeprecated; + bool added; + bool inuse; + } + + import dmd.common.bitfields : generateBitFields; + mixin(generateBitFields!(BitFields, ubyte)); extern (D) this(const ref Loc loc, Identifier ident, Type memtype) { diff --git a/gcc/d/dmd/dstruct.d b/gcc/d/dmd/dstruct.d index de5f1453c9a..4126a8adc68 100644 --- a/gcc/d/dmd/dstruct.d +++ b/gcc/d/dmd/dstruct.d @@ -192,17 +192,6 @@ enum StructFlags : int */ extern (C++) class StructDeclaration : AggregateDeclaration { - bool zeroInit; // !=0 if initialize with 0 fill - bool hasIdentityAssign; // true if has identity opAssign - bool hasBlitAssign; // true if opAssign is a blit - bool hasIdentityEquals; // true if has identity opEquals - bool hasNoFields; // has no fields - bool hasCopyCtor; // copy constructor - // Even if struct is defined as non-root symbol, some built-in operations - // (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo. - // For those, today TypeInfo_Struct is generated in COMDAT. - bool requestTypeInfo; - FuncDeclarations postblits; // Array of postblit functions FuncDeclaration postblit; // aggregate postblit @@ -212,11 +201,29 @@ extern (C++) class StructDeclaration : AggregateDeclaration extern (C++) __gshared FuncDeclaration xerreq; // object.xopEquals extern (C++) __gshared FuncDeclaration xerrcmp; // object.xopCmp + // ABI-specific type(s) if the struct can be passed in registers + TypeTuple argTypes; + structalign_t alignment; // alignment applied outside of the struct ThreeState ispod; // if struct is POD - // ABI-specific type(s) if the struct can be passed in registers - TypeTuple argTypes; + // `bool` fields that are compacted into bit fields in a string mixin + private extern (D) static struct BitFields + { + bool zeroInit; // !=0 if initialize with 0 fill + bool hasIdentityAssign; // true if has identity opAssign + bool hasBlitAssign; // true if opAssign is a blit + bool hasIdentityEquals; // true if has identity opEquals + bool hasNoFields; // has no fields + bool hasCopyCtor; // copy constructor + // Even if struct is defined as non-root symbol, some built-in operations + // (e.g. TypeidExp, NewExp, ArrayLiteralExp, etc) request its TypeInfo. + // For those, today TypeInfo_Struct is generated in COMDAT. + bool requestTypeInfo; + } + + import dmd.common.bitfields : generateBitFields; + mixin(generateBitFields!(BitFields, ubyte)); extern (D) this(const ref Loc loc, Identifier id, bool inObject) { diff --git a/gcc/d/dmd/dsymbolsem.d b/gcc/d/dmd/dsymbolsem.d index 6dbc129baaf..7fd47818759 100644 --- a/gcc/d/dmd/dsymbolsem.d +++ b/gcc/d/dmd/dsymbolsem.d @@ -49,6 +49,7 @@ import dmd.identifier; import dmd.importc; import dmd.init; import dmd.initsem; +import dmd.intrange; import dmd.hdrgen; import dmd.mtype; import dmd.mustuse; @@ -2177,6 +2178,13 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor assert(ed.memtype); int nextValue = 0; // C11 6.7.2.2-3 first member value defaults to 0 + // C11 6.7.2.2-2 value must be representable as an int. + // The sizemask represents all values that int will fit into, + // from 0..uint.max. We want to cover int.min..uint.max. + const mask = Type.tint32.sizemask(); + IntRange ir = IntRange(SignExtendedNumber(~(mask >> 1), true), + SignExtendedNumber(mask)); + void emSemantic(EnumMember em, ref int nextValue) { static void errorReturn(EnumMember em) @@ -2206,21 +2214,32 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor em.error("enum member must be an integral constant expression, not `%s` of type `%s`", e.toChars(), e.type.toChars()); return errorReturn(em); } - const sinteger_t v = ie.toInteger(); - if (v < int.min || v > uint.max) + if (!ir.contains(getIntRange(ie))) { // C11 6.7.2.2-2 em.error("enum member value `%s` does not fit in an `int`", e.toChars()); return errorReturn(em); } - em.value = new IntegerExp(em.loc, cast(int)v, Type.tint32); - nextValue = cast(int)v; + nextValue = cast(int)ie.toInteger(); + em.value = new IntegerExp(em.loc, nextValue, Type.tint32); } else { + // C11 6.7.2.2-3 add 1 to value of previous enumeration constant + bool first = (em == (*em.ed.members)[0]); + if (!first) + { + import core.checkedint : adds; + bool overflow; + nextValue = adds(nextValue, 1, overflow); + if (overflow) + { + em.error("initialization with `%d+1` causes overflow for type `int`", nextValue - 1); + return errorReturn(em); + } + } em.value = new IntegerExp(em.loc, nextValue, Type.tint32); } - ++nextValue; // C11 6.7.2.2-3 add 1 to value of previous enumeration constant em.semanticRun = PASS.semanticdone; } diff --git a/gcc/d/dmd/enum.h b/gcc/d/dmd/enum.h index 9ec130099fe..723cebc7e0a 100644 --- a/gcc/d/dmd/enum.h +++ b/gcc/d/dmd/enum.h @@ -35,10 +35,15 @@ public: Expression *maxval; Expression *minval; Expression *defaultval; // default initializer - - bool isdeprecated; - bool added; - int inuse; +private: + uint8_t bitFields; +public: + bool isdeprecated() const; + bool isdeprecated(bool v); + bool added() const; + bool added(bool v); + bool inuse() const; + bool inuse(bool v); EnumDeclaration *syntaxCopy(Dsymbol *s) override; void addMember(Scope *sc, ScopeDsymbol *sds) override; diff --git a/gcc/d/dmd/escape.d b/gcc/d/dmd/escape.d index 97a655289b5..0646f57c5cd 100644 --- a/gcc/d/dmd/escape.d +++ b/gcc/d/dmd/escape.d @@ -328,12 +328,12 @@ bool checkParamArgumentEscape(Scope* sc, FuncDeclaration fdc, Parameter par, STC else if (par) { result |= sc.setUnsafeDIP1000(gag, arg.loc, - desc ~ " `%s` assigned to non-scope parameter `%s`", v, par); + desc ~ " `%s` assigned to non-scope parameter `%s` calling `%s`", v, par, fdc); } else { result |= sc.setUnsafeDIP1000(gag, arg.loc, - desc ~ " `%s` assigned to non-scope parameter `this`", v); + desc ~ " `%s` assigned to non-scope parameter `this` calling `%s`", v, fdc); } } @@ -1230,9 +1230,24 @@ private bool checkReturnEscapeImpl(Scope* sc, Expression e, bool refs, bool gag) !(!refs && sc.func.isFuncDeclaration().getLevel(pfunc, sc.intypeof) > 0) ) { - // https://issues.dlang.org/show_bug.cgi?id=17029 - result |= sc.setUnsafeDIP1000(gag, e.loc, "scope variable `%s` may not be returned", v); - continue; + if (v.isParameter() && !(v.storage_class & STC.return_)) + { + // https://issues.dlang.org/show_bug.cgi?id=23191 + if (!gag) + { + previewErrorFunc(sc.isDeprecated(), global.params.useDIP1000)(e.loc, + "scope parameter `%s` may not be returned", v.toChars() + ); + result = true; + continue; + } + } + else + { + // https://issues.dlang.org/show_bug.cgi?id=17029 + result |= sc.setUnsafeDIP1000(gag, e.loc, "scope variable `%s` may not be returned", v); + continue; + } } } else if (v.storage_class & STC.variadic && p == sc.func) @@ -2492,9 +2507,11 @@ private void addMaybe(VarDeclaration va, VarDeclaration v) * fmt = printf-style format string * arg0 = (optional) argument for first %s format specifier * arg1 = (optional) argument for second %s format specifier + * arg2 = (optional) argument for third %s format specifier * Returns: whether an actual safe error (not deprecation) occured */ -private bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* msg, RootObject arg0 = null, RootObject arg1 = null) +private bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, const(char)* msg, + RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null) { if (fs == FeatureState.disabled) { @@ -2502,7 +2519,7 @@ private bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, con } else if (fs == FeatureState.enabled) { - return sc.setUnsafe(gag, loc, msg, arg0, arg1); + return sc.setUnsafe(gag, loc, msg, arg0, arg1, arg2); } else { @@ -2510,22 +2527,23 @@ private bool setUnsafePreview(Scope* sc, FeatureState fs, bool gag, Loc loc, con { if (!gag) previewErrorFunc(sc.isDeprecated(), fs)( - loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "" + loc, msg, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : "" ); } else if (!sc.func.safetyViolation) { import dmd.func : AttributeViolation; - sc.func.safetyViolation = new AttributeViolation(loc, msg, arg0, arg1); + sc.func.safetyViolation = new AttributeViolation(loc, msg, arg0, arg1, arg2); } return false; } } // `setUnsafePreview` partially evaluated for dip1000 -private bool setUnsafeDIP1000(Scope* sc, bool gag, Loc loc, const(char)* msg, RootObject arg0 = null, RootObject arg1 = null) +private bool setUnsafeDIP1000(Scope* sc, bool gag, Loc loc, const(char)* msg, + RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null) { - return setUnsafePreview(sc, global.params.useDIP1000, gag, loc, msg, arg0, arg1); + return setUnsafePreview(sc, global.params.useDIP1000, gag, loc, msg, arg0, arg1, arg2); } /*************************************** diff --git a/gcc/d/dmd/expression.d b/gcc/d/dmd/expression.d index 4d171059306..ceecf4b5e74 100644 --- a/gcc/d/dmd/expression.d +++ b/gcc/d/dmd/expression.d @@ -1438,7 +1438,7 @@ extern (C++) abstract class Expression : ASTNode else if (!sc.func.safetyViolation) { import dmd.func : AttributeViolation; - sc.func.safetyViolation = new AttributeViolation(this.loc, null, f, null); + sc.func.safetyViolation = new AttributeViolation(this.loc, null, f, null, null); } } return false; diff --git a/gcc/d/dmd/func.d b/gcc/d/dmd/func.d index d42925990a9..83bc2eab1fe 100644 --- a/gcc/d/dmd/func.d +++ b/gcc/d/dmd/func.d @@ -1476,17 +1476,19 @@ extern (C++) class FuncDeclaration : Declaration * fmt = printf-style format string * arg0 = (optional) argument for first %s format specifier * arg1 = (optional) argument for second %s format specifier + * arg2 = (optional) argument for third %s format specifier * Returns: whether there's a safe error */ extern (D) final bool setUnsafe( - bool gag = false, Loc loc = Loc.init, const(char)* fmt = null, RootObject arg0 = null, RootObject arg1 = null) + bool gag = false, Loc loc = Loc.init, const(char)* fmt = null, + RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null) { if (flags & FUNCFLAG.safetyInprocess) { flags &= ~FUNCFLAG.safetyInprocess; type.toTypeFunction().trust = TRUST.system; if (fmt || arg0) - safetyViolation = new AttributeViolation(loc, fmt, arg0, arg1); + safetyViolation = new AttributeViolation(loc, fmt, arg0, arg1, arg2); if (fes) fes.func.setUnsafe(); @@ -1494,7 +1496,7 @@ extern (C++) class FuncDeclaration : Declaration else if (isSafe()) { if (!gag && fmt) - .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : ""); + .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : ""); return true; } @@ -4370,10 +4372,12 @@ extern (C++) final class NewDeclaration : FuncDeclaration * fmt = printf-style format string * arg0 = (optional) argument for first %s format specifier * arg1 = (optional) argument for second %s format specifier + * arg2 = (optional) argument for third %s format specifier * Returns: whether there's a safe error */ bool setUnsafe(Scope* sc, - bool gag = false, Loc loc = Loc.init, const(char)* fmt = null, RootObject arg0 = null, RootObject arg1 = null) + bool gag = false, Loc loc = Loc.init, const(char)* fmt = null, + RootObject arg0 = null, RootObject arg1 = null, RootObject arg2 = null) { // TODO: // For @system variables, unsafe initializers at global scope should mark @@ -4394,13 +4398,13 @@ bool setUnsafe(Scope* sc, { // Message wil be gagged, but still call error() to update global.errors and for // -verrors=spec - .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : ""); + .error(loc, fmt, arg0 ? arg0.toChars() : "", arg1 ? arg1.toChars() : "", arg2 ? arg2.toChars() : ""); return true; } return false; } - return sc.func.setUnsafe(gag, loc, fmt, arg0, arg1); + return sc.func.setUnsafe(gag, loc, fmt, arg0, arg1, arg2); } /// Stores a reason why a function failed to infer a function attribute like `@safe` or `pure` @@ -4421,6 +4425,8 @@ struct AttributeViolation RootObject arg0 = null; /// ditto RootObject arg1 = null; + /// ditto + RootObject arg2 = null; } /// Print the reason why `fd` was inferred `@system` as a supplemental error @@ -4438,7 +4444,8 @@ void errorSupplementalInferredSafety(FuncDeclaration fd, int maxDepth, bool depr errorFunc(s.loc, deprecation ? "which would be `@system` because of:" : "which was inferred `@system` because of:"); - errorFunc(s.loc, s.fmtStr, s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : ""); + errorFunc(s.loc, s.fmtStr, + s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : ""); } else if (FuncDeclaration fd2 = cast(FuncDeclaration) s.arg0) { diff --git a/gcc/d/dmd/parse.d b/gcc/d/dmd/parse.d index 89f8ae3470f..eb5e6942948 100644 --- a/gcc/d/dmd/parse.d +++ b/gcc/d/dmd/parse.d @@ -4862,7 +4862,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer if (udas !is null) { if (storage_class != 0) - error("cannot put a storage-class in an alias declaration."); + error("cannot put a storage-class in an `alias` declaration."); // parseAttributes shouldn't have set these variables assert(link == linkage && !setAlignment && ealign is null); auto tpl_ = cast(AST.TemplateDeclaration) s; @@ -4887,7 +4887,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer parseAttributes(); // type if (udas) - error("user-defined attributes not allowed for alias declarations"); + error("user-defined attributes not allowed for `alias` declarations"); auto t = parseType(); diff --git a/gcc/d/dmd/statementsem.d b/gcc/d/dmd/statementsem.d index 06e28a4819d..f23b9882ae0 100644 --- a/gcc/d/dmd/statementsem.d +++ b/gcc/d/dmd/statementsem.d @@ -4401,19 +4401,21 @@ public auto makeTupleForeach(Scope* sc, bool isStatic, bool isDecl, ForeachState Dsymbol ds = null; if (!(storageClass & STC.manifest)) { - if ((isStatic || tb.ty == Tfunction || storageClass&STC.alias_) && e.op == EXP.variable) - ds = (cast(VarExp)e).var; - else if (e.op == EXP.template_) - ds = (cast(TemplateExp)e).td; - else if (e.op == EXP.scope_) - ds = (cast(ScopeExp)e).sds; - else if (e.op == EXP.function_) + if (isStatic || tb.ty == Tfunction || storageClass & STC.alias_) { - auto fe = cast(FuncExp)e; - ds = fe.td ? cast(Dsymbol)fe.td : fe.fd; + if (auto ve = e.isVarExp()) + ds = ve.var; + else if (auto dve = e.isDotVarExp()) + ds = dve.var; } - else if (e.op == EXP.overloadSet) - ds = (cast(OverExp)e).vars; + if (auto te = e.isTemplateExp()) + ds = te.td; + else if (auto se = e.isScopeExp()) + ds = se.sds; + else if (auto fe = e.isFuncExp()) + ds = fe.td ? fe.td : fe.fd; + else if (auto oe = e.isOverExp()) + ds = oe.vars; } else if (storageClass & STC.alias_) { @@ -4530,6 +4532,7 @@ public auto makeTupleForeach(Scope* sc, bool isStatic, bool isDecl, ForeachState auto field = Identifier.idPool(StaticForeach.tupleFieldName.ptr,StaticForeach.tupleFieldName.length); Expression access = new DotIdExp(loc, e, field); access = expressionSemantic(access, sc); + access = access.optimize(WANTvalue); if (!tuple) return returnEarly(); //printf("%s\n",tuple.toChars()); foreach (l; 0 .. dim) diff --git a/gcc/d/dmd/typesem.d b/gcc/d/dmd/typesem.d index 31ecbd246e6..8cacdb10a26 100644 --- a/gcc/d/dmd/typesem.d +++ b/gcc/d/dmd/typesem.d @@ -119,7 +119,7 @@ private void resolveTupleIndex(const ref Loc loc, Scope* sc, Dsymbol s, out Expr const(uinteger_t) d = eindex.toUInteger(); if (d >= tup.objects.dim) { - .error(loc, "tuple index `%llu` exceeds length %llu", d, cast(ulong)tup.objects.dim); + .error(loc, "tuple index `%llu` out of bounds `[0 .. %llu]`", d, cast(ulong)tup.objects.dim); pt = Type.terror; return; } @@ -554,7 +554,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) uinteger_t d = mtype.dim.toUInteger(); if (d >= tup.objects.dim) { - .error(loc, "tuple index %llu exceeds %llu", cast(ulong)d, cast(ulong)tup.objects.dim); + .error(loc, "tuple index `%llu` out of bounds `[0 .. %llu]`", cast(ulong)d, cast(ulong)tup.objects.dim); return error(); } @@ -649,7 +649,7 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) uinteger_t d = mtype.dim.toUInteger(); if (d >= tt.arguments.dim) { - .error(loc, "tuple index %llu exceeds %llu", cast(ulong)d, cast(ulong)tt.arguments.dim); + .error(loc, "tuple index `%llu` out of bounds `[0 .. %llu]`", cast(ulong)d, cast(ulong)tt.arguments.dim); return error(); } Type telem = (*tt.arguments)[cast(size_t)d].type; @@ -1224,6 +1224,25 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) continue; } + // -preview=in: Always add `ref` when used with `extern(C++)` functions + // Done here to allow passing opaque types with `in` + if (global.params.previewIn && (fparam.storageClass & (STC.in_ | STC.ref_)) == STC.in_) + { + switch (tf.linkage) + { + case LINK.cpp: + fparam.storageClass |= STC.ref_; + break; + case LINK.default_, LINK.d: + break; + default: + .error(loc, "cannot use `in` parameters with `extern(%s)` functions", + linkageToChars(tf.linkage)); + .errorSupplemental(loc, "parameter `%s` declared as `in` here", fparam.toChars()); + break; + } + } + if (t.ty == Tfunction) { .error(loc, "cannot have parameter of function type `%s`", fparam.type.toChars()); @@ -2572,7 +2591,7 @@ void resolve(Type mt, const ref Loc loc, Scope* sc, out Expression pe, out Type const d = mt.dim.toUInteger(); if (d >= tup.objects.dim) { - error(loc, "tuple index `%llu` exceeds length %llu", d, cast(ulong) tup.objects.dim); + error(loc, "tuple index `%llu` out of bounds `[0 .. %llu]`", d, cast(ulong) tup.objects.dim); return returnError(); } @@ -4891,9 +4910,9 @@ Expression getMaxMinValue(EnumDeclaration ed, const ref Loc loc, Identifier id) */ Expression e = em.value; Expression ec = new CmpExp(id == Id.max ? EXP.greaterThan : EXP.lessThan, em.loc, e, *pval); - ed.inuse++; + ed.inuse = true; ec = ec.expressionSemantic(em._scope); - ed.inuse--; + ed.inuse = false; ec = ec.ctfeInterpret(); if (ec.op == EXP.error) { diff --git a/gcc/d/typeinfo.cc b/gcc/d/typeinfo.cc index 1f8afdd2c74..d1f0d59952f 100644 --- a/gcc/d/typeinfo.cc +++ b/gcc/d/typeinfo.cc @@ -1050,7 +1050,7 @@ public: this->layout_string (ti->deco); /* Default initializer for struct. */ - tree ptr = (sd->zeroInit) ? null_pointer_node + tree ptr = (sd->zeroInit ()) ? null_pointer_node : build_address (aggregate_initializer_decl (sd)); this->layout_field (d_array_value (array_type_node, size_int (sd->structsize), ptr)); @@ -1771,7 +1771,7 @@ public: { if (!ti->needsCodegen ()) { - if (ti->minst || sd->requestTypeInfo) + if (ti->minst || sd->requestTypeInfo ()) return; this->result_ |= true; diff --git a/gcc/testsuite/gdc.test/compilable/b16360.d b/gcc/testsuite/gdc.test/compilable/b16360.d deleted file mode 100644 index 11415791b65..00000000000 --- a/gcc/testsuite/gdc.test/compilable/b16360.d +++ /dev/null @@ -1,39 +0,0 @@ -/* -REQUIRED_ARGS: -inline -wi - -TEST_OUTPUT: ---- -compilable/b16360.d(12): Warning: cannot inline function `b16360.foo` -compilable/b16360.d(25): Warning: cannot inline function `b16360.bar` ---- -*/ - -pragma(inline, true) -auto foo() -{ - static struct U - { - int a = 42; - float b; - ~this(){} // __dtor: inline not allowed - } - U u; - return u.a; -} - -pragma(inline, true) -auto bar() -{ - class U // class : inline not allowed - { - int a = 42; - float b; - } - return (new U).a; -} - -void main() -{ - auto f = foo(); - auto b = bar(); -} diff --git a/gcc/testsuite/gdc.test/compilable/inliner.d b/gcc/testsuite/gdc.test/compilable/inliner.d new file mode 100644 index 00000000000..1273809b8db --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/inliner.d @@ -0,0 +1,21 @@ +// REQUIRED_ARGS: -inline -O -unittest + +struct Cent +{ + ulong lo; + ulong hi; +} + +Cent add(Cent, Cent); + +Cent sub(Cent c1, Cent c2) +{ + return add(c1, c2); +} + +Cent udivmod(Cent c3, Cent c4) +{ + Cent quotient; + Cent rem = sub(c3, c4); + return quotient; +} diff --git a/gcc/testsuite/gdc.test/compilable/inliner2.d b/gcc/testsuite/gdc.test/compilable/inliner2.d new file mode 100644 index 00000000000..7ffa5cca31b --- /dev/null +++ b/gcc/testsuite/gdc.test/compilable/inliner2.d @@ -0,0 +1,27 @@ +// REQUIRED_ARGS: -O -inline + +struct Cent +{ + ulong lo; // low 64 bits + ulong hi; // high 64 bits +} + +pure bool tst(Cent c) +{ + return c.hi || c.lo; +} + +pure Cent dec(Cent c); +pure Cent shl(Cent c, uint n); + +pure Cent udivmod(Cent c1, Cent c2, out Cent modulus) +{ + ulong v1 = shl(c2, 3).hi; + + Cent quotient; + + if (tst(quotient)) + quotient = dec(quotient); + + return quotient; +} diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail17927.d b/gcc/testsuite/gdc.test/fail_compilation/fail17927.d index 410f3077706..cf610ff8d97 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail17927.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail17927.d @@ -1,10 +1,10 @@ /* REQUIRED_ARGS: -preview=dip1000 * TEST_OUTPUT: --- -fail_compilation/fail17927.d(13): Error: scope variable `this` may not be returned -fail_compilation/fail17927.d(15): Error: scope variable `this` may not be returned -fail_compilation/fail17927.d(21): Error: scope variable `ptr` may not be returned -fail_compilation/fail17927.d(23): Error: scope variable `ptr` may not be returned +fail_compilation/fail17927.d(13): Error: scope parameter `this` may not be returned +fail_compilation/fail17927.d(15): Error: scope parameter `this` may not be returned +fail_compilation/fail17927.d(21): Error: scope parameter `ptr` may not be returned +fail_compilation/fail17927.d(23): Error: scope parameter `ptr` may not be returned --- */ // https://issues.dlang.org/show_bug.cgi?id=17927 diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail20108.d b/gcc/testsuite/gdc.test/fail_compilation/fail20108.d index f768b89e6a4..15845e1d2fc 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail20108.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail20108.d @@ -3,7 +3,7 @@ TEST_OUTPUT: --- fail_compilation/fail20108.d(15): Error: address of variable `y` assigned to `x` with longer lifetime -fail_compilation/fail20108.d(16): Error: scope variable `x` may not be returned +fail_compilation/fail20108.d(16): Error: scope parameter `x` may not be returned fail_compilation/fail20108.d(23): Error: address of variable `y` assigned to `x` with longer lifetime fail_compilation/fail20108.d(24): Error: scope variable `x` may not be returned --- diff --git a/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d b/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d index 3e7637ff667..3fac1678e69 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d +++ b/gcc/testsuite/gdc.test/fail_compilation/fail_scope.d @@ -2,7 +2,10 @@ REQUIRED_ARGS: TEST_OUTPUT: --- -fail_compilation/fail_scope.d(40): Deprecation: scope variable `p` may not be returned +fail_compilation/fail_scope.d(30): Deprecation: scope parameter `da` may not be returned +fail_compilation/fail_scope.d(32): Deprecation: scope parameter `o` may not be returned +fail_compilation/fail_scope.d(33): Deprecation: scope parameter `dg` may not be returned +fail_compilation/fail_scope.d(40): Deprecation: scope parameter `p` may not be returned fail_compilation/fail_scope.d(45): Error: returning `cast(char[])string` escapes a reference to local variable `string` fail_compilation/fail_scope.d(63): Error: returning `s.bar()` escapes a reference to local variable `s` fail_compilation/fail_scope.d(74): Error: `fail_scope.foo8` called with argument types `(int)` matches both: @@ -16,9 +19,6 @@ fail_compilation/fail_scope.d(108): Deprecation: escaping reference to outer loc fail_compilation/fail_scope.d(127): Deprecation: returning `s.bar()` escapes a reference to local variable `s` fail_compilation/fail_scope.d(137): Error: returning `foo16226(i)` escapes a reference to local variable `i` --- -//fail_compilation/fail_scope.d(30): Error: scope variable `da` may not be returned -//fail_compilation/fail_scope.d(32): Error: scope variable `o` may not be returned -//fail_compilation/fail_scope.d(33): Error: scope variable `dg` may not be returned //fail_compilation/fail_scope.d(35): Error: scope variable `da` may not be returned //fail_compilation/fail_scope.d(37): Error: scope variable `o` may not be returned //fail_compilation/fail_scope.d(38): Error: scope variable `dg` may not be returned diff --git a/gcc/testsuite/gdc.test/fail_compilation/ice12574.d b/gcc/testsuite/gdc.test/fail_compilation/ice12574.d index 420b6b70078..93e5f1d8cc0 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/ice12574.d +++ b/gcc/testsuite/gdc.test/fail_compilation/ice12574.d @@ -1,7 +1,7 @@ /* TEST_OUTPUT: --- -fail_compilation/ice12574.d(40): Error: tuple index `2` exceeds length 2 +fail_compilation/ice12574.d(40): Error: tuple index `2` out of bounds `[0 .. 2]` fail_compilation/ice12574.d(53): Error: template instance `ice12574.reduce!("a", "a").reduce!(Tuple!(int, int, int))` error instantiating --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/previewin.d b/gcc/testsuite/gdc.test/fail_compilation/previewin.d index b3beaf4c9d8..ce0cf926a13 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/previewin.d +++ b/gcc/testsuite/gdc.test/fail_compilation/previewin.d @@ -10,7 +10,7 @@ fail_compilation/previewin.d(6): Error: function `previewin.takeFunction(void fu fail_compilation/previewin.d(6): cannot pass argument `__lambda3` of type `void function(ref const(real) x) pure nothrow @nogc @safe` to parameter `void function(in real) f` fail_compilation/previewin.d(15): Error: scope variable `arg` assigned to non-scope `myGlobal` fail_compilation/previewin.d(16): Error: scope variable `arg` assigned to non-scope `myGlobal` -fail_compilation/previewin.d(17): Error: scope variable `arg` may not be returned +fail_compilation/previewin.d(17): Error: scope parameter `arg` may not be returned fail_compilation/previewin.d(18): Error: scope variable `arg` assigned to `escape` with longer lifetime fail_compilation/previewin.d(22): Error: returning `arg` escapes a reference to parameter `arg` fail_compilation/previewin.d(22): perhaps annotate the parameter with `return` diff --git a/gcc/testsuite/gdc.test/fail_compilation/previewin2.d b/gcc/testsuite/gdc.test/fail_compilation/previewin2.d new file mode 100644 index 00000000000..e9fe6a1fa88 --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/previewin2.d @@ -0,0 +1,18 @@ +/* +REQUIRED_ARGS: -preview=in -preview=dip1000 +TEST_OUTPUT: +--- +fail_compilation/previewin2.d(1): Error: cannot use `in` parameters with `extern(C)` functions +fail_compilation/previewin2.d(1): parameter `a` declared as `in` here +fail_compilation/previewin2.d(2): Error: cannot use `in` parameters with `extern(Windows)` functions +fail_compilation/previewin2.d(2): parameter `a` declared as `in` here +fail_compilation/previewin2.d(4): Error: cannot use `in` parameters with `extern(C)` functions +fail_compilation/previewin2.d(4): parameter `__anonymous_param` declared as `in` here +--- +*/ + +#line 1 +extern(C) void wrongLink1 (in int a); +extern(Windows) void wrongLink2 (in void* a); +struct Large { ulong[64] data; } +extern(C) void wrongLink3 (in Large); diff --git a/gcc/testsuite/gdc.test/fail_compilation/retscope.d b/gcc/testsuite/gdc.test/fail_compilation/retscope.d index 27d566362bd..93944040db9 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/retscope.d +++ b/gcc/testsuite/gdc.test/fail_compilation/retscope.d @@ -2,7 +2,7 @@ REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- -fail_compilation/retscope.d(22): Error: scope variable `p` may not be returned +fail_compilation/retscope.d(22): Error: scope parameter `p` may not be returned fail_compilation/retscope.d(32): Error: returning `b ? nested1(& i) : nested2(& j)` escapes a reference to local variable `j` fail_compilation/retscope.d(45): Error: scope variable `p` assigned to non-scope `q` fail_compilation/retscope.d(47): Error: address of variable `i` assigned to `q` with longer lifetime @@ -85,7 +85,7 @@ struct HTTP /* TEST_OUTPUT: --- -fail_compilation/retscope.d(96): Error: reference to local variable `sa` assigned to non-scope parameter `a` +fail_compilation/retscope.d(96): Error: reference to local variable `sa` assigned to non-scope parameter `a` calling `bar8` --- */ // https://issues.dlang.org/show_bug.cgi?id=8838 @@ -149,7 +149,7 @@ S10* test10() /* TEST_OUTPUT: --- -fail_compilation/retscope.d(158): Error: scope variable `this` may not be returned +fail_compilation/retscope.d(158): Error: scope parameter `this` may not be returned --- */ @@ -218,7 +218,7 @@ void* escape3 (scope void* p) @safe { /* TEST_OUTPUT: --- -fail_compilation/retscope.d(229): Error: scope variable `ptr` may not be returned +fail_compilation/retscope.d(229): Error: scope parameter `ptr` may not be returned --- */ @@ -403,7 +403,7 @@ class Foo13 /* TEST_OUTPUT: --- -fail_compilation/retscope.d(1205): Error: scope variable `f14` assigned to non-scope parameter `this` +fail_compilation/retscope.d(1205): Error: scope variable `f14` assigned to non-scope parameter `this` calling `foo` --- */ @@ -454,7 +454,7 @@ fail_compilation/retscope.d(1311): Error: scope variable `u2` assigned to `ek` w /* TEST_OUTPUT: --- -fail_compilation/retscope.d(1405): Error: reference to local variable `buf` assigned to non-scope parameter `__anonymous_param` +fail_compilation/retscope.d(1405): Error: reference to local variable `buf` assigned to non-scope parameter `__anonymous_param` calling `myprintf` --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/retscope2.d b/gcc/testsuite/gdc.test/fail_compilation/retscope2.d index 17d2182b454..9f1e13dde98 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/retscope2.d +++ b/gcc/testsuite/gdc.test/fail_compilation/retscope2.d @@ -86,8 +86,8 @@ fail_compilation/retscope2.d(504): Error: scope variable `c` may not be returned /* TEST_OUTPUT: --- -fail_compilation/retscope2.d(604): Error: scope variable `_param_0` assigned to non-scope parameter `__anonymous_param` -fail_compilation/retscope2.d(604): Error: scope variable `_param_1` assigned to non-scope parameter `__anonymous_param` +fail_compilation/retscope2.d(604): Error: scope variable `_param_0` assigned to non-scope parameter `__anonymous_param` calling `foo600` +fail_compilation/retscope2.d(604): Error: scope variable `_param_1` assigned to non-scope parameter `__anonymous_param` calling `foo600` fail_compilation/retscope2.d(614): Error: template instance `retscope2.test600!(int*, int*)` error instantiating --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/retscope6.d b/gcc/testsuite/gdc.test/fail_compilation/retscope6.d index b9a85aeddc1..a8e5de5dc6d 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/retscope6.d +++ b/gcc/testsuite/gdc.test/fail_compilation/retscope6.d @@ -76,9 +76,9 @@ void foo() @safe /* TEST_OUTPUT: --- fail_compilation/retscope6.d(8016): Error: address of variable `i` assigned to `p` with longer lifetime -fail_compilation/retscope6.d(8031): Error: reference to local variable `i` assigned to non-scope parameter `p` -fail_compilation/retscope6.d(8031): Error: reference to local variable `j` assigned to non-scope parameter `q` -fail_compilation/retscope6.d(8048): Error: reference to local variable `j` assigned to non-scope parameter `q` +fail_compilation/retscope6.d(8031): Error: reference to local variable `i` assigned to non-scope parameter `p` calling `betty` +fail_compilation/retscope6.d(8031): Error: reference to local variable `j` assigned to non-scope parameter `q` calling `betty` +fail_compilation/retscope6.d(8048): Error: reference to local variable `j` assigned to non-scope parameter `q` calling `archie` --- */ @@ -172,7 +172,7 @@ T9 testfred() /* TEST_OUTPUT: --- -fail_compilation/retscope6.d(10003): Error: scope variable `values` assigned to non-scope parameter `values` +fail_compilation/retscope6.d(10003): Error: scope variable `values` assigned to non-scope parameter `values` calling `escape` --- */ @@ -234,7 +234,7 @@ const(int)* f_c_20150() @safe nothrow /* TEST_OUTPUT: --- -fail_compilation/retscope6.d(13010): Error: reference to local variable `str` assigned to non-scope parameter `x` +fail_compilation/retscope6.d(13010): Error: reference to local variable `str` assigned to non-scope parameter `x` calling `f_throw` --- */ @@ -254,7 +254,7 @@ void escape_throw_20150() @safe /* TEST_OUTPUT: --- -fail_compilation/retscope6.d(14019): Error: scope variable `scopePtr` assigned to non-scope parameter `x` +fail_compilation/retscope6.d(14019): Error: scope variable `scopePtr` assigned to non-scope parameter `x` calling `noInfer23021` fail_compilation/retscope6.d(14022): Error: scope variable `scopePtr` may not be returned --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/test14238.d b/gcc/testsuite/gdc.test/fail_compilation/test14238.d index e0d0b35c4d6..a0e4d69b361 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/test14238.d +++ b/gcc/testsuite/gdc.test/fail_compilation/test14238.d @@ -1,7 +1,7 @@ /* REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- -fail_compilation/test14238.d(20): Error: scope variable `fn` may not be returned +fail_compilation/test14238.d(20): Error: scope parameter `fn` may not be returned fail_compilation/test14238.d(28): Error: escaping reference to stack allocated value returned by `&baz` --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/test17423.d b/gcc/testsuite/gdc.test/fail_compilation/test17423.d index ec86646fc5a..3afb63b591b 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/test17423.d +++ b/gcc/testsuite/gdc.test/fail_compilation/test17423.d @@ -1,7 +1,7 @@ /* REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- -fail_compilation/test17423.d(26): Error: reference to local `this` assigned to non-scope parameter `dlg` +fail_compilation/test17423.d(26): Error: reference to local `this` assigned to non-scope parameter `dlg` calling `opApply` --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/test17450.d b/gcc/testsuite/gdc.test/fail_compilation/test17450.d index 098adaae648..ddf3f46fb12 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/test17450.d +++ b/gcc/testsuite/gdc.test/fail_compilation/test17450.d @@ -33,8 +33,8 @@ struct S { /* TEST_OUTPUT: --- -fail_compilation/test17450.d(103): Error: scope variable `c` may not be returned -fail_compilation/test17450.d(106): Error: scope variable `this` may not be returned +fail_compilation/test17450.d(103): Error: scope parameter `c` may not be returned +fail_compilation/test17450.d(106): Error: scope parameter `this` may not be returned --- */ // https://issues.dlang.org/show_bug.cgi?id=17450 diff --git a/gcc/testsuite/gdc.test/fail_compilation/test20245.d b/gcc/testsuite/gdc.test/fail_compilation/test20245.d index daa0697cffd..1713c9d8c27 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/test20245.d +++ b/gcc/testsuite/gdc.test/fail_compilation/test20245.d @@ -2,15 +2,15 @@ REQUIRED_ARGS: -preview=dip1000 TEST_OUTPUT: --- -fail_compilation/test20245.d(20): Error: reference to local variable `x` assigned to non-scope parameter `ptr` +fail_compilation/test20245.d(20): Error: reference to local variable `x` assigned to non-scope parameter `ptr` calling `escape` fail_compilation/test20245.d(21): Error: copying `&x` into allocated memory escapes a reference to parameter `x` fail_compilation/test20245.d(22): Error: scope variable `a` may not be returned fail_compilation/test20245.d(26): Error: cannot take address of `scope` variable `x` since `scope` applies to first indirection only -fail_compilation/test20245.d(32): Error: reference to local variable `x` assigned to non-scope parameter `ptr` +fail_compilation/test20245.d(32): Error: reference to local variable `x` assigned to non-scope parameter `ptr` calling `escape` fail_compilation/test20245.d(33): Error: copying `&x` into allocated memory escapes a reference to parameter `x` fail_compilation/test20245.d(49): Error: reference to local variable `price` assigned to non-scope `this.minPrice` -fail_compilation/test20245.d(68): Error: reference to local variable `this` assigned to non-scope parameter `msg` -fail_compilation/test20245.d(88): Error: reference to local variable `this` assigned to non-scope parameter `content` +fail_compilation/test20245.d(68): Error: reference to local variable `this` assigned to non-scope parameter `msg` calling `this` +fail_compilation/test20245.d(88): Error: reference to local variable `this` assigned to non-scope parameter `content` calling `listUp` --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/test22818.d b/gcc/testsuite/gdc.test/fail_compilation/test22818.d index ae96b3bc109..5759415ead2 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/test22818.d +++ b/gcc/testsuite/gdc.test/fail_compilation/test22818.d @@ -1,7 +1,7 @@ /* REQUIRED_ARGS: -preview=dip1000 * TEST_OUTPUT: --- -fail_compilation/test22818.d(104): Error: scope variable `c` may not be returned +fail_compilation/test22818.d(104): Error: scope parameter `c` may not be returned --- */ diff --git a/gcc/testsuite/gdc.test/fail_compilation/typeerrors.d b/gcc/testsuite/gdc.test/fail_compilation/typeerrors.d index 37395d4b897..9d527b75d71 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/typeerrors.d +++ b/gcc/testsuite/gdc.test/fail_compilation/typeerrors.d @@ -2,7 +2,7 @@ TEST_OUTPUT: --- fail_compilation/typeerrors.d(32): Deprecation: `scope` as a type constraint is deprecated. Use `scope` at the usage site. -fail_compilation/typeerrors.d(37): Error: tuple index 4 exceeds 4 +fail_compilation/typeerrors.d(37): Error: tuple index `4` out of bounds `[0 .. 4]` fail_compilation/typeerrors.d(39): Error: variable `x` cannot be read at compile time fail_compilation/typeerrors.d(40): Error: cannot have array of `void()` fail_compilation/typeerrors.d(41): Error: cannot have array of scope `typeerrors.C` diff --git a/gcc/testsuite/gdc.test/fail_compilation/udaparams.d b/gcc/testsuite/gdc.test/fail_compilation/udaparams.d index 5d0390f4f29..ec4796789ac 100644 --- a/gcc/testsuite/gdc.test/fail_compilation/udaparams.d +++ b/gcc/testsuite/gdc.test/fail_compilation/udaparams.d @@ -12,8 +12,8 @@ fail_compilation/udaparams.d(40): Error: `@safe` attribute for function paramete fail_compilation/udaparams.d(43): Error: `@system` attribute for function parameter is not supported fail_compilation/udaparams.d(44): Error: `@trusted` attribute for function parameter is not supported fail_compilation/udaparams.d(45): Error: `@nogc` attribute for function parameter is not supported -fail_compilation/udaparams.d(51): Error: cannot put a storage-class in an alias declaration. -fail_compilation/udaparams.d(52): Error: cannot put a storage-class in an alias declaration. +fail_compilation/udaparams.d(51): Error: cannot put a storage-class in an `alias` declaration. +fail_compilation/udaparams.d(52): Error: cannot put a storage-class in an `alias` declaration. fail_compilation/udaparams.d(53): Error: semicolon expected to close `alias` declaration fail_compilation/udaparams.d(53): Error: declaration expected, not `=>` fail_compilation/udaparams.d(54): Error: semicolon expected to close `alias` declaration diff --git a/gcc/testsuite/gdc.test/fail_compilation/udatypes.d b/gcc/testsuite/gdc.test/fail_compilation/udatypes.d new file mode 100644 index 00000000000..a7f2bfc521f --- /dev/null +++ b/gcc/testsuite/gdc.test/fail_compilation/udatypes.d @@ -0,0 +1,8 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/udatypes.d(8): Error: user-defined attributes not allowed for `alias` declarations +--- +*/ + +alias c_typedef = extern(C) @(1) void* function(size_t); diff --git a/gcc/testsuite/gdc.test/runnable/ice10086b.d b/gcc/testsuite/gdc.test/runnable/ice10086b.d index abb6f78a4ac..910c5c4a7a2 100644 --- a/gcc/testsuite/gdc.test/runnable/ice10086b.d +++ b/gcc/testsuite/gdc.test/runnable/ice10086b.d @@ -5,3 +5,53 @@ import imports.ice10086y; import imports.ice10086x; void main() { test(); } + +static if (0) +{ +/* this is a reduced one-file version that triggers a seg fault +because the use of OPframeptr gets inlined, and the offests +to it are not updated. +Compile with: -O -inline +*/ + +pragma(inline, false) +auto bind(alias f, bindValues...)() +{ + pragma(inline, false) + auto bind(Types...)(Types values) + { + return f(bindValues, values); + } + return bind(); +} + + +struct SS +{ + int a1 = 123; +} + +pragma(inline, false) +@safe auto ff(SS rr) +{ + return rr; +} + +// pragma(inline, false) +@safe auto gg(SS ss) // this getting inlined triggers the problem +{ + return bind!(ff, ss); +} + +pragma(inline, false) +void test() +{ + SS s1; + + auto zb = bind!(gg, s1)(); + assert(zb.a1 == 123); +} + + +void main() { test(); } +} diff --git a/gcc/testsuite/gdc.test/runnable/inline3.d b/gcc/testsuite/gdc.test/runnable/inline3.d new file mode 100644 index 00000000000..01af5c8cbe5 --- /dev/null +++ b/gcc/testsuite/gdc.test/runnable/inline3.d @@ -0,0 +1,44 @@ +// REQUIRED_ARGS: -inline -O + +// Test operator overloading + +extern (C) int printf(const(char*) fmt, ...); + +struct Tuple6798(T...) +{ + T field; + alias field this; + + bool opEquals(Tuple6798 rxx) + { + foreach (i, _; T) + { + if (!__equals(this[i], rxx[i])) + assert(0); + //return false; + } + return true; + } +} + +auto tuple(T...)(T args) +{ + return Tuple6798!T(args); +} + +int zzzz() +{ + if (!__equals("mno", "mno")) + assert(0); + + assert(tuple("abcd", "x") == tuple("abcd", "x")); + return 0; +} + +int main() +{ + zzzz(); + + printf("Success\n"); + return 0; +} diff --git a/gcc/testsuite/gdc.test/runnable/staticforeach.d b/gcc/testsuite/gdc.test/runnable/staticforeach.d index bf6dc983935..6a9ac5deb2f 100644 --- a/gcc/testsuite/gdc.test/runnable/staticforeach.d +++ b/gcc/testsuite/gdc.test/runnable/staticforeach.d @@ -39,7 +39,36 @@ void test19479() } } +/**********************************/ +// https://issues.dlang.org/show_bug.cgi?id=23192 + +alias AliasSeq(Args...) = Args; + +struct S23192 +{ + int x; + int y; + + int fun() + { + static foreach (sym; AliasSeq!(S23192.x)) + int i = sym; + + static foreach (sym; AliasSeq!(this.y)) + int j = sym; + + return i + j; + } +} + +void test23192() +{ + assert(S23192(1, 2).fun() == 3); + static assert(S23192(1, 2).fun() == 3); +} + void main() { test19479(); + test23192(); } diff --git a/gcc/testsuite/gdc.test/runnable_cxx/cppa.d b/gcc/testsuite/gdc.test/runnable_cxx/cppa.d index e31588948a6..cd91dd55834 100644 --- a/gcc/testsuite/gdc.test/runnable_cxx/cppa.d +++ b/gcc/testsuite/gdc.test/runnable_cxx/cppa.d @@ -1,3 +1,4 @@ +// REQUIRED_ARGS: -preview=in // PERMUTE_ARGS: -g // EXTRA_CPP_SOURCES: cppb.cpp // EXTRA_FILES: extra-files/cppb.h @@ -1637,7 +1638,13 @@ void test19134() } // https://issues.dlang.org/show_bug.cgi?id=18955 -alias std_string = std.basic_string!(char); +version (linux) + alias std_string = std.basic_string!(char); +else +{ + import core.stdcpp.string : core_basic_string = basic_string; + alias std_string = core_basic_string!(char); +} extern(C++) void callback18955(ref const(std_string) str) { @@ -1646,6 +1653,16 @@ extern(C++) void test18955(); /****************************************/ +extern(C++) void testPreviewIn(); + +extern(C++) void previewInFunction(in int a, in std_string b, ref const(std_string) c) +{ + assert(a == 42); + assert(&b is &c); +} + +/****************************************/ + void main() { test1(); @@ -1695,6 +1712,7 @@ void main() test18966(); test19134(); test18955(); + testPreviewIn(); printf("Success\n"); } diff --git a/gcc/testsuite/gdc.test/runnable_cxx/extra-files/cppb.cpp b/gcc/testsuite/gdc.test/runnable_cxx/extra-files/cppb.cpp index 4fa87efcfff..83667cbddc7 100644 --- a/gcc/testsuite/gdc.test/runnable_cxx/extra-files/cppb.cpp +++ b/gcc/testsuite/gdc.test/runnable_cxx/extra-files/cppb.cpp @@ -4,30 +4,8 @@ #include <exception> #include <cstdarg> -#if _WIN32 // otherwise defined in C header files! -// https://issues.dlang.org/show_bug.cgi?id=18955 -namespace std -{ - template<typename Char> - struct char_traits - { - }; - template<typename Char> - class allocator - { - }; - template<typename Char, typename Traits, typename Alloc> - class basic_string - { - }; - typedef basic_string<char, char_traits<char>, allocator<char> > string; -} -#else // if POSIX - #include <string> -#endif // _WIN32 - #include "cppb.h" /**************************************/ @@ -936,3 +914,11 @@ void test18955() callback18955(s); #endif } + +void previewInFunction(const int& a, const std::string& b, const std::string& c); + +void testPreviewIn() +{ + std::string s = "Hello World"; + previewInFunction(42, s, s); +} |