From 8ef32fa8af53bc709c1cbdeb1fbb47444da94e2b Mon Sep 17 00:00:00 2001 From: Dennis Date: Mon, 16 May 2022 09:52:51 +0200 Subject: [PATCH 01/23] Fix issue 23100 - empty array literal passed to scope param not 'falsey' anymore (#14105) --- src/dmd/expressionsem.d | 4 ++-- test/runnable/test20734.d | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index 717420910a..71386d4f50 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -2058,10 +2058,10 @@ private bool functionParameters(const ref Loc loc, Scope* sc, ArrayLiteralExp ale; if (p.type.toBasetype().ty == Tarray && - (ale = a.isArrayLiteralExp()) !is null) + (ale = a.isArrayLiteralExp()) !is null && ale.elements && ale.elements.length > 0) { // allocate the array literal as temporary static array on the stack - ale.type = ale.type.nextOf().sarrayOf(ale.elements ? ale.elements.length : 0); + ale.type = ale.type.nextOf().sarrayOf(ale.elements.length); auto tmp = copyToTemp(0, "__arrayliteral_on_stack", ale); auto declareTmp = new DeclarationExp(ale.loc, tmp); auto castToSlice = new CastExp(ale.loc, new VarExp(ale.loc, tmp), diff --git a/test/runnable/test20734.d b/test/runnable/test20734.d index 264602bccc..b3c5916ada 100644 --- a/test/runnable/test20734.d +++ b/test/runnable/test20734.d @@ -16,6 +16,7 @@ extern(C) int main() nothrow @nogc @safe { takeScopeSlice([ S(1), S(2) ]); // @nogc => no GC allocation (() @trusted { assert(numDtor == 2); })(); // stack-allocated array literal properly destructed + assert23100([]); return 0; } @@ -26,3 +27,9 @@ void test23098() @safe { f23098([10, 20]); } + +// https://issues.dlang.org/show_bug.cgi?id=23100 +void assert23100(scope int[] d) @safe nothrow @nogc +{ + assert(!d); +} From c3bd914c2af2a4b66ee433e634370cf91c427f9c Mon Sep 17 00:00:00 2001 From: Dennis Korpel Date: Wed, 18 May 2022 11:28:35 +0200 Subject: [PATCH 02/23] Fix issue 23102 - pinholeopt, "Conditional jump or move depends on uninitialised value(s)" --- src/dmd/backend/cod2.d | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dmd/backend/cod2.d b/src/dmd/backend/cod2.d index 4ca5ea6e15..a4abbd329a 100644 --- a/src/dmd/backend/cod2.d +++ b/src/dmd/backend/cod2.d @@ -1348,6 +1348,7 @@ void cddiv(ref CodeBuilder cdb,elem *e,regm_t *pretregs) code cs = void; cs.Iflags = 0; + cs.IFL2 = 0; cs.Irex = 0; switch (e2.Eoper) From cf80ca9d4b4e99db30d2644706ecbddc8f79cd49 Mon Sep 17 00:00:00 2001 From: Razvan Nitu Date: Fri, 20 May 2022 14:19:27 +0300 Subject: [PATCH 03/23] Fix Issue 23082 - stringof of template alias overloaded with function accessed by trait: segfault. (#14149) --- src/dmd/expressionsem.d | 2 +- test/compilable/test23082.d | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/compilable/test23082.d diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index 71386d4f50..a4079f4189 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -12535,7 +12535,7 @@ Expression semanticY(DotIdExp exp, Scope* sc, int flag) e = new CommaExp(exp.loc, eleft, e); e.type = Type.tvoid; // ambiguous type? } - return e; + return e.expressionSemantic(sc); } if (auto o = s.isOverloadSet()) { diff --git a/test/compilable/test23082.d b/test/compilable/test23082.d new file mode 100644 index 0000000000..9df4e4e777 --- /dev/null +++ b/test/compilable/test23082.d @@ -0,0 +1,17 @@ +// https://issues.dlang.org/show_bug.cgi?id=23082 + +/* +TEST_OUTPUT: +--- +bar +--- +*/ + +void foo()() {} +alias bar = foo; +void bar() { } + +void main() +{ + pragma(msg, __traits(parent, main).bar.stringof); +} From dbe0600f853466992fe8f3c3f684f520f6a15883 Mon Sep 17 00:00:00 2001 From: mhh Date: Tue, 17 May 2022 18:03:50 +0100 Subject: [PATCH 04/23] Fix Issue 23114 - Make noreturn conversions work --- src/dmd/dcast.d | 3 ++ src/dmd/impcnvtab.d | 55 +++++++++++++++++++++++++++++++++++++ test/compilable/noreturn1.d | 28 +++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/src/dmd/dcast.d b/src/dmd/dcast.d index 83978391e4..853f659663 100644 --- a/src/dmd/dcast.d +++ b/src/dmd/dcast.d @@ -2954,6 +2954,9 @@ Lagain: t1 = Type.basic[ty1]; t2 = Type.basic[ty2]; + + if (!(t1 && t2)) + return null; e1 = e1.castTo(sc, t1); e2 = e2.castTo(sc, t2); return Lret(Type.basic[ty]); diff --git a/src/dmd/impcnvtab.d b/src/dmd/impcnvtab.d index ab46f5eebb..832c331c31 100644 --- a/src/dmd/impcnvtab.d +++ b/src/dmd/impcnvtab.d @@ -64,6 +64,57 @@ enum ImpCnvTab impCnvTab = generateImpCnvTab(); ImpCnvTab generateImpCnvTab() { + TY[TMAX] typeTYs = + [ + Tarray, + Tsarray, + Taarray, + Tpointer, + Treference, + Tfunction, + Tident, + Tclass, + Tstruct, + Tenum, + Tdelegate, + Tnone, + Tvoid, + Tint8, + Tuns8, + Tint16, + Tuns16, + Tint32, + Tuns32, + Tint64, + Tuns64, + Tfloat32, + Tfloat64, + Tfloat80, + Timaginary32, + Timaginary64, + Timaginary80, + Tcomplex32, + Tcomplex64, + Tcomplex80, + Tbool, + Tchar, + Twchar, + Tdchar, + Terror, + Tinstance, + Ttypeof, + Ttuple, + Tslice, + Treturn, + Tnull, + Tvector, + Tint128, + Tuns128, + Ttraits, + Tmixin, + Tnoreturn, + Ttag, + ]; ImpCnvTab impCnvTab; // Set conversion tables @@ -375,5 +426,9 @@ ImpCnvTab generateImpCnvTab() X(Tcomplex80,Tcomplex80, Tcomplex80,Tcomplex80, Tcomplex80); + // "No type is implicitly convertible to noreturn, but noreturn is implicitly convertible to every other type" + foreach(convertToTy; typeTYs) + X(Tnoreturn, convertToTy, convertToTy, convertToTy, convertToTy); + return impCnvTab; } diff --git a/test/compilable/noreturn1.d b/test/compilable/noreturn1.d index 5bba9baa72..e648a56d89 100644 --- a/test/compilable/noreturn1.d +++ b/test/compilable/noreturn1.d @@ -122,3 +122,31 @@ noreturn testdg(noreturn delegate() dg) { dg(); } + +noreturn func() +{ + while(1) + { + } +} +alias AliasSeq(T...) = T; +alias Types = AliasSeq!(bool, byte, ubyte, short, ushort, int, uint, + long, ulong, char, wchar, dchar, float, double, + real); +void noreturnImplicit() +{ + /* + Testing both ways because, although the underlying table + is symmetrical the code that calls into it may be buggy. + */ + { + int x = 2 + func(); + int y = func() + 2; + } + foreach(T; Types) + { + T value; + auto x = value + throw new Exception("Hello"); + auto y = (throw new Exception("wow")) + value; + } +} From 5c41c29b085f7a55a2d20381565c8d1d25b92c2b Mon Sep 17 00:00:00 2001 From: Mathis Beer Date: Mon, 30 May 2022 11:17:12 +0200 Subject: [PATCH 05/23] Fix issue 23148, 21723: Generate invariant id on the basis of location rather than counter. This makes __invariant more resilient to template order issues. --- src/dmd/astbase.d | 2 +- src/dmd/func.d | 2 +- test/compilable/extra-files/vcg-ast.d.cg | 2 +- test/fail_compilation/fail4421.d | 2 +- test/fail_compilation/fail7848.d | 8 ++++---- test/fail_compilation/test20626.d | 2 +- test/runnable/extra-files/lib21723a.d | 3 +++ test/runnable/extra-files/lib21723b.d | 4 ++++ test/runnable/extra-files/lib23148.d | 10 ++++++++++ test/runnable/extra-files/test21723.d | 5 +++++ test/runnable/extra-files/test23148.d | 6 ++++++ test/runnable/test21723.sh | 6 ++++++ test/runnable/test23148.sh | 6 ++++++ 13 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 test/runnable/extra-files/lib21723a.d create mode 100644 test/runnable/extra-files/lib21723b.d create mode 100644 test/runnable/extra-files/lib23148.d create mode 100644 test/runnable/extra-files/test21723.d create mode 100644 test/runnable/extra-files/test23148.d create mode 100644 test/runnable/test21723.sh create mode 100644 test/runnable/test23148.sh diff --git a/src/dmd/astbase.d b/src/dmd/astbase.d index 1c34eef816..0720fe2f4d 100644 --- a/src/dmd/astbase.d +++ b/src/dmd/astbase.d @@ -711,7 +711,7 @@ struct ASTBase { extern (D) this(const ref Loc loc, Loc endloc, StorageClass stc, Identifier id, Statement fbody) { - super(loc, endloc, id ? id : Identifier.generateId("__invariant"), stc, null); + super(loc, endloc, id ? id : Identifier.generateIdWithLoc("__invariant", loc), stc, null); this.fbody = fbody; } diff --git a/src/dmd/func.d b/src/dmd/func.d index 55abe4d52e..6b77143751 100644 --- a/src/dmd/func.d +++ b/src/dmd/func.d @@ -4150,7 +4150,7 @@ extern (C++) final class InvariantDeclaration : FuncDeclaration { extern (D) this(const ref Loc loc, const ref Loc endloc, StorageClass stc, Identifier id, Statement fbody) { - super(loc, endloc, id ? id : Identifier.generateId("__invariant"), stc, null); + super(loc, endloc, id ? id : Identifier.generateIdWithLoc("__invariant", loc), stc, null); this.fbody = fbody; } diff --git a/test/compilable/extra-files/vcg-ast.d.cg b/test/compilable/extra-files/vcg-ast.d.cg index 5469f55252..6ee6ad2957 100644 --- a/test/compilable/extra-files/vcg-ast.d.cg +++ b/test/compilable/extra-files/vcg-ast.d.cg @@ -83,7 +83,7 @@ class C : Object } invariant { - this.__invariant1() , this.__invariant2(); + this.__invariant_L41_C5() , this.__invariant_L42_C5(); } } enum __c_wchar_t : dchar; diff --git a/test/fail_compilation/fail4421.d b/test/fail_compilation/fail4421.d index 3aedfc31f3..835b85ae18 100644 --- a/test/fail_compilation/fail4421.d +++ b/test/fail_compilation/fail4421.d @@ -3,7 +3,7 @@ TEST_OUTPUT: --- fail_compilation/fail4421.d(16): Error: function `fail4421.U1.__postblit` destructors, postblits and invariants are not allowed in union `U1` fail_compilation/fail4421.d(17): Error: destructor `fail4421.U1.~this` destructors, postblits and invariants are not allowed in union `U1` -fail_compilation/fail4421.d(18): Error: function `fail4421.U1.__invariant1` destructors, postblits and invariants are not allowed in union `U1` +fail_compilation/fail4421.d(18): Error: function `fail4421.U1.__invariant_L18_C5` destructors, postblits and invariants are not allowed in union `U1` --- diff --git a/test/fail_compilation/fail7848.d b/test/fail_compilation/fail7848.d index e8371c4f7f..a0e6c27cd9 100644 --- a/test/fail_compilation/fail7848.d +++ b/test/fail_compilation/fail7848.d @@ -9,12 +9,12 @@ fail_compilation/fail7848.d(21): `fail7848.func` is declared here fail_compilation/fail7848.d(27): Error: `@nogc` function `fail7848.C.__unittest_L25_C30` cannot call non-@nogc function `fail7848.func` fail_compilation/fail7848.d(27): Error: function `fail7848.func` is not `nothrow` fail_compilation/fail7848.d(25): Error: function `fail7848.C.__unittest_L25_C30` may throw but is marked as `nothrow` -fail_compilation/fail7848.d(32): Error: `pure` function `fail7848.C.__invariant1` cannot call impure function `fail7848.func` -fail_compilation/fail7848.d(32): Error: `@safe` function `fail7848.C.__invariant1` cannot call `@system` function `fail7848.func` +fail_compilation/fail7848.d(32): Error: `pure` function `fail7848.C.__invariant_L30_C30` cannot call impure function `fail7848.func` +fail_compilation/fail7848.d(32): Error: `@safe` function `fail7848.C.__invariant_L30_C30` cannot call `@system` function `fail7848.func` fail_compilation/fail7848.d(21): `fail7848.func` is declared here -fail_compilation/fail7848.d(32): Error: `@nogc` function `fail7848.C.__invariant1` cannot call non-@nogc function `fail7848.func` +fail_compilation/fail7848.d(32): Error: `@nogc` function `fail7848.C.__invariant_L30_C30` cannot call non-@nogc function `fail7848.func` fail_compilation/fail7848.d(32): Error: function `fail7848.func` is not `nothrow` -fail_compilation/fail7848.d(30): Error: function `fail7848.C.__invariant1` may throw but is marked as `nothrow` +fail_compilation/fail7848.d(30): Error: function `fail7848.C.__invariant_L30_C30` may throw but is marked as `nothrow` --- */ diff --git a/test/fail_compilation/test20626.d b/test/fail_compilation/test20626.d index bd0bed8a85..12591d0e16 100644 --- a/test/fail_compilation/test20626.d +++ b/test/fail_compilation/test20626.d @@ -19,4 +19,4 @@ struct S invariant {} } -pragma(msg, typeof(S.init.__invariant1)); +pragma(msg, typeof(S.init.__invariant_L6_C5)); diff --git a/test/runnable/extra-files/lib21723a.d b/test/runnable/extra-files/lib21723a.d new file mode 100644 index 0000000000..9f3980debd --- /dev/null +++ b/test/runnable/extra-files/lib21723a.d @@ -0,0 +1,3 @@ +import lib21723b; + +alias Struct = lib21723b.Struct; diff --git a/test/runnable/extra-files/lib21723b.d b/test/runnable/extra-files/lib21723b.d new file mode 100644 index 0000000000..c6bd7868c8 --- /dev/null +++ b/test/runnable/extra-files/lib21723b.d @@ -0,0 +1,4 @@ +struct Struct { + invariant { void call() { } } + void templfun()() { } +} diff --git a/test/runnable/extra-files/lib23148.d b/test/runnable/extra-files/lib23148.d new file mode 100644 index 0000000000..c532d8a536 --- /dev/null +++ b/test/runnable/extra-files/lib23148.d @@ -0,0 +1,10 @@ +struct Struct { + SumType!() v1; +} +void foo()() { SumType!() v2; } +struct SumType() { + ~this() { } + invariant { alias a = {}; match!a(); } + +} +void match(alias handler)() { } diff --git a/test/runnable/extra-files/test21723.d b/test/runnable/extra-files/test21723.d new file mode 100644 index 0000000000..2cbf2b45cb --- /dev/null +++ b/test/runnable/extra-files/test21723.d @@ -0,0 +1,5 @@ +import lib21723a; + +void trigger(Struct val) { val.templfun; } + +void main() { alias lambda = a => a; } diff --git a/test/runnable/extra-files/test23148.d b/test/runnable/extra-files/test23148.d new file mode 100644 index 0000000000..e25bc0707a --- /dev/null +++ b/test/runnable/extra-files/test23148.d @@ -0,0 +1,6 @@ +import lib23148; + +alias l = _ => 0; +void main() { + foo!()(); +} diff --git a/test/runnable/test21723.sh b/test/runnable/test21723.sh new file mode 100644 index 0000000000..b8833b83b7 --- /dev/null +++ b/test/runnable/test21723.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib21723a.d ${EXTRA_FILES}/lib21723b.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} -inline ${EXTRA_FILES}/test21723.d ${OUTPUT_BASE}${LIBEXT} + +rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/runnable/test23148.sh b/test/runnable/test23148.sh new file mode 100644 index 0000000000..5d3c5e44e6 --- /dev/null +++ b/test/runnable/test23148.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib23148.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test23148.d ${OUTPUT_BASE}${LIBEXT} + +rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} From 8c1beec2b6508c6d47fc23081702e5f8df6bf8ba Mon Sep 17 00:00:00 2001 From: Mathis Beer Date: Fri, 3 Jun 2022 08:22:51 +0200 Subject: [PATCH 06/23] Refactor: Instead of using any generated identifier for invariants, patch up the identifier based on the number of invariants in the aggregate. Relying on any sort of global counter leads to linker errors with static libraries. Even the current approach, which fixed #23148 and #21723, is not reliable. This commit instead fixes up the identifier of the invariant symbol based on the index of the invariant in the struct or class itself, thus removing any reliance on a global counter. --- src/dmd/dsymbolsem.d | 3 +++ src/dmd/frontend.h | 1 + src/dmd/func.d | 12 +++++++++++- test/compilable/extra-files/vcg-ast.d.cg | 2 +- test/fail_compilation/fail4421.d | 2 +- test/fail_compilation/fail7848.d | 8 ++++---- test/fail_compilation/test20626.d | 2 +- 7 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/dmd/dsymbolsem.d b/src/dmd/dsymbolsem.d index be8f915090..c5766787bf 100644 --- a/src/dmd/dsymbolsem.d +++ b/src/dmd/dsymbolsem.d @@ -4407,7 +4407,10 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor invd.semanticRun < PASS.semantic && !ad.isUnionDeclaration() // users are on their own with union fields ) + { + invd.fixupInvariantIdent(ad.invs.length); ad.invs.push(invd); + } if (!invd.type) invd.type = new TypeFunction(ParameterList(), Type.tvoid, LINK.d, invd.storage_class); diff --git a/src/dmd/frontend.h b/src/dmd/frontend.h index d830edab96..f28f00ee2e 100644 --- a/src/dmd/frontend.h +++ b/src/dmd/frontend.h @@ -3022,6 +3022,7 @@ public: bool addPostInvariant(); InvariantDeclaration* isInvariantDeclaration(); void accept(Visitor* v); + void fixupInvariantIdent(size_t offset); }; class NewDeclaration final : public FuncDeclaration diff --git a/src/dmd/func.d b/src/dmd/func.d index 6b77143751..de46c7ea7f 100644 --- a/src/dmd/func.d +++ b/src/dmd/func.d @@ -4150,7 +4150,8 @@ extern (C++) final class InvariantDeclaration : FuncDeclaration { extern (D) this(const ref Loc loc, const ref Loc endloc, StorageClass stc, Identifier id, Statement fbody) { - super(loc, endloc, id ? id : Identifier.generateIdWithLoc("__invariant", loc), stc, null); + // Make a unique invariant for now; we'll fix it up as we add it to the aggregate invariant list. + super(loc, endloc, id ? id : Identifier.generateId("__invariant"), stc, null); this.fbody = fbody; } @@ -4186,6 +4187,15 @@ extern (C++) final class InvariantDeclaration : FuncDeclaration { v.visit(this); } + + void fixupInvariantIdent(size_t offset) + { + OutBuffer idBuf; + idBuf.writestring("__invariant"); + idBuf.print(offset); + + ident = Identifier.idPool(idBuf[]); + } } diff --git a/test/compilable/extra-files/vcg-ast.d.cg b/test/compilable/extra-files/vcg-ast.d.cg index 6ee6ad2957..5b88b7231b 100644 --- a/test/compilable/extra-files/vcg-ast.d.cg +++ b/test/compilable/extra-files/vcg-ast.d.cg @@ -83,7 +83,7 @@ class C : Object } invariant { - this.__invariant_L41_C5() , this.__invariant_L42_C5(); + this.__invariant0() , this.__invariant1(); } } enum __c_wchar_t : dchar; diff --git a/test/fail_compilation/fail4421.d b/test/fail_compilation/fail4421.d index 835b85ae18..3aedfc31f3 100644 --- a/test/fail_compilation/fail4421.d +++ b/test/fail_compilation/fail4421.d @@ -3,7 +3,7 @@ TEST_OUTPUT: --- fail_compilation/fail4421.d(16): Error: function `fail4421.U1.__postblit` destructors, postblits and invariants are not allowed in union `U1` fail_compilation/fail4421.d(17): Error: destructor `fail4421.U1.~this` destructors, postblits and invariants are not allowed in union `U1` -fail_compilation/fail4421.d(18): Error: function `fail4421.U1.__invariant_L18_C5` destructors, postblits and invariants are not allowed in union `U1` +fail_compilation/fail4421.d(18): Error: function `fail4421.U1.__invariant1` destructors, postblits and invariants are not allowed in union `U1` --- diff --git a/test/fail_compilation/fail7848.d b/test/fail_compilation/fail7848.d index a0e6c27cd9..001c7d7544 100644 --- a/test/fail_compilation/fail7848.d +++ b/test/fail_compilation/fail7848.d @@ -9,12 +9,12 @@ fail_compilation/fail7848.d(21): `fail7848.func` is declared here fail_compilation/fail7848.d(27): Error: `@nogc` function `fail7848.C.__unittest_L25_C30` cannot call non-@nogc function `fail7848.func` fail_compilation/fail7848.d(27): Error: function `fail7848.func` is not `nothrow` fail_compilation/fail7848.d(25): Error: function `fail7848.C.__unittest_L25_C30` may throw but is marked as `nothrow` -fail_compilation/fail7848.d(32): Error: `pure` function `fail7848.C.__invariant_L30_C30` cannot call impure function `fail7848.func` -fail_compilation/fail7848.d(32): Error: `@safe` function `fail7848.C.__invariant_L30_C30` cannot call `@system` function `fail7848.func` +fail_compilation/fail7848.d(32): Error: `pure` function `fail7848.C.__invariant0` cannot call impure function `fail7848.func` +fail_compilation/fail7848.d(32): Error: `@safe` function `fail7848.C.__invariant0` cannot call `@system` function `fail7848.func` fail_compilation/fail7848.d(21): `fail7848.func` is declared here -fail_compilation/fail7848.d(32): Error: `@nogc` function `fail7848.C.__invariant_L30_C30` cannot call non-@nogc function `fail7848.func` +fail_compilation/fail7848.d(32): Error: `@nogc` function `fail7848.C.__invariant0` cannot call non-@nogc function `fail7848.func` fail_compilation/fail7848.d(32): Error: function `fail7848.func` is not `nothrow` -fail_compilation/fail7848.d(30): Error: function `fail7848.C.__invariant_L30_C30` may throw but is marked as `nothrow` +fail_compilation/fail7848.d(30): Error: function `fail7848.C.__invariant0` may throw but is marked as `nothrow` --- */ diff --git a/test/fail_compilation/test20626.d b/test/fail_compilation/test20626.d index 12591d0e16..bd0bed8a85 100644 --- a/test/fail_compilation/test20626.d +++ b/test/fail_compilation/test20626.d @@ -19,4 +19,4 @@ struct S invariant {} } -pragma(msg, typeof(S.init.__invariant_L6_C5)); +pragma(msg, typeof(S.init.__invariant1)); From 5ba0fa2a593582e505d1f9b0ef45fc8d6452b74a Mon Sep 17 00:00:00 2001 From: FeepingCreature Date: Sat, 4 Jun 2022 13:39:20 +0200 Subject: [PATCH 07/23] Mark fixupInvariantIdent as extern(D); it's not needed in the headers. --- src/dmd/frontend.h | 1 - src/dmd/func.d | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/dmd/frontend.h b/src/dmd/frontend.h index f28f00ee2e..d830edab96 100644 --- a/src/dmd/frontend.h +++ b/src/dmd/frontend.h @@ -3022,7 +3022,6 @@ public: bool addPostInvariant(); InvariantDeclaration* isInvariantDeclaration(); void accept(Visitor* v); - void fixupInvariantIdent(size_t offset); }; class NewDeclaration final : public FuncDeclaration diff --git a/src/dmd/func.d b/src/dmd/func.d index de46c7ea7f..68294efbf0 100644 --- a/src/dmd/func.d +++ b/src/dmd/func.d @@ -4188,7 +4188,7 @@ extern (C++) final class InvariantDeclaration : FuncDeclaration v.visit(this); } - void fixupInvariantIdent(size_t offset) + extern (D) void fixupInvariantIdent(size_t offset) { OutBuffer idBuf; idBuf.writestring("__invariant"); From 6d590f4c88d7ada0743e5bdb4223a7d044924322 Mon Sep 17 00:00:00 2001 From: mhh Date: Tue, 7 Jun 2022 15:17:07 +0100 Subject: [PATCH 08/23] Fix Issue 20143 - Backend constant folding did not support division by real. This involved simply adding the correct case to the grand olde switch statement that does the evalu8tion --- src/dmd/backend/evalu8.d | 4 ++++ test/compilable/backendfloatoptim.d | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/compilable/backendfloatoptim.d diff --git a/src/dmd/backend/evalu8.d b/src/dmd/backend/evalu8.d index 5cb7c0d53d..03f44b4582 100644 --- a/src/dmd/backend/evalu8.d +++ b/src/dmd/backend/evalu8.d @@ -984,6 +984,10 @@ static if (0) case TYdouble_alias: e.EV.Vdouble = e1.EV.Vdouble / e2.EV.Vdouble; break; + case TYldouble: + // cast is required because Vldouble is a soft type on windows + e.EV.Vdouble = cast(double)(e1.EV.Vdouble / e2.EV.Vldouble); + break; case TYidouble: e.EV.Vdouble = -e1.EV.Vdouble / e2.EV.Vdouble; break; diff --git a/test/compilable/backendfloatoptim.d b/test/compilable/backendfloatoptim.d new file mode 100644 index 0000000000..7ec9f614ef --- /dev/null +++ b/test/compilable/backendfloatoptim.d @@ -0,0 +1,10 @@ +// REQUIRED_ARGS: -O -inline + +//https://issues.dlang.org/show_bug.cgi?id=20143 +real fun(int x) { return 0.0; } + +double bug() +{ + // value passed to fun is irrelevant + return 0.0 / fun(420); +} From 7af85622571184159202d47db818adcff15919a8 Mon Sep 17 00:00:00 2001 From: mhh Date: Tue, 7 Jun 2022 18:53:53 +0100 Subject: [PATCH 09/23] Add division operator to opBinaryRight in the longdouble_soft implementation so evalu8 patch works on ldc-windows --- src/dmd/root/longdouble.d | 1 + 1 file changed, 1 insertion(+) diff --git a/src/dmd/root/longdouble.d b/src/dmd/root/longdouble.d index b359a0d4e8..bbffc35a4b 100644 --- a/src/dmd/root/longdouble.d +++ b/src/dmd/root/longdouble.d @@ -156,6 +156,7 @@ nothrow @nogc pure: static if (op == "+") return longdouble_soft(rhs).ld_add(this); else static if (op == "-") return longdouble_soft(rhs).ld_sub(this); else static if (op == "*") return longdouble_soft(rhs).ld_mul(this); + else static if (op == "/") return longdouble_soft(rhs).ld_div(this); else static if (op == "%") return longdouble_soft(rhs).ld_mod(this); else static assert(false, "Operator `"~op~"` is not implemented"); } From 954e5b6394a2a5e47cabf9e4ae13a5f3815db71b Mon Sep 17 00:00:00 2001 From: Dennis Date: Wed, 8 Jun 2022 15:14:15 +0200 Subject: [PATCH 10/23] Fix Issue 23170 - Array literal passed to map in lambda, then returned from nested function, is memory corrupted (#14193) --- src/dmd/expressionsem.d | 3 ++- test/fail_compilation/test23170.d | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/fail_compilation/test23170.d diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index a4079f4189..6e861f80c3 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -2048,7 +2048,8 @@ private bool functionParameters(const ref Loc loc, Scope* sc, if (global.params.useDIP1000 == FeatureState.enabled) err |= checkParamArgumentEscape(sc, fd, p, arg, false, false); } - else if (!(pStc & STC.return_)) + else if (!(pStc & STC.return_) && + ((global.params.useDIP1000 == FeatureState.enabled) || !(p.storageClass & STC.scopeinferred))) { /* Argument value cannot escape from the called function. */ diff --git a/test/fail_compilation/test23170.d b/test/fail_compilation/test23170.d new file mode 100644 index 0000000000..eb79cd8156 --- /dev/null +++ b/test/fail_compilation/test23170.d @@ -0,0 +1,12 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/test23170.d(10): Error: array literal in `@nogc` delegate `test23170.__lambda5` may cause a GC allocation +--- +*/ +// https://issues.dlang.org/show_bug.cgi?id=23170 + +@nogc: +enum lambda = () => badAlias([1, 2, 3]); +alias badAlias = (int[] array) => id(array); +int[] id(int[] array) { return array; } From 26e08f01d33215e1ae326fda530fb4a7fd9e7d6d Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Mon, 6 Jun 2022 20:14:07 -0700 Subject: [PATCH 11/23] fix Issue 23166 - seg fault when compiling with -inline --- src/dmd/inline.d | 5 ++++- test/compilable/test23166.d | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/compilable/test23166.d diff --git a/src/dmd/inline.d b/src/dmd/inline.d index 602c4362f2..2ce3130939 100644 --- a/src/dmd/inline.d +++ b/src/dmd/inline.d @@ -38,6 +38,7 @@ import dmd.init; import dmd.initsem; import dmd.mtype; import dmd.opover; +import dmd.printast; import dmd.statement; import dmd.tokens; import dmd.visitor; @@ -236,7 +237,7 @@ public: auto e1 = doInlineAs!Expression(ifs.ifbody, ids); assert(ids.foundReturn); auto e2 = doInlineAs!Expression(s3, ids); - + assert(e2); Expression e = new CondExp(econd.loc, econd, e1, e2); e.type = e1.type; if (e.type.ty == Ttuple) @@ -249,6 +250,7 @@ public: } else { + ids.foundReturn = false; auto e = doInlineAs!Expression(sx, ids); result = Expression.combine(result, e); } @@ -374,6 +376,7 @@ public: override void visit(ImportStatement s) { + //printf("ImportStatement.doInlineAs!%s()\n", Result.stringof.ptr); } override void visit(ForStatement s) diff --git a/test/compilable/test23166.d b/test/compilable/test23166.d new file mode 100644 index 0000000000..66da4cd696 --- /dev/null +++ b/test/compilable/test23166.d @@ -0,0 +1,22 @@ +// REQUIRED_ARGS: -inline + +// https://issues.dlang.org/show_bug.cgi?id=23166 + +// seg fault with -inline + +bool __equals(scope const char[] lhs, scope const char[] rhs) +{ + if (lhs.length != rhs.length) + return false; + + { + import core.stdc.string : memcmp; + return lhs.length == 0; + } + return true; +} + +int test(string type) +{ + return __equals(type, "as-is"); +} From 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae Mon Sep 17 00:00:00 2001 From: richard andrew cattermole Date: Sun, 12 Jun 2022 05:23:52 +1200 Subject: [PATCH 12/23] Fix Issue 23177 - ModuleInfo is not exported on Windows --- src/dmd/toobj.d | 1 + test/dshell/dll.d | 2 +- test/dshell/extra-files/dll/issue23177.d | 7 +++++++ test/dshell/extra-files/dll/mydll.d | 1 + test/dshell/extra-files/dll/testdll.d | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/dshell/extra-files/dll/issue23177.d diff --git a/src/dmd/toobj.d b/src/dmd/toobj.d index f9b1e953ba..b51954070f 100644 --- a/src/dmd/toobj.d +++ b/src/dmd/toobj.d @@ -222,6 +222,7 @@ void genModuleInfo(Module m) ////////////////////////////////////////////// objmod.moduleinfo(msym); + objmod.export_symbol(m.csym, 0); } /***************************************** diff --git a/test/dshell/dll.d b/test/dshell/dll.d index adaef53d9e..9451217f78 100644 --- a/test/dshell/dll.d +++ b/test/dshell/dll.d @@ -22,7 +22,7 @@ int main() enum mainExtra = `-fPIC -L-L$OUTPUT_BASE -L$DLL`; } - run(`$DMD -m$MODEL -shared -od=$OUTPUT_BASE -of=$DLL $SRC/mydll.d ` ~ dllExtra); + run(`$DMD -m$MODEL -shared -od=$OUTPUT_BASE -of=$DLL $SRC/mydll.d $SRC/issue23177.d ` ~ dllExtra); run(`$DMD -m$MODEL -I$SRC -od=$OUTPUT_BASE -of=$EXE_NAME $SRC/testdll.d ` ~ mainExtra); diff --git a/test/dshell/extra-files/dll/issue23177.d b/test/dshell/extra-files/dll/issue23177.d new file mode 100644 index 0000000000..0d463c080d --- /dev/null +++ b/test/dshell/extra-files/dll/issue23177.d @@ -0,0 +1,7 @@ +module issue23177; +// This module existing should trigger ModuleInfo to be referenced. +// Therefore if the fix for issue23177 works, this won't cause a linker error. + +shared static this() { + assert(1); +} diff --git a/test/dshell/extra-files/dll/mydll.d b/test/dshell/extra-files/dll/mydll.d index 65c389f6c4..d6677415e3 100644 --- a/test/dshell/extra-files/dll/mydll.d +++ b/test/dshell/extra-files/dll/mydll.d @@ -1,4 +1,5 @@ module mydll; +import issue23177; export: diff --git a/test/dshell/extra-files/dll/testdll.d b/test/dshell/extra-files/dll/testdll.d index a3fa8aebb6..bdc10858d1 100644 --- a/test/dshell/extra-files/dll/testdll.d +++ b/test/dshell/extra-files/dll/testdll.d @@ -1,4 +1,5 @@ import mydll; +import issue23177; void test1() { From a848e705db5c7dd3802e0dd0cd1c03a3523ad642 Mon Sep 17 00:00:00 2001 From: richard andrew cattermole Date: Sun, 12 Jun 2022 06:53:23 +1200 Subject: [PATCH 13/23] CI test runner does not know about MSVC linker export + import files generation message which causes failures when generated. --- test/dshell/test9377.d | 4 ++-- test/runnable/gdb15729.sh | 8 ++++++-- test/runnable/link14198a.sh | 2 +- test/runnable/link14834.sh | 2 +- test/runnable/link846.sh | 2 +- test/runnable/test10386.sh | 2 +- test/runnable/test13666.sh | 2 +- test/runnable/test13742.sh | 7 +++++-- test/runnable/test18456.sh | 8 ++++++-- test/runnable/test21723.sh | 8 ++++++-- test/runnable/test23148.sh | 8 ++++++-- test/tools/d_do_test.d | 11 ++++++++++- test/tools/dshell_prebuilt/dshell_prebuilt.d | 12 +++++++++++- 13 files changed, 57 insertions(+), 19 deletions(-) diff --git a/test/dshell/test9377.d b/test/dshell/test9377.d index 6ad26fd7d1..977a4a22e3 100644 --- a/test/dshell/test9377.d +++ b/test/dshell/test9377.d @@ -1,8 +1,8 @@ import dshell; void main() { - Vars.set("libname", "$OUTPUT_BASE/a$LIBEXT"); + Vars.set("libname", "$OUTPUT_BASE/a_b$LIBEXT"); run("$DMD -m$MODEL -I$EXTRA_FILES -of$libname -c $EXTRA_FILES/mul9377a.d $EXTRA_FILES/mul9377b.d -lib"); - run("$DMD -m$MODEL -I$EXTRA_FILES -of$OUTPUT_BASE/a$EXE $EXTRA_FILES/multi9377.d $libname"); + run("$DMD -m$MODEL -I$EXTRA_FILES -of$OUTPUT_BASE/a_b_full$EXE $EXTRA_FILES/multi9377.d $libname"); } diff --git a/test/runnable/gdb15729.sh b/test/runnable/gdb15729.sh index 042b170854..d76b97ac32 100755 --- a/test/runnable/gdb15729.sh +++ b/test/runnable/gdb15729.sh @@ -7,8 +7,12 @@ echo RESULT= p s.val " -$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}${SEP}lib15729.d -$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}gdb15729.d ${OUTPUT_BASE}${LIBEXT} + +libname=${OUTPUT_BASE}_dep${LIBEXT} + + +$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}${SEP}lib15729.d +$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}gdb15729.d ${libname} if [ $OS == "linux" ]; then echo "${GDB_SCRIPT}" > ${OUTPUT_BASE}.gdb diff --git a/test/runnable/link14198a.sh b/test/runnable/link14198a.sh index 468e36d7de..da6bf190bb 100755 --- a/test/runnable/link14198a.sh +++ b/test/runnable/link14198a.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}${LIBEXT} +libname=${OUTPUT_BASE}_dep${LIBEXT} # build library diff --git a/test/runnable/link14834.sh b/test/runnable/link14834.sh index e65ff06e4b..506623cc39 100755 --- a/test/runnable/link14834.sh +++ b/test/runnable/link14834.sh @@ -3,7 +3,7 @@ dir=${RESULTS_DIR}${SEP}runnable -libname=${OUTPUT_BASE}${LIBEXT} +libname=${OUTPUT_BASE}_dep${LIBEXT} exename=${OUTPUT_BASE}${EXE} $DMD -m${MODEL} -I${EXTRA_FILES} -lib -of${libname} ${EXTRA_FILES}${SEP}link14834a.d diff --git a/test/runnable/link846.sh b/test/runnable/link846.sh index a895b2f7ca..33e70dbec2 100755 --- a/test/runnable/link846.sh +++ b/test/runnable/link846.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}${LIBEXT} +libname=${OUTPUT_BASE}_dep${LIBEXT} # build library with -release $DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -release -boundscheck=off -lib ${EXTRA_FILES}${SEP}lib846.d diff --git a/test/runnable/test10386.sh b/test/runnable/test10386.sh index 3fa66ef1fe..49b2c9f646 100755 --- a/test/runnable/test10386.sh +++ b/test/runnable/test10386.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}${LIBEXT} +libname=${OUTPUT_BASE}_dep${LIBEXT} $DMD -m${MODEL} -Irunnable -I${EXTRA_FILES} -of${libname} -c ${EXTRA_FILES}${SEP}lib10386${SEP}foo${SEP}bar.d ${EXTRA_FILES}${SEP}lib10386${SEP}foo${SEP}package.d -lib diff --git a/test/runnable/test13666.sh b/test/runnable/test13666.sh index 195dd24ab0..e53878c632 100755 --- a/test/runnable/test13666.sh +++ b/test/runnable/test13666.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}${LIBEXT} +libname=${OUTPUT_BASE}_dep${LIBEXT} $DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}${SEP}lib13666.d diff --git a/test/runnable/test13742.sh b/test/runnable/test13742.sh index c09ef38cae..103c242a79 100755 --- a/test/runnable/test13742.sh +++ b/test/runnable/test13742.sh @@ -1,8 +1,11 @@ #!/usr/bin/env bash -$DMD -m${MODEL} -I${EXTRA_FILES} -lib -cov -of${OUTPUT_BASE}${LIBEXT} ${EXTRA_FILES}${SEP}lib13742a.d ${EXTRA_FILES}${SEP}lib13742b.d -$DMD -m${MODEL} -I${EXTRA_FILES} -cov -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}test13742.d ${OUTPUT_BASE}${LIBEXT} +libname=${OUTPUT_BASE}_dep${LIBEXT} + + +$DMD -m${MODEL} -I${EXTRA_FILES} -lib -cov -of${libname} ${EXTRA_FILES}${SEP}lib13742a.d ${EXTRA_FILES}${SEP}lib13742b.d +$DMD -m${MODEL} -I${EXTRA_FILES} -cov -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}test13742.d ${libname} ${OUTPUT_BASE}${EXE} --DRT-covopt=dstpath:${RESULTS_TEST_DIR} diff --git a/test/runnable/test18456.sh b/test/runnable/test18456.sh index f61d69a2a7..124587104b 100644 --- a/test/runnable/test18456.sh +++ b/test/runnable/test18456.sh @@ -1,8 +1,12 @@ #!/usr/bin/env bash + +libname=${OUTPUT_BASE}_dep${LIBEXT} + + # source file order is important -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib18456b.d ${EXTRA_FILES}/lib18456.d -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test18456.d ${OUTPUT_BASE}${LIBEXT} +$DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}/lib18456b.d ${EXTRA_FILES}/lib18456.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test18456.d ${libname} ${OUTPUT_BASE}${EXE} rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/runnable/test21723.sh b/test/runnable/test21723.sh index b8833b83b7..955a126165 100644 --- a/test/runnable/test21723.sh +++ b/test/runnable/test21723.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib21723a.d ${EXTRA_FILES}/lib21723b.d -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} -inline ${EXTRA_FILES}/test21723.d ${OUTPUT_BASE}${LIBEXT} + +libname=${OUTPUT_BASE}_dep${LIBEXT} + + +$DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}/lib21723a.d ${EXTRA_FILES}/lib21723b.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} -inline ${EXTRA_FILES}/test21723.d ${libname} rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/runnable/test23148.sh b/test/runnable/test23148.sh index 5d3c5e44e6..ceaa2876b0 100644 --- a/test/runnable/test23148.sh +++ b/test/runnable/test23148.sh @@ -1,6 +1,10 @@ #!/usr/bin/env bash -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib23148.d -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test23148.d ${OUTPUT_BASE}${LIBEXT} + +libname=${OUTPUT_BASE}_dep${LIBEXT} + + +$DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}/lib23148.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test23148.d ${libname} rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/tools/d_do_test.d b/test/tools/d_do_test.d index 88024900db..c1d9c75dcc 100755 --- a/test/tools/d_do_test.d +++ b/test/tools/d_do_test.d @@ -1730,13 +1730,22 @@ int tryMain(string[] args) } } + /// This should be similar in nature as ``dshell_prebuilt.d`` ``filterCompilerOutput`` function. void prepare(ref string compile_output) { if (compile_output.empty) return; compile_output = compile_output.unifyNewLine(); - compile_output = std.regex.replaceAll(compile_output, regex(`^DMD v2\.[0-9]+.*\n? DEBUG$`, "m"), ""); + compile_output = std.regex.replaceAll(compile_output, std.regex.regex(`^DMD v2\.[0-9]+.*\n? DEBUG$`, "m"), ""); + + if(envData.os == "windows" && envData.model != "32omf") { + // For MSVC linker, when it generates a binary file with an export table (with the import generation) it will add a message + // this message is both linker specific and platform specific, which we do not want our tests checked against. + // so we'll remove it prior to doing anything with the output. + compile_output = std.regex.replaceAll(compile_output, std.regex.regex(r"\s*Creating library [\S\\/]+ and object [\S\\/]+\r?\n?", "s"), ""); + } + compile_output = std.string.strip(compile_output); // replace test_result path with fixed ones compile_output = compile_output.replace(result_path, resultsDirReplacement); diff --git a/test/tools/dshell_prebuilt/dshell_prebuilt.d b/test/tools/dshell_prebuilt/dshell_prebuilt.d index 51991e0ea0..004f8052dd 100644 --- a/test/tools/dshell_prebuilt/dshell_prebuilt.d +++ b/test/tools/dshell_prebuilt/dshell_prebuilt.d @@ -326,10 +326,20 @@ private GrepResult grepLines(T)(T lineRange, string finalPattern) /** remove \r and the compiler debug header from the given string. + +This should be the same code that is used in ``d_do_test.d`` inside the inline function ``tryMain`` ``testCombination`` ``prepare``. */ string filterCompilerOutput(string output) { output = std.string.replace(output, "\r", ""); - output = std.regex.replaceAll(output, regex(`^DMD v2\.[0-9]+.*\n? DEBUG\n`, "m"), ""); + output = std.regex.replaceAll(output, std.regex.regex(`^DMD v2\.[0-9]+.*\n? DEBUG\n`, "m"), ""); + + version(Windows) { + // For MSVC linker, when it generates a binary file with an export table (with the import generation) it will add a message + // this message is both linker specific and platform specific, which we do not want our tests checked against. + // so we'll remove it prior to doing anything with the output. + output = std.regex.replaceAll(output, std.regex.regex(r"\s*Creating library [\S\\/]+ and object [\S\\/]+\r?\n?", "s"), ""); + } + return output; } From ea3ebd6a4ed8772b5a613fc95eefcdcd71444e5f Mon Sep 17 00:00:00 2001 From: richard andrew cattermole Date: Sun, 12 Jun 2022 09:38:06 +1200 Subject: [PATCH 14/23] Disable runnable/testmodule.d for Windows due to MSVC linker error with Unicode symbol names --- test/runnable/testmodule.d | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/runnable/testmodule.d b/test/runnable/testmodule.d index 45da7d1659..a6c9daddfc 100644 --- a/test/runnable/testmodule.d +++ b/test/runnable/testmodule.d @@ -1,5 +1,10 @@ // PERMUTE_ARGS: +// MS linker apparently doesn't (properly?) support Unicode in +// `/INCLUDE:symbol` linker directives. +// This has been upstreamed from LDC. +// DISABLED: win + // $HeadURL$ // $Date$ // $Author$ From 728461b1edd68d616c9e037281f1d6e4f5c73a34 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 12 Jun 2022 17:33:55 +0200 Subject: [PATCH 15/23] Revert "Disable runnable/testmodule.d for Windows due to MSVC linker error with Unicode symbol names" This reverts commit ea3ebd6a4ed8772b5a613fc95eefcdcd71444e5f. --- test/runnable/testmodule.d | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/runnable/testmodule.d b/test/runnable/testmodule.d index a6c9daddfc..45da7d1659 100644 --- a/test/runnable/testmodule.d +++ b/test/runnable/testmodule.d @@ -1,10 +1,5 @@ // PERMUTE_ARGS: -// MS linker apparently doesn't (properly?) support Unicode in -// `/INCLUDE:symbol` linker directives. -// This has been upstreamed from LDC. -// DISABLED: win - // $HeadURL$ // $Date$ // $Author$ From 690095401d7acc2aeafbf73f634515f7801223ca Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 12 Jun 2022 17:33:55 +0200 Subject: [PATCH 16/23] Revert "CI test runner does not know about MSVC linker export + import files generation message which causes failures when generated." This reverts commit a848e705db5c7dd3802e0dd0cd1c03a3523ad642. --- test/dshell/test9377.d | 4 ++-- test/runnable/gdb15729.sh | 8 ++------ test/runnable/link14198a.sh | 2 +- test/runnable/link14834.sh | 2 +- test/runnable/link846.sh | 2 +- test/runnable/test10386.sh | 2 +- test/runnable/test13666.sh | 2 +- test/runnable/test13742.sh | 7 ++----- test/runnable/test18456.sh | 8 ++------ test/runnable/test21723.sh | 8 ++------ test/runnable/test23148.sh | 8 ++------ test/tools/d_do_test.d | 11 +---------- test/tools/dshell_prebuilt/dshell_prebuilt.d | 12 +----------- 13 files changed, 19 insertions(+), 57 deletions(-) diff --git a/test/dshell/test9377.d b/test/dshell/test9377.d index 977a4a22e3..6ad26fd7d1 100644 --- a/test/dshell/test9377.d +++ b/test/dshell/test9377.d @@ -1,8 +1,8 @@ import dshell; void main() { - Vars.set("libname", "$OUTPUT_BASE/a_b$LIBEXT"); + Vars.set("libname", "$OUTPUT_BASE/a$LIBEXT"); run("$DMD -m$MODEL -I$EXTRA_FILES -of$libname -c $EXTRA_FILES/mul9377a.d $EXTRA_FILES/mul9377b.d -lib"); - run("$DMD -m$MODEL -I$EXTRA_FILES -of$OUTPUT_BASE/a_b_full$EXE $EXTRA_FILES/multi9377.d $libname"); + run("$DMD -m$MODEL -I$EXTRA_FILES -of$OUTPUT_BASE/a$EXE $EXTRA_FILES/multi9377.d $libname"); } diff --git a/test/runnable/gdb15729.sh b/test/runnable/gdb15729.sh index d76b97ac32..042b170854 100755 --- a/test/runnable/gdb15729.sh +++ b/test/runnable/gdb15729.sh @@ -7,12 +7,8 @@ echo RESULT= p s.val " - -libname=${OUTPUT_BASE}_dep${LIBEXT} - - -$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}${SEP}lib15729.d -$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}gdb15729.d ${libname} +$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}${SEP}lib15729.d +$DMD -g -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}gdb15729.d ${OUTPUT_BASE}${LIBEXT} if [ $OS == "linux" ]; then echo "${GDB_SCRIPT}" > ${OUTPUT_BASE}.gdb diff --git a/test/runnable/link14198a.sh b/test/runnable/link14198a.sh index da6bf190bb..468e36d7de 100755 --- a/test/runnable/link14198a.sh +++ b/test/runnable/link14198a.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}_dep${LIBEXT} +libname=${OUTPUT_BASE}${LIBEXT} # build library diff --git a/test/runnable/link14834.sh b/test/runnable/link14834.sh index 506623cc39..e65ff06e4b 100755 --- a/test/runnable/link14834.sh +++ b/test/runnable/link14834.sh @@ -3,7 +3,7 @@ dir=${RESULTS_DIR}${SEP}runnable -libname=${OUTPUT_BASE}_dep${LIBEXT} +libname=${OUTPUT_BASE}${LIBEXT} exename=${OUTPUT_BASE}${EXE} $DMD -m${MODEL} -I${EXTRA_FILES} -lib -of${libname} ${EXTRA_FILES}${SEP}link14834a.d diff --git a/test/runnable/link846.sh b/test/runnable/link846.sh index 33e70dbec2..a895b2f7ca 100755 --- a/test/runnable/link846.sh +++ b/test/runnable/link846.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}_dep${LIBEXT} +libname=${OUTPUT_BASE}${LIBEXT} # build library with -release $DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -release -boundscheck=off -lib ${EXTRA_FILES}${SEP}lib846.d diff --git a/test/runnable/test10386.sh b/test/runnable/test10386.sh index 49b2c9f646..3fa66ef1fe 100755 --- a/test/runnable/test10386.sh +++ b/test/runnable/test10386.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}_dep${LIBEXT} +libname=${OUTPUT_BASE}${LIBEXT} $DMD -m${MODEL} -Irunnable -I${EXTRA_FILES} -of${libname} -c ${EXTRA_FILES}${SEP}lib10386${SEP}foo${SEP}bar.d ${EXTRA_FILES}${SEP}lib10386${SEP}foo${SEP}package.d -lib diff --git a/test/runnable/test13666.sh b/test/runnable/test13666.sh index e53878c632..195dd24ab0 100755 --- a/test/runnable/test13666.sh +++ b/test/runnable/test13666.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}_dep${LIBEXT} +libname=${OUTPUT_BASE}${LIBEXT} $DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}${SEP}lib13666.d diff --git a/test/runnable/test13742.sh b/test/runnable/test13742.sh index 103c242a79..c09ef38cae 100755 --- a/test/runnable/test13742.sh +++ b/test/runnable/test13742.sh @@ -1,11 +1,8 @@ #!/usr/bin/env bash -libname=${OUTPUT_BASE}_dep${LIBEXT} - - -$DMD -m${MODEL} -I${EXTRA_FILES} -lib -cov -of${libname} ${EXTRA_FILES}${SEP}lib13742a.d ${EXTRA_FILES}${SEP}lib13742b.d -$DMD -m${MODEL} -I${EXTRA_FILES} -cov -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}test13742.d ${libname} +$DMD -m${MODEL} -I${EXTRA_FILES} -lib -cov -of${OUTPUT_BASE}${LIBEXT} ${EXTRA_FILES}${SEP}lib13742a.d ${EXTRA_FILES}${SEP}lib13742b.d +$DMD -m${MODEL} -I${EXTRA_FILES} -cov -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}${SEP}test13742.d ${OUTPUT_BASE}${LIBEXT} ${OUTPUT_BASE}${EXE} --DRT-covopt=dstpath:${RESULTS_TEST_DIR} diff --git a/test/runnable/test18456.sh b/test/runnable/test18456.sh index 124587104b..f61d69a2a7 100644 --- a/test/runnable/test18456.sh +++ b/test/runnable/test18456.sh @@ -1,12 +1,8 @@ #!/usr/bin/env bash - -libname=${OUTPUT_BASE}_dep${LIBEXT} - - # source file order is important -$DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}/lib18456b.d ${EXTRA_FILES}/lib18456.d -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test18456.d ${libname} +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib18456b.d ${EXTRA_FILES}/lib18456.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test18456.d ${OUTPUT_BASE}${LIBEXT} ${OUTPUT_BASE}${EXE} rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/runnable/test21723.sh b/test/runnable/test21723.sh index 955a126165..b8833b83b7 100644 --- a/test/runnable/test21723.sh +++ b/test/runnable/test21723.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -libname=${OUTPUT_BASE}_dep${LIBEXT} - - -$DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}/lib21723a.d ${EXTRA_FILES}/lib21723b.d -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} -inline ${EXTRA_FILES}/test21723.d ${libname} +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib21723a.d ${EXTRA_FILES}/lib21723b.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} -inline ${EXTRA_FILES}/test21723.d ${OUTPUT_BASE}${LIBEXT} rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/runnable/test23148.sh b/test/runnable/test23148.sh index ceaa2876b0..5d3c5e44e6 100644 --- a/test/runnable/test23148.sh +++ b/test/runnable/test23148.sh @@ -1,10 +1,6 @@ #!/usr/bin/env bash - -libname=${OUTPUT_BASE}_dep${LIBEXT} - - -$DMD -m${MODEL} -I${EXTRA_FILES} -of${libname} -lib ${EXTRA_FILES}/lib23148.d -$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test23148.d ${libname} +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${LIBEXT} -lib ${EXTRA_FILES}/lib23148.d +$DMD -m${MODEL} -I${EXTRA_FILES} -of${OUTPUT_BASE}${EXE} ${EXTRA_FILES}/test23148.d ${OUTPUT_BASE}${LIBEXT} rm_retry ${OUTPUT_BASE}{${LIBEXT},${EXE}} diff --git a/test/tools/d_do_test.d b/test/tools/d_do_test.d index c1d9c75dcc..88024900db 100755 --- a/test/tools/d_do_test.d +++ b/test/tools/d_do_test.d @@ -1730,22 +1730,13 @@ int tryMain(string[] args) } } - /// This should be similar in nature as ``dshell_prebuilt.d`` ``filterCompilerOutput`` function. void prepare(ref string compile_output) { if (compile_output.empty) return; compile_output = compile_output.unifyNewLine(); - compile_output = std.regex.replaceAll(compile_output, std.regex.regex(`^DMD v2\.[0-9]+.*\n? DEBUG$`, "m"), ""); - - if(envData.os == "windows" && envData.model != "32omf") { - // For MSVC linker, when it generates a binary file with an export table (with the import generation) it will add a message - // this message is both linker specific and platform specific, which we do not want our tests checked against. - // so we'll remove it prior to doing anything with the output. - compile_output = std.regex.replaceAll(compile_output, std.regex.regex(r"\s*Creating library [\S\\/]+ and object [\S\\/]+\r?\n?", "s"), ""); - } - + compile_output = std.regex.replaceAll(compile_output, regex(`^DMD v2\.[0-9]+.*\n? DEBUG$`, "m"), ""); compile_output = std.string.strip(compile_output); // replace test_result path with fixed ones compile_output = compile_output.replace(result_path, resultsDirReplacement); diff --git a/test/tools/dshell_prebuilt/dshell_prebuilt.d b/test/tools/dshell_prebuilt/dshell_prebuilt.d index 004f8052dd..51991e0ea0 100644 --- a/test/tools/dshell_prebuilt/dshell_prebuilt.d +++ b/test/tools/dshell_prebuilt/dshell_prebuilt.d @@ -326,20 +326,10 @@ private GrepResult grepLines(T)(T lineRange, string finalPattern) /** remove \r and the compiler debug header from the given string. - -This should be the same code that is used in ``d_do_test.d`` inside the inline function ``tryMain`` ``testCombination`` ``prepare``. */ string filterCompilerOutput(string output) { output = std.string.replace(output, "\r", ""); - output = std.regex.replaceAll(output, std.regex.regex(`^DMD v2\.[0-9]+.*\n? DEBUG\n`, "m"), ""); - - version(Windows) { - // For MSVC linker, when it generates a binary file with an export table (with the import generation) it will add a message - // this message is both linker specific and platform specific, which we do not want our tests checked against. - // so we'll remove it prior to doing anything with the output. - output = std.regex.replaceAll(output, std.regex.regex(r"\s*Creating library [\S\\/]+ and object [\S\\/]+\r?\n?", "s"), ""); - } - + output = std.regex.replaceAll(output, regex(`^DMD v2\.[0-9]+.*\n? DEBUG\n`, "m"), ""); return output; } From 4ee3ac43f5235d3798c0c0cd9f317f5e1aa07ce4 Mon Sep 17 00:00:00 2001 From: Martin Kinkelin Date: Sun, 12 Jun 2022 17:33:55 +0200 Subject: [PATCH 17/23] Revert "Fix Issue 23177 - ModuleInfo is not exported on Windows" This reverts commit 2aabe864da7c95ea8eb8abbca7c4f0b1dcfe55ae. --- src/dmd/toobj.d | 1 - test/dshell/dll.d | 2 +- test/dshell/extra-files/dll/issue23177.d | 7 ------- test/dshell/extra-files/dll/mydll.d | 1 - test/dshell/extra-files/dll/testdll.d | 1 - 5 files changed, 1 insertion(+), 11 deletions(-) delete mode 100644 test/dshell/extra-files/dll/issue23177.d diff --git a/src/dmd/toobj.d b/src/dmd/toobj.d index b51954070f..f9b1e953ba 100644 --- a/src/dmd/toobj.d +++ b/src/dmd/toobj.d @@ -222,7 +222,6 @@ void genModuleInfo(Module m) ////////////////////////////////////////////// objmod.moduleinfo(msym); - objmod.export_symbol(m.csym, 0); } /***************************************** diff --git a/test/dshell/dll.d b/test/dshell/dll.d index 9451217f78..adaef53d9e 100644 --- a/test/dshell/dll.d +++ b/test/dshell/dll.d @@ -22,7 +22,7 @@ int main() enum mainExtra = `-fPIC -L-L$OUTPUT_BASE -L$DLL`; } - run(`$DMD -m$MODEL -shared -od=$OUTPUT_BASE -of=$DLL $SRC/mydll.d $SRC/issue23177.d ` ~ dllExtra); + run(`$DMD -m$MODEL -shared -od=$OUTPUT_BASE -of=$DLL $SRC/mydll.d ` ~ dllExtra); run(`$DMD -m$MODEL -I$SRC -od=$OUTPUT_BASE -of=$EXE_NAME $SRC/testdll.d ` ~ mainExtra); diff --git a/test/dshell/extra-files/dll/issue23177.d b/test/dshell/extra-files/dll/issue23177.d deleted file mode 100644 index 0d463c080d..0000000000 --- a/test/dshell/extra-files/dll/issue23177.d +++ /dev/null @@ -1,7 +0,0 @@ -module issue23177; -// This module existing should trigger ModuleInfo to be referenced. -// Therefore if the fix for issue23177 works, this won't cause a linker error. - -shared static this() { - assert(1); -} diff --git a/test/dshell/extra-files/dll/mydll.d b/test/dshell/extra-files/dll/mydll.d index d6677415e3..65c389f6c4 100644 --- a/test/dshell/extra-files/dll/mydll.d +++ b/test/dshell/extra-files/dll/mydll.d @@ -1,5 +1,4 @@ module mydll; -import issue23177; export: diff --git a/test/dshell/extra-files/dll/testdll.d b/test/dshell/extra-files/dll/testdll.d index bdc10858d1..a3fa8aebb6 100644 --- a/test/dshell/extra-files/dll/testdll.d +++ b/test/dshell/extra-files/dll/testdll.d @@ -1,5 +1,4 @@ import mydll; -import issue23177; void test1() { From 84ee8c96ec85782ef33e6ee25aaa7005bf477580 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Mon, 13 Jun 2022 20:05:31 +0200 Subject: [PATCH 18/23] fix Issue 23181 - [REG 2.099] AssertError@src/dmd/e2ir.d(6094): Trying reference _d_arraysetctor --- src/dmd/e2ir.d | 5 ++++- src/dmd/expressionsem.d | 4 +++- test/fail_compilation/fail23181.d | 16 ++++++++++++++++ test/runnable/test23181.d | 27 +++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 test/fail_compilation/fail23181.d create mode 100644 test/runnable/test23181.d diff --git a/src/dmd/e2ir.d b/src/dmd/e2ir.d index 8e45cc23b2..bc8a2ebf66 100644 --- a/src/dmd/e2ir.d +++ b/src/dmd/e2ir.d @@ -6124,7 +6124,10 @@ Lagain: /* Need to do postblit/destructor. * void *_d_arraysetassign(void *p, void *value, int dim, TypeInfo ti); */ - assert(op != EXP.construct, "Trying reference _d_arraysetctor, this should not happen!"); + if (op == EXP.construct) + { + assert(0, "Trying reference _d_arraysetctor, this should not happen!"); + } r = RTLSYM.ARRAYSETASSIGN; evalue = el_una(OPaddr, TYnptr, evalue); // This is a hack so we can call postblits on const/immutable objects. diff --git a/src/dmd/expressionsem.d b/src/dmd/expressionsem.d index 6e861f80c3..0617b69ccc 100644 --- a/src/dmd/expressionsem.d +++ b/src/dmd/expressionsem.d @@ -9927,9 +9927,11 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor ae.e2.type.nextOf && ae.e1.type.nextOf.mutableOf.equals(ae.e2.type.nextOf.mutableOf); + /* Unlike isArrayCtor above, lower all Rvalues. If the RHS is a literal, + * then we do want to make a temporary for it and call its destructor. + */ const isArraySetCtor = (ae.e1.isSliceExp || ae.e1.type.ty == Tsarray) && - ae.e2.isLvalue && (ae.e2.type.ty == Tstruct || ae.e2.type.ty == Tsarray) && ae.e1.type.nextOf && ae.e1.type.nextOf.equivalent(ae.e2.type); diff --git a/test/fail_compilation/fail23181.d b/test/fail_compilation/fail23181.d new file mode 100644 index 0000000000..519244c1cd --- /dev/null +++ b/test/fail_compilation/fail23181.d @@ -0,0 +1,16 @@ +/* https://issues.dlang.org/show_bug.cgi?id=23181 +TEST_OUTPUT: +--- +$p:druntime/import/core/lifetime.d$($n$): Error: struct `fail23181.fail23181.NoPostblit` is not copyable because it has a disabled postblit +$p:druntime/import/core/internal/array/construction.d$($n$): Error: template instance `core.lifetime.copyEmplace!(NoPostblit, NoPostblit)` error instantiating +fail_compilation/fail23181.d(15): instantiated from here: `_d_arraysetctor!(NoPostblit[], NoPostblit)` +--- +*/ +void fail23181() +{ + struct NoPostblit + { + @disable this(this); + } + NoPostblit[4] noblit23181 = NoPostblit(); +} diff --git a/test/runnable/test23181.d b/test/runnable/test23181.d new file mode 100644 index 0000000000..b961690a2b --- /dev/null +++ b/test/runnable/test23181.d @@ -0,0 +1,27 @@ +// https://issues.dlang.org/show_bug.cgi?id=23181 +void main() +{ + int count; + struct HasDtor + { + ~this() { ++count; } + } + + // array[] = elem() + // -> creates temporary to construct array and calls destructor. + { + count = 0; + HasDtor[4] dtor1 = HasDtor(); + assert(count == 1); + } + assert(count == 5); + + // array[] = array[elem()] + // -> constructs array using direct emplacement. + { + count = 0; + HasDtor[2] dtor2 = [HasDtor(), HasDtor()]; + assert(count == 0); + } + assert(count == 2); +} From cdd3e2ae54798148a2e0130e4bd01300ccf4fe86 Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Wed, 15 Jun 2022 13:22:45 +0300 Subject: [PATCH 19/23] Fix Issue 23120 - dmd illegal instruction throw expression --- src/dmd/e2ir.d | 9 +++++++++ test/runnable/noreturn1.d | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/src/dmd/e2ir.d b/src/dmd/e2ir.d index bc8a2ebf66..0442eb6f79 100644 --- a/src/dmd/e2ir.d +++ b/src/dmd/e2ir.d @@ -2079,6 +2079,15 @@ elem* toElem(Expression e, IRState *irs) return e; } + /* + https://issues.dlang.org/show_bug.cgi?id=23120 + + If rhs is a noreturn expression, then there is no point + to generate any code for the noreturen variable. + */ + if (ae.e2.type.isTypeNoreturn()) + return setResult(toElem(ae.e2, irs)); + Type t1b = ae.e1.type.toBasetype(); // Look for array.length = n diff --git a/test/runnable/noreturn1.d b/test/runnable/noreturn1.d index 7d15b54a21..5ed46c1625 100644 --- a/test/runnable/noreturn1.d +++ b/test/runnable/noreturn1.d @@ -261,6 +261,37 @@ void testThrowDtor() /*****************************************/ +noreturn func() +{ + throw new Exception("B"); +} + +// https://issues.dlang.org/show_bug.cgi?id=23120 +void test23120() +{ + string a; + try + { + noreturn q = throw new Exception ("A"); + } + catch(Exception e) + { + a ~= e.msg; + } + + try + { + noreturn z = func(); + } + catch(Exception e) + { + a ~= e.msg; + } + + assert(a == "AB"); +} + +/*****************************************/ int main() { test1(); @@ -269,5 +300,6 @@ int main() testThrowExpression(); testThrowSideEffect(); testThrowDtor(); + test23120(); return 0; } From 10f612d3bce5b560ccef7098a089df4ceeb2c006 Mon Sep 17 00:00:00 2001 From: Boris Carvajal Date: Fri, 17 Jun 2022 04:21:14 -0400 Subject: [PATCH 20/23] Fix Issue 23172 - [REG2.100] Wrong cast inserted for ternary operator and non-int enums --- src/dmd/dcast.d | 11 ++++++++--- test/compilable/test23172.d | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 test/compilable/test23172.d diff --git a/src/dmd/dcast.d b/src/dmd/dcast.d index 853f659663..6afa1c966b 100644 --- a/src/dmd/dcast.d +++ b/src/dmd/dcast.d @@ -1107,9 +1107,14 @@ MATCH implicitConvTo(Expression e, Type t) MATCH visitCond(CondExp e) { - auto result = visit(e); - if (result != MATCH.nomatch) - return result; + e.econd = e.econd.optimize(WANTvalue); + const opt = e.econd.toBool(); + if (opt.isPresent()) + { + auto result = visit(e); + if (result != MATCH.nomatch) + return result; + } MATCH m1 = e.e1.implicitConvTo(t); MATCH m2 = e.e2.implicitConvTo(t); diff --git a/test/compilable/test23172.d b/test/compilable/test23172.d new file mode 100644 index 0000000000..18b6d4ce8c --- /dev/null +++ b/test/compilable/test23172.d @@ -0,0 +1,33 @@ +// https://issues.dlang.org/show_bug.cgi?id=23172 + +enum E : ubyte { // `ubyte` is needed to trigger the bug + A, + B, +} + +struct S { + E e; +} + +void compiles(bool b, S s) { + E e = b ? E.A : s.e; +} + +void errors(bool b, const ref S s) { + E e = b ? E.A : s.e; +} + +// from https://issues.dlang.org/show_bug.cgi?id=23188 + +enum Status : byte +{ + A, B, C +} + +Status foo() +{ + Status t = Status.A; + const Status s = t; + + return (s == Status.A) ? Status.B : s; // <-- here +} From 2c336dfa825c481f0a32f495ce26232e45d820a4 Mon Sep 17 00:00:00 2001 From: RazvanN7 Date: Tue, 5 Jul 2022 17:08:26 +0300 Subject: [PATCH 21/23] Fix Issue 21443 - scope (failure) with a return breaks safety --- changelog/deprecate_scope_failure_return.dd | 23 +++++++++++++++++++++ src/dmd/statementsem.d | 16 +++++++++++--- test/fail_compilation/fail6889.d | 2 +- test/fail_compilation/test21443.d | 21 +++++++++++++++++++ test/runnable/warning1.d | 9 -------- 5 files changed, 58 insertions(+), 13 deletions(-) create mode 100644 changelog/deprecate_scope_failure_return.dd create mode 100644 test/fail_compilation/test21443.d diff --git a/changelog/deprecate_scope_failure_return.dd b/changelog/deprecate_scope_failure_return.dd new file mode 100644 index 0000000000..19b9add960 --- /dev/null +++ b/changelog/deprecate_scope_failure_return.dd @@ -0,0 +1,23 @@ +`scope(failure)` blocks that contain `return` statements are now deprecated + +Starting with this release, having a `return` statement in the body of a `scope(failure)` +statement is deprecated. Having the ability to `return` from such blocks is error prone since currently, Errors are also handled by `scope(failure)`. This leads to the following situation: + +--- +ulong get () @safe nothrow +{ + scope (failure) return 10; + throw new Error(""); +} + +void main () @safe +{ + assert(get() == 10); // passes +} +--- + +where an error is circumvented by a return. If a return is indeed desired +in such situations, then the solution is to simply use a try-catch block +for the function body. + +Note: `scope(exit)` and `scope(success)` already present this restriction. diff --git a/src/dmd/statementsem.d b/src/dmd/statementsem.d index 2916bbc38d..c1c2dc92e1 100644 --- a/src/dmd/statementsem.d +++ b/src/dmd/statementsem.d @@ -2829,10 +2829,20 @@ package (dmd) extern (C++) final class StatementSemanticVisitor : Visitor rs.error("`return` statements cannot be in contracts"); errors = true; } - if (sc.os && sc.os.tok != TOK.onScopeFailure) + if (sc.os) { - rs.error("`return` statements cannot be in `%s` bodies", Token.toChars(sc.os.tok)); - errors = true; + // @@@DEPRECATED_2.112@@@ + // Deprecated in 2.100, transform into an error in 2.112 + if (sc.os.tok == TOK.onScopeFailure) + { + rs.deprecation("`return` statements cannot be in `scope(failure)` bodies."); + deprecationSupplemental(rs.loc, "Use try-catch blocks for this purpose"); + } + else + { + rs.error("`return` statements cannot be in `%s` bodies", Token.toChars(sc.os.tok)); + errors = true; + } } if (sc.tf) { diff --git a/test/fail_compilation/fail6889.d b/test/fail_compilation/fail6889.d index aa18977090..ee84a84ce7 100644 --- a/test/fail_compilation/fail6889.d +++ b/test/fail_compilation/fail6889.d @@ -55,7 +55,7 @@ L1: scope(failure) { L2: goto L1; } // OK goto L2; // NG - scope(failure) { return; } // OK + foreach (i; 0..1) { diff --git a/test/fail_compilation/test21443.d b/test/fail_compilation/test21443.d new file mode 100644 index 0000000000..2d99524da3 --- /dev/null +++ b/test/fail_compilation/test21443.d @@ -0,0 +1,21 @@ +// https://issues.dlang.org/show_bug.cgi?id=21443 +// REQUIRED_ARGS: -de + +/* +TEST_OUTPUT: +--- +fail_compilation/test21443.d(14): Deprecation: `return` statements cannot be in `scope(failure)` bodies. +fail_compilation/test21443.d(14): Use try-catch blocks for this purpose +--- +*/ + +ulong get () @safe nothrow +{ + scope (failure) return 10; + throw new Error(""); +} + +void main () @safe +{ + assert(get() == 10); // passes +} diff --git a/test/runnable/warning1.d b/test/runnable/warning1.d index 537088e97c..01ac20c0ba 100644 --- a/test/runnable/warning1.d +++ b/test/runnable/warning1.d @@ -133,15 +133,6 @@ void test6518() } } -/******************************************/ -// https://issues.dlang.org/show_bug.cgi?id=7232 - -bool test7232() -{ - scope(failure) return false; - return true; -} - /***************************************************/ struct S9332 From fa80a8bb79808bee6629d84cbc83636399077d15 Mon Sep 17 00:00:00 2001 From: Martin Nowak Date: Fri, 8 Jul 2022 16:19:02 +0200 Subject: [PATCH 22/23] bump VERSION to v2.100.1-beta.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 5ea2ba0d8e..7e72eaed4b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.100.0 +v2.100.1-beta.1 From f282f98f7b8cadd4e37fb95c78d3590756f817e7 Mon Sep 17 00:00:00 2001 From: Iain Buclaw Date: Sat, 9 Jul 2022 16:08:44 +0200 Subject: [PATCH 23/23] bump VERSION to v2.100.1 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 7e72eaed4b..83a14f57e1 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v2.100.1-beta.1 +v2.100.1