From patchwork Tue Nov 30 15:11:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 48296 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 48210385BF99 for ; Tue, 30 Nov 2021 15:12:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48210385BF99 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638285156; bh=Z+guBZr4ukyS+EWjv49CFUilqla/8N1UiMIJfD1vkxI=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=jvJfOFO4vqyRsWWkjRIiTTcMIFxb5Vfelhmf9In1Ftoo3noEvGMia59ZsZ8/1EIdz gFyaPxlj6wG7HtJcFthGczoxKBrAtqlOprtEb4RmwPHLOAxbGOwrw8uY8po6K6mSkz mgRi1LOIjyyiV2GLkh3vjloAS3Xoc/lCCJKIvdqY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-202.mailbox.org (mout-p-202.mailbox.org [IPv6:2001:67c:2050::465:202]) by sourceware.org (Postfix) with ESMTPS id 2D709385C017 for ; Tue, 30 Nov 2021 15:11:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 2D709385C017 Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-202.mailbox.org (Postfix) with ESMTPS id 4J3QfX2XL8zQjh5; Tue, 30 Nov 2021 16:11:32 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de To: gcc-patches@gcc.gnu.org Subject: [committed 17/19] libphobos: Import druntime testsuite v2.098.0-beta.1 (e6caaab9) Date: Tue, 30 Nov 2021 16:11:12 +0100 Message-Id: <20211130151112.631900-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_LOTSOFHASH, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This is the updated D runtime library testsuite. Bootstrapped, regression tested, and committed to mainline. Regards, Iain. --- libphobos/ChangeLog: * testsuite/libphobos.aa/test_aa.d: Update test. * testsuite/libphobos.exceptions/unknown_gc.d: Likewise. * testsuite/libphobos.hash/test_hash.d: Likewise. * testsuite/libphobos.shared/host.c: Likewise. * testsuite/libphobos.shared/load.d: Likewise. * testsuite/libphobos.shared/load_13414.d: Likewise. * testsuite/libphobos.thread/fiber_guard_page.d: Likewise. * testsuite/libphobos.thread/tlsgc_sections.d: Likewise. * testsuite/libphobos.shared/link_mod_collision.d: Removed. * testsuite/libphobos.shared/load_mod_collision.d: Removed. * testsuite/libphobos.allocations/alloc_from_assert.d: New test. * testsuite/libphobos.betterc/test18828.d: New test. * testsuite/libphobos.betterc/test19416.d: New test. * testsuite/libphobos.betterc/test19421.d: New test. * testsuite/libphobos.betterc/test19561.d: New test. * testsuite/libphobos.betterc/test19924.d: New test. * testsuite/libphobos.betterc/test20088.d: New test. * testsuite/libphobos.betterc/test20613.d: New test. * testsuite/libphobos.config/test19433.d: New test. * testsuite/libphobos.config/test20459.d: New test. * testsuite/libphobos.exceptions/assert_fail.d: New test. * testsuite/libphobos.exceptions/catch_in_finally.d: New test. * testsuite/libphobos.exceptions/future_message.d: New test. * testsuite/libphobos.exceptions/long_backtrace_trunc.d: New test. * testsuite/libphobos.exceptions/refcounted.d: New test. * testsuite/libphobos.exceptions/rt_trap_exceptions.d: New test. * testsuite/libphobos.exceptions/rt_trap_exceptions_drt.d: New test. * testsuite/libphobos.gc/attributes.d: New test. * testsuite/libphobos.gc/forkgc.d: New test. * testsuite/libphobos.gc/forkgc2.d: New test. * testsuite/libphobos.gc/nocollect.d: New test. * testsuite/libphobos.gc/precisegc.d: New test. * testsuite/libphobos.gc/recoverfree.d: New test. * testsuite/libphobos.gc/sigmaskgc.d: New test. * testsuite/libphobos.gc/startbackgc.d: New test. * testsuite/libphobos.imports/bug18193.d: New test. * testsuite/libphobos.init_fini/custom_gc.d: New test. * testsuite/libphobos.init_fini/test18996.d: New test. * testsuite/libphobos.lifetime/large_aggregate_destroy_21097.d: New test. * testsuite/libphobos.thread/external_threads.d: New test. * testsuite/libphobos.thread/join_detach.d: New test. * testsuite/libphobos.thread/test_import.d: New test. * testsuite/libphobos.thread/tlsstack.d: New test. * testsuite/libphobos.typeinfo/enum_.d: New test. * testsuite/libphobos.typeinfo/isbaseof.d: New test. * testsuite/libphobos.unittest/customhandler.d: New test. --- libphobos/testsuite/libphobos.aa/test_aa.d | 79 ++- .../libphobos.allocations/alloc_from_assert.d | 25 + .../testsuite/libphobos.betterc/test18828.d | 10 + .../testsuite/libphobos.betterc/test19416.d | 14 + .../testsuite/libphobos.betterc/test19421.d | 13 + .../testsuite/libphobos.betterc/test19561.d | 16 + .../testsuite/libphobos.betterc/test19924.d | 15 + .../testsuite/libphobos.betterc/test20088.d | 14 + .../testsuite/libphobos.betterc/test20613.d | 18 + .../testsuite/libphobos.config/test19433.d | 7 + .../testsuite/libphobos.config/test20459.d | 5 + .../libphobos.exceptions/assert_fail.d | 564 ++++++++++++++++++ .../libphobos.exceptions/catch_in_finally.d | 191 ++++++ .../libphobos.exceptions/future_message.d | 71 +++ .../long_backtrace_trunc.d | 37 ++ .../libphobos.exceptions/refcounted.d | 96 +++ .../libphobos.exceptions/rt_trap_exceptions.d | 15 + .../rt_trap_exceptions_drt.d | 11 + .../libphobos.exceptions/unknown_gc.d | 4 + libphobos/testsuite/libphobos.gc/attributes.d | 30 + libphobos/testsuite/libphobos.gc/forkgc.d | 36 ++ libphobos/testsuite/libphobos.gc/forkgc2.d | 22 + libphobos/testsuite/libphobos.gc/nocollect.d | 15 + libphobos/testsuite/libphobos.gc/precisegc.d | 126 ++++ .../testsuite/libphobos.gc/recoverfree.d | 13 + libphobos/testsuite/libphobos.gc/sigmaskgc.d | 42 ++ .../testsuite/libphobos.gc/startbackgc.d | 22 + .../testsuite/libphobos.hash/test_hash.d | 140 ++++- .../testsuite/libphobos.imports/bug18193.d | 4 + .../testsuite/libphobos.init_fini/custom_gc.d | 203 +++++++ .../testsuite/libphobos.init_fini/test18996.d | 13 + .../large_aggregate_destroy_21097.d | 78 +++ libphobos/testsuite/libphobos.shared/host.c | 8 + .../libphobos.shared/link_mod_collision.d | 5 - libphobos/testsuite/libphobos.shared/load.d | 1 - .../testsuite/libphobos.shared/load_13414.d | 13 +- .../libphobos.shared/load_mod_collision.d | 14 - .../libphobos.thread/external_threads.d | 50 ++ .../libphobos.thread/fiber_guard_page.d | 4 + .../testsuite/libphobos.thread/join_detach.d | 20 + .../testsuite/libphobos.thread/test_import.d | 7 + .../libphobos.thread/tlsgc_sections.d | 61 +- .../testsuite/libphobos.thread/tlsstack.d | 38 ++ .../testsuite/libphobos.typeinfo/enum_.d | 21 + .../testsuite/libphobos.typeinfo/isbaseof.d | 46 ++ .../libphobos.unittest/customhandler.d | 21 + 46 files changed, 2191 insertions(+), 67 deletions(-) create mode 100644 libphobos/testsuite/libphobos.allocations/alloc_from_assert.d create mode 100644 libphobos/testsuite/libphobos.betterc/test18828.d create mode 100644 libphobos/testsuite/libphobos.betterc/test19416.d create mode 100644 libphobos/testsuite/libphobos.betterc/test19421.d create mode 100644 libphobos/testsuite/libphobos.betterc/test19561.d create mode 100644 libphobos/testsuite/libphobos.betterc/test19924.d create mode 100644 libphobos/testsuite/libphobos.betterc/test20088.d create mode 100644 libphobos/testsuite/libphobos.betterc/test20613.d create mode 100644 libphobos/testsuite/libphobos.config/test19433.d create mode 100644 libphobos/testsuite/libphobos.config/test20459.d create mode 100644 libphobos/testsuite/libphobos.exceptions/assert_fail.d create mode 100644 libphobos/testsuite/libphobos.exceptions/catch_in_finally.d create mode 100644 libphobos/testsuite/libphobos.exceptions/future_message.d create mode 100644 libphobos/testsuite/libphobos.exceptions/long_backtrace_trunc.d create mode 100644 libphobos/testsuite/libphobos.exceptions/refcounted.d create mode 100644 libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions.d create mode 100644 libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions_drt.d create mode 100644 libphobos/testsuite/libphobos.gc/attributes.d create mode 100644 libphobos/testsuite/libphobos.gc/forkgc.d create mode 100644 libphobos/testsuite/libphobos.gc/forkgc2.d create mode 100644 libphobos/testsuite/libphobos.gc/nocollect.d create mode 100644 libphobos/testsuite/libphobos.gc/precisegc.d create mode 100644 libphobos/testsuite/libphobos.gc/recoverfree.d create mode 100644 libphobos/testsuite/libphobos.gc/sigmaskgc.d create mode 100644 libphobos/testsuite/libphobos.gc/startbackgc.d create mode 100644 libphobos/testsuite/libphobos.imports/bug18193.d create mode 100644 libphobos/testsuite/libphobos.init_fini/custom_gc.d create mode 100644 libphobos/testsuite/libphobos.init_fini/test18996.d create mode 100644 libphobos/testsuite/libphobos.lifetime/large_aggregate_destroy_21097.d delete mode 100644 libphobos/testsuite/libphobos.shared/link_mod_collision.d delete mode 100644 libphobos/testsuite/libphobos.shared/load_mod_collision.d create mode 100644 libphobos/testsuite/libphobos.thread/external_threads.d create mode 100644 libphobos/testsuite/libphobos.thread/join_detach.d create mode 100644 libphobos/testsuite/libphobos.thread/test_import.d create mode 100644 libphobos/testsuite/libphobos.thread/tlsstack.d create mode 100644 libphobos/testsuite/libphobos.typeinfo/enum_.d create mode 100644 libphobos/testsuite/libphobos.typeinfo/isbaseof.d create mode 100644 libphobos/testsuite/libphobos.unittest/customhandler.d diff --git a/libphobos/testsuite/libphobos.aa/test_aa.d b/libphobos/testsuite/libphobos.aa/test_aa.d index d6222b13175..11ad2f90ff1 100644 --- a/libphobos/testsuite/libphobos.aa/test_aa.d +++ b/libphobos/testsuite/libphobos.aa/test_aa.d @@ -30,6 +30,8 @@ void main() issue15367(); issue16974(); issue18071(); + issue20440(); + issue21442(); testIterationWithConst(); testStructArrayKey(); miscTests1(); @@ -286,21 +288,20 @@ void testUpdate2() assert(updated); } -void testByKey1() +void testByKey1() @safe { - static assert(!__traits(compiles, - () @safe { - struct BadValue - { - int x; - this(this) @safe { *(cast(ubyte*)(null) + 100000) = 5; } // not @safe - alias x this; - } + static struct BadValue + { + int x; + this(this) @system { *(cast(ubyte*)(null) + 100000) = 5; } // not @safe + alias x this; + } - BadValue[int] aa; - () @safe { auto x = aa.byKey.front; } (); - } - )); + BadValue[int] aa; + + // FIXME: Should be @system because of the postblit + if (false) + auto x = aa.byKey.front; } void testByKey2() nothrow pure @@ -690,6 +691,58 @@ void issue18071() () @safe { assert(f.byKey.empty); }(); } +/// Test that `require` works even with types whose opAssign +/// doesn't return a reference to the receiver. +/// https://issues.dlang.org/show_bug.cgi?id=20440 +void issue20440() @safe +{ + static struct S + { + int value; + auto opAssign(S s) { + this.value = s.value; + return this; + } + } + S[S] aa; + assert(aa.require(S(1), S(2)) == S(2)); + assert(aa[S(1)] == S(2)); +} + +/// +void issue21442() +{ + import core.memory; + + size_t[size_t] glob; + + class Foo + { + size_t count; + + this (size_t entries) @safe + { + this.count = entries; + foreach (idx; 0 .. entries) + glob[idx] = idx; + } + + ~this () @safe + { + foreach (idx; 0 .. this.count) + glob.remove(idx); + } + } + + void bar () @safe + { + Foo f = new Foo(16); + } + + bar(); + GC.collect(); // Needs to happen from a GC collection +} + /// Verify iteration with const. void testIterationWithConst() { diff --git a/libphobos/testsuite/libphobos.allocations/alloc_from_assert.d b/libphobos/testsuite/libphobos.allocations/alloc_from_assert.d new file mode 100644 index 00000000000..a377cd9139d --- /dev/null +++ b/libphobos/testsuite/libphobos.allocations/alloc_from_assert.d @@ -0,0 +1,25 @@ +import core.exception; +import core.memory; + +class FailFinalization +{ + int magic; + + ~this () @nogc nothrow + { + try + assert(this.magic == 42); + catch (AssertError) {} + } +} + +void foo () +{ + auto dangling = new FailFinalization(); +} + +void main() +{ + foo(); + GC.collect(); +} diff --git a/libphobos/testsuite/libphobos.betterc/test18828.d b/libphobos/testsuite/libphobos.betterc/test18828.d new file mode 100644 index 00000000000..db0530dd13c --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test18828.d @@ -0,0 +1,10 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=18828 + +struct S18828 { } + +extern(C) void main() +{ + S18828 s; + destroy(s); +} diff --git a/libphobos/testsuite/libphobos.betterc/test19416.d b/libphobos/testsuite/libphobos.betterc/test19416.d new file mode 100644 index 00000000000..aff93d3aa5f --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test19416.d @@ -0,0 +1,14 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19416 + +import core.stdc.stdlib : malloc, free; +import core.exception : onOutOfMemoryError; + +extern(C) void main() +{ + auto m = malloc(1); + if (!m) + onOutOfMemoryError(); + else + free(m); +} diff --git a/libphobos/testsuite/libphobos.betterc/test19421.d b/libphobos/testsuite/libphobos.betterc/test19421.d new file mode 100644 index 00000000000..2427c5e9a0c --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test19421.d @@ -0,0 +1,13 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19421 + +import core.memory; + +extern(C) void main() @nogc nothrow pure +{ + auto p = pureMalloc(1); + p = pureRealloc(p, 2); + if (p) pureFree(p); + p = pureCalloc(1, 1); + if (p) pureFree(p); +} diff --git a/libphobos/testsuite/libphobos.betterc/test19561.d b/libphobos/testsuite/libphobos.betterc/test19561.d new file mode 100644 index 00000000000..96ecec51ae4 --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test19561.d @@ -0,0 +1,16 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19561 + +import core.memory; + +extern(C) void main() @nogc nothrow pure +{ + int[3] a, b; + a[] = 0; + a[] = b[]; + //FIXME: Next line requires compiler change. + //a[] = 1; // error: undefined reference to '_memset32' + a[] += 1; + a[] += b[]; + int[3] c = a[] + b[]; +} diff --git a/libphobos/testsuite/libphobos.betterc/test19924.d b/libphobos/testsuite/libphobos.betterc/test19924.d new file mode 100644 index 00000000000..e9a93cad0ac --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test19924.d @@ -0,0 +1,15 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=19924 + +import core.bitop; + +extern(C) void main() +{ + uint a = 0x01_23_45_67; + a = bswap(a); + assert(a == 0x67_45_23_01); + + ulong b = 0x01_23_45_67_89_ab_cd_ef; + b = bswap(b); + assert(b == 0xef_cd_ab_89_67_45_23_01); +} diff --git a/libphobos/testsuite/libphobos.betterc/test20088.d b/libphobos/testsuite/libphobos.betterc/test20088.d new file mode 100644 index 00000000000..a809041c877 --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test20088.d @@ -0,0 +1,14 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20088 + +struct S { + int i; +} + +extern(C) int main() @nogc nothrow pure +{ + S[2] s = [S(1),S(2)]; + void[] v = cast(void[])s; + S[] p = cast(S[])v; // cast of void[] to S[] triggers __ArrayCast template function + return 0; +} diff --git a/libphobos/testsuite/libphobos.betterc/test20613.d b/libphobos/testsuite/libphobos.betterc/test20613.d new file mode 100644 index 00000000000..b03e2d17b62 --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/test20613.d @@ -0,0 +1,18 @@ +/*******************************************/ +// https://issues.dlang.org/show_bug.cgi?id=20613 + +extern(C) int main() @nogc nothrow pure +{ + auto s = "F"; + final switch(s) + { + case "A": break; + case "B": break; + case "C": break; + case "D": break; + case "E": break; + case "F": break; + case "G": break; + } + return 0; +} diff --git a/libphobos/testsuite/libphobos.config/test19433.d b/libphobos/testsuite/libphobos.config/test19433.d new file mode 100644 index 00000000000..1c58145103e --- /dev/null +++ b/libphobos/testsuite/libphobos.config/test19433.d @@ -0,0 +1,7 @@ +extern(C) __gshared bool rt_cmdline_enabled = false; + +void main(string[] args) +{ + assert(args.length == 2); + assert(args[1] == "--DRT-dont-eat-me"); +} diff --git a/libphobos/testsuite/libphobos.config/test20459.d b/libphobos/testsuite/libphobos.config/test20459.d new file mode 100644 index 00000000000..248720d8f30 --- /dev/null +++ b/libphobos/testsuite/libphobos.config/test20459.d @@ -0,0 +1,5 @@ +void main (string[] args) +{ + assert(args.length == 5); + assert(args[1 .. $] == [ "foo", "bar", "--", "--DRT-gcopts=profile:1" ]); +} diff --git a/libphobos/testsuite/libphobos.exceptions/assert_fail.d b/libphobos/testsuite/libphobos.exceptions/assert_fail.d new file mode 100644 index 00000000000..79b3cb8139e --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/assert_fail.d @@ -0,0 +1,564 @@ +import core.stdc.stdio : fprintf, stderr; +import core.internal.dassert : _d_assert_fail; + +void test(string comp = "==", A, B)(A a, B b, string msg, size_t line = __LINE__) +{ + test(_d_assert_fail!(A)(comp, a, b), msg, line); +} + +void test(const string actual, const string expected, size_t line = __LINE__) +{ + import core.exception : AssertError; + + if (actual != expected) + { + const msg = "Mismatch!\nExpected: <" ~ expected ~ ">\nActual: <" ~ actual ~ '>'; + throw new AssertError(msg, __FILE__, line); + } +} + +void testIntegers() +{ + test(1, 2, "1 != 2"); + test(-10, 8, "-10 != 8"); + test(byte.min, byte.max, "-128 != 127"); + test(ubyte.min, ubyte.max, "0 != 255"); + test(short.min, short.max, "-32768 != 32767"); + test(ushort.min, ushort.max, "0 != 65535"); + test(int.min, int.max, "-2147483648 != 2147483647"); + test(uint.min, uint.max, "0 != 4294967295"); + test(long.min, long.max, "-9223372036854775808 != 9223372036854775807"); + test(ulong.min, ulong.max, "0 != 18446744073709551615"); + test(shared(ulong).min, shared(ulong).max, "0 != 18446744073709551615"); + + int testFun() { return 1; } + test(testFun(), 2, "1 != 2"); +} + +void testIntegerComparisons() +{ + test!"!="(2, 2, "2 == 2"); + test!"<"(2, 1, "2 >= 1"); + test!"<="(2, 1, "2 > 1"); + test!">"(1, 2, "1 <= 2"); + test!">="(1, 2, "1 < 2"); +} + +void testFloatingPoint() +{ + if (__ctfe) + { + test(float.max, -float.max, " != "); + test(double.max, -double.max, " != "); + test(real(1), real(-1), " != "); + } + else + { + test(1.5, 2.5, "1.5 != 2.5"); + test(float.max, -float.max, "3.40282e+38 != -3.40282e+38"); + test(double.max, -double.max, "1.79769e+308 != -1.79769e+308"); + test(real(1), real(-1), "1 != -1"); + } +} + +void testPointers() +{ + static struct S + { + string toString() const { return "S(...)"; } + } + + static if ((void*).sizeof == 4) + enum ptr = "0x12345670"; + else + enum ptr = "0x123456789abcdef0"; + + int* p = cast(int*) mixin(ptr); + test(cast(S*) p, p, ptr ~ " != " ~ ptr); +} + +void testStrings() +{ + test("foo", "bar", `"foo" != "bar"`); + test("", "bar", `"" != "bar"`); + + char[] dlang = "dlang".dup; + const(char)[] rust = "rust"; + test(dlang, rust, `"dlang" != "rust"`); + + // https://issues.dlang.org/show_bug.cgi?id=20322 + test("left"w, "right"w, `"left" != "right"`); + test("left"d, "right"d, `"left" != "right"`); + + test('A', 'B', "'A' != 'B'"); + test(wchar('❤'), wchar('∑'), "'❤' != '∑'"); + test(dchar('❤'), dchar('∑'), "'❤' != '∑'"); + + // Detect invalid code points + test(char(255), 'B', "cast(char) 255 != 'B'"); + test(wchar(0xD888), wchar('∑'), "cast(wchar) 55432 != '∑'"); + test(dchar(0xDDDD), dchar('∑'), "cast(dchar) 56797 != '∑'"); +} + +void testToString() +{ + class Foo + { + this(string payload) { + this.payload = payload; + } + + string payload; + override string toString() { + return "Foo(" ~ payload ~ ")"; + } + } + test(new Foo("a"), new Foo("b"), "Foo(a) != Foo(b)"); + + scope f = cast(shared) new Foo("a"); + if (!__ctfe) // Ref somehow get's lost in CTFE + test!"!="(f, f, "Foo(a) == Foo(a)"); + + // Verifiy that the const toString is selected if present + static struct Overloaded + { + string toString() + { + return "Mutable"; + } + + string toString() const + { + return "Const"; + } + } + + test!"!="(Overloaded(), Overloaded(), "Const == Const"); + + Foo fnull = null; + test!"!is"(fnull, fnull, "`null` is `null`"); +} + + +void testArray() +{ + test([1], [0], "[1] != [0]"); + test([1, 2, 3], [0], "[1, 2, 3] != [0]"); + + // test with long arrays + int[] arr; + foreach (i; 0 .. 100) + arr ~= i; + test(arr, [0], "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, ...] != [0]"); + + // Ignore fake arrays + static struct S + { + int[2] arr; + int[] get() return { return arr[]; } + alias get this; + } + + const a = S([1, 2]); + test(a, S([3, 4]), "S([1, 2]) != S([3, 4])"); +} + +void testStruct() +{ + struct S { int s; } + struct T { T[] t; } + test(S(0), S(1), "S(0) != S(1)"); + test(T([T(null)]), T(null), "T([T([])]) != T([])"); + + // https://issues.dlang.org/show_bug.cgi?id=20323 + static struct NoCopy + { + @disable this(this); + } + + NoCopy n; + test(_d_assert_fail!(typeof(n))("!=", n, n), "NoCopy() == NoCopy()"); + + shared NoCopy sn; + test(_d_assert_fail!(typeof(sn))("!=", sn, sn), "NoCopy() == NoCopy()"); +} + +void testAA() +{ + test([1:"one"], [2: "two"], `[1: "one"] != [2: "two"]`); + test!"in"(1, [2: 3], "1 !in [2: 3]"); + test!"in"("foo", ["bar": true], `"foo" !in ["bar": true]`); +} + +void testAttributes() @safe pure @nogc nothrow +{ + int a; + string s = _d_assert_fail!(int, char)("==", a, 'c', 1, 'd'); + assert(s == `(0, 'c') != (1, 'd')`); + + string s2 = _d_assert_fail!int("", a); + assert(s2 == `0 != true`); +} + +// https://issues.dlang.org/show_bug.cgi?id=20066 +void testVoidArray() +{ + test!"!is"([], null, (__ctfe ? "" : "[]") ~ " is `null`"); + test!"!is"(null, null, "`null` is `null`"); + test([1], null, "[1] != `null`"); + test("s", null, "\"s\" != `null`"); + test(['c'], null, "\"c\" != `null`"); + test!"!="(null, null, "`null` == `null`"); + + const void[] chunk = [byte(1), byte(2), byte(3)]; + test(chunk, null, (__ctfe ? "" : "[1, 2, 3]") ~ " != `null`"); +} + +void testTemporary() +{ + static struct Bad + { + ~this() @system {} + } + + test!"!="(Bad(), Bad(), "Bad() == Bad()"); +} + +void testEnum() +{ + static struct UUID { + union + { + ubyte[] data = [1]; + } + } + + ubyte[] data; + enum ctfe = UUID(); + test(_d_assert_fail!(ubyte[])("==", ctfe.data, data), "[1] != []"); +} + +void testUnary() +{ + test(_d_assert_fail!int("", 9), "9 != true"); + test(_d_assert_fail!(int[])("!", [1, 2, 3]), "[1, 2, 3] == true"); +} + +void testTuple() +{ + test(_d_assert_fail("=="), "() != ()"); + test(_d_assert_fail("!="), "() == ()"); + test(_d_assert_fail(">="), "() < ()"); +} + +void testStructEquals() +{ + struct T { + bool b; + int i; + float f1 = 2.5; + float f2 = 0; + string s1 = "bar"; + string s2; + } + + T t1; + test!"!="(t1, t1, `T(false, 0, 2.5, 0, "bar", "") == T(false, 0, 2.5, 0, "bar", "")`); + T t2 = {s1: "bari"}; + test(t1, t2, `T(false, 0, 2.5, 0, "bar", "") != T(false, 0, 2.5, 0, "bari", "")`); +} + +void testStructEquals2() +{ + struct T { + bool b; + int i; + float f1 = 2.5; + float f2 = 0; + } + + T t1; + test!"!="(t1, t1, `T(false, 0, 2.5, 0) == T(false, 0, 2.5, 0)`); + T t2 = {i: 2}; + test(t1, t2, `T(false, 0, 2.5, 0) != T(false, 2, 2.5, 0)`); +} + +void testStructEquals3() +{ + struct T { + bool b; + int i; + string s1 = "bar"; + string s2; + } + + T t1; + test!"!="(t1, t1, `T(false, 0, "bar", "") == T(false, 0, "bar", "")`); + T t2 = {s1: "bari"}; + test(t1, t2, `T(false, 0, "bar", "") != T(false, 0, "bari", "")`); +} + +void testStructEquals4() +{ + struct T { + float f1 = 2.5; + float f2 = 0; + string s1 = "bar"; + string s2; + } + + T t1; + test!"!="(t1, t1, `T(2.5, 0, "bar", "") == T(2.5, 0, "bar", "")`); + T t2 = {s1: "bari"}; + test(t1, t2, `T(2.5, 0, "bar", "") != T(2.5, 0, "bari", "")`); +} + +void testStructEquals5() +{ + struct T { + bool b; + int i; + float f2 = 0; + string s2; + } + + T t1; + test!"!="(t1, t1, `T(false, 0, 0, "") == T(false, 0, 0, "")`); + T t2 = {b: true}; + test(t1, t2, `T(false, 0, 0, "") != T(true, 0, 0, "")`); +} + +void testStructEquals6() +{ + class C { override string toString() { return "C()"; }} + struct T { + bool b; + int i; + float f2 = 0; + string s2; + int[] arr; + C c; + } + + T t1; + test!"!="(t1, t1, "T(false, 0, 0, \"\", [], `null`) == T(false, 0, 0, \"\", [], `null`)"); + T t2 = {arr: [1]}; + test(t1, t2, "T(false, 0, 0, \"\", [], `null`) != T(false, 0, 0, \"\", [1], `null`)"); + T t3 = {c: new C()}; + test(t1, t3, "T(false, 0, 0, \"\", [], `null`) != T(false, 0, 0, \"\", [], C())"); +} + +void testContextPointer() +{ + int i; + struct T + { + int j; + int get() + { + return i * j; + } + } + T t = T(1); + t.tupleof[$-1] = cast(void*) 0xABCD; // Deterministic context pointer + test(t, t, `T(1, : 0xabcd) != T(1, : 0xabcd)`); +} + +void testExternClasses() +{ + { + extern(C++) static class Cpp + { + int a; + this(int a) { this.a = a; } + } + scope a = new Cpp(1); + scope b = new Cpp(2); + test(a, b, "Cpp(1) != Cpp(2)"); + test(a, Cpp.init, "Cpp(1) != null"); + } + { + extern(C++) static class CppToString + { + int a; + this(int a) { this.a = a; } + extern(D) string toString() const { return a == 0 ? "hello" : "world"; } + } + scope a = new CppToString(0); + scope b = new CppToString(1); + test(a, b, "hello != world"); + } + if (!__ctfe) + { + extern(C++) static class Opaque; + Opaque null_ = null; + Opaque notNull = cast(Opaque) &null_; + test(null_, notNull, "null != "); + } + { + extern(C++) static interface Stuff {} + scope Stuff stuff = new class Stuff {}; + test(stuff, Stuff.init, "Stuff() != null"); + } +} + +void testShared() +{ + static struct Small + { + int i; + } + + auto s1 = shared Small(1); + const s2 = shared Small(2); + test(s1, s2, "Small(1) != Small(2)"); + + static struct Big + { + long[10] l; + } + + auto b1 = shared Big([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + const b2 = shared Big(); + test(b1, b2, "Big([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) != Big([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])"); + + // Sanity check: Big shouldn't be supported by atomicLoad + import core.atomic : atomicLoad; + static assert( __traits(compiles, atomicLoad(s1))); + static assert(!__traits(compiles, atomicLoad(b1))); +} + +void testException() +{ + static struct MayThrow + { + int i; + string toString() + { + if (i == 1) + throw new Exception("Error"); + return "Some message"; + } + } + + test(MayThrow(0), MayThrow(1), `Some message != `); +} + +void testOverlappingFields() +{ + static struct S + { + union + { + double num; + immutable(char)[] name; + } + } + + test(S(1.0), S(2.0), "S(, ) != S(, )"); + + static struct S2 + { + int valid; + union + { + double num; + immutable(char)[] name; + } + } + + test(S2(4, 1.0), S2(5, 2.0), "S2(4, , ) != S2(5, , )"); + + static struct S3 + { + union + { + double num; + immutable(char)[] name; + } + int valid; + } + S3 a = { + num: 1.0, + valid: 8 + }; + + S3 b = { + num: 1.0, + valid: 8 + }; + test(a, b, "S3(, , 8) != S3(, , 8)"); +} + +void testDestruction() +{ + static class Test + { + __gshared string unary, binary; + __gshared bool run; + + ~this() + { + run = true; + unary = _d_assert_fail!int("", 1); + binary = _d_assert_fail!int("==", 1, 2); + } + } + + static void createGarbage() + { + new Test(); + new long[100]; + } + + import core.memory : GC; + createGarbage(); + GC.collect(); + + assert(Test.run); + assert(Test.unary == "Assertion failed (rich formatting is disabled in finalizers)"); + assert(Test.binary == "Assertion failed (rich formatting is disabled in finalizers)"); +} + +int main() +{ + testIntegers(); + testIntegerComparisons(); + testFloatingPoint(); + testPointers(); + testStrings(); + testToString(); + testArray(); + testStruct(); + testAA(); + testAttributes(); + testVoidArray(); + testTemporary(); + testEnum(); + testUnary(); + testTuple(); + if (!__ctfe) + testStructEquals(); + if (!__ctfe) + testStructEquals2(); + testStructEquals3(); + if (!__ctfe) + testStructEquals4(); + if (!__ctfe) + testStructEquals5(); + if (!__ctfe) + testStructEquals6(); + testContextPointer(); + testExternClasses(); + testShared(); + testException(); + testOverlappingFields(); + if (!__ctfe) + testDestruction(); + + if (!__ctfe) + fprintf(stderr, "success.\n"); + return 0; +} + +enum forceCTFE = main(); diff --git a/libphobos/testsuite/libphobos.exceptions/catch_in_finally.d b/libphobos/testsuite/libphobos.exceptions/catch_in_finally.d new file mode 100644 index 00000000000..88bd73957dd --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/catch_in_finally.d @@ -0,0 +1,191 @@ +import core.stdc.stdio : fprintf, stderr; + +class MyException : Exception +{ + this() { super(typeof(this).stringof); } +} + +void throw_catch() +{ + try + { + throw new MyException; + } + catch (MyException) + { + } + catch (Exception) + { + assert(false); + } +} + +// Test that exceptions that are entirely thrown and caught in finally blocks don't affect exception handling. +void test1() +{ + try + { + try + { + throw new Exception("p"); + } + finally + { + throw_catch(); + } + } + catch (Exception e) + { + assert(e.msg == "p"); + } +} + +// Test that exceptions that are entirely thrown and caught in finally blocks don't interfere with chaining. +void test2() +{ + try + { + try + { + try + { + throw new Exception("p"); + } + finally + { + throw new Exception("q"); + } + } + finally + { + throw_catch(); + } + } + catch(Exception e) + { + assert(e.msg == "p"); + assert(e.next.msg == "q"); + assert(!e.next.next); + } +} + +void test3() +{ + try + { + try + { + try + { + throw new Exception("p"); + } + finally + { + throw_catch(); + } + } + finally + { + throw new Exception("q"); + } + } + catch(Exception e) + { + assert(e.msg == "p"); + assert(e.next.msg == "q"); + assert(!e.next.next); + } +} + +// Test order of exception handler operations. +void test4() +{ + string result; + void throw_catch() + { + pragma(inline, false); + try + { + result ~= "b"; + throw new MyException; + } + catch (MyException) + { + result ~= "c"; + } + catch (Exception) + { + assert(false); + } + } + try + { + try + { + result ~= "a"; + throw new Exception(""); + } + finally + { + throw_catch(); + } + } + catch(Exception e) + { + result ~= "d"; + } + assert(result == "abcd"); +} + +void test5() +{ + string result; + void fail() + { + result ~= "b"; + throw new Exception("a"); + } + + void throw_catch() + { + pragma(inline, false); + try + { + fail(); + } + catch(Exception e) + { + assert(e.msg == "a"); + assert(!e.next); + result ~= "c"; + } + } + try + { + try + { + result ~= "a"; + throw new Exception("x"); + } + finally + { + throw_catch(); + } + } + catch (Exception e) + { + assert(e.msg == "x"); + assert(!e.next); + result ~= "d"; + } + assert(result == "abcd"); +} + +void main() { + test1(); + test2(); + test3(); + test4(); + test5(); + fprintf(stderr, "success.\n"); +} diff --git a/libphobos/testsuite/libphobos.exceptions/future_message.d b/libphobos/testsuite/libphobos.exceptions/future_message.d new file mode 100644 index 00000000000..61b10348287 --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/future_message.d @@ -0,0 +1,71 @@ +// { dg-options "-Wno-deprecated" } +import core.stdc.stdio; + +// Make sure basic stuff works with future Throwable.message +class NoMessage : Throwable +{ + @nogc @safe pure nothrow this(string msg, Throwable next = null) + { + super(msg, next); + } +} + +class WithMessage : Throwable +{ + @nogc @safe pure nothrow this(string msg, Throwable next = null) + { + super(msg, next); + } + + override const(char)[] message() const + { + return "I have a custom message."; + } +} + +class WithMessageNoOverride : Throwable +{ + @nogc @safe pure nothrow this(string msg, Throwable next = null) + { + super(msg, next); + } + + const(char)[] message() const + { + return "I have a custom message and no override."; + } +} + +class WithMessageNoOverrideAndDifferentSignature : Throwable +{ + @nogc @safe pure nothrow this(string msg, Throwable next = null) + { + super(msg, next); + } + + immutable(char)[] message() + { + return "I have a custom message and I'm nothing like Throwable.message."; + } +} + +void test(Throwable t) +{ + try + { + throw t; + } + catch (Throwable e) + { + fprintf(stderr, "%.*s ", cast(int)e.message.length, e.message.ptr); + } +} + +void main() +{ + test(new NoMessage("exception")); + test(new WithMessage("exception")); + test(new WithMessageNoOverride("exception")); + test(new WithMessageNoOverrideAndDifferentSignature("exception")); + fprintf(stderr, "\n"); +} diff --git a/libphobos/testsuite/libphobos.exceptions/long_backtrace_trunc.d b/libphobos/testsuite/libphobos.exceptions/long_backtrace_trunc.d new file mode 100644 index 00000000000..3ff45e55c87 --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/long_backtrace_trunc.d @@ -0,0 +1,37 @@ +struct AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA(T) { +struct BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB { +struct CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC { +struct DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD { +struct EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE { +struct FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF { +struct GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG { +struct HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH { + T tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt(int x) { + throw new Exception("test"); + } +} +} +} +} +} +} +} +} + +void main() { + try { + AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA!int. + BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB. + CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC. + DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD. + EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE. + FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF. + GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG. + HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH x; + x.tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt(1); + } catch (Exception e) { + import core.stdc.stdio; + auto str = e.toString(); + printf("%.*s\n", cast(int)str.length, str.ptr); + } +} diff --git a/libphobos/testsuite/libphobos.exceptions/refcounted.d b/libphobos/testsuite/libphobos.exceptions/refcounted.d new file mode 100644 index 00000000000..2b7e79bbf39 --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/refcounted.d @@ -0,0 +1,96 @@ +// { dg-options "-fpreview=dip1008" } +class E : Exception +{ + static int instances; + this(string msg = "") + { + super(msg); + instances++; + } + + ~this() + { + instances--; + } +} + +void main() +{ + alias chain = Exception.chainTogether; + + assert(chain(null, null) is null); + + try + { + throw new E(); + } + catch (E e) + { + assert(E.instances == 1); + assert(e.refcount == 2); + } + + assert(E.instances == 0); + + try + { + throw new E(); + } + catch (E e) + { + assert(chain(null, e) is e); + assert(e.refcount == 2); // "Owned by e" + 1 + } + + assert(E.instances == 0); + + try + { + throw new E(); + } + catch (E e) + { + assert(chain(e, null) is e); + assert(e.refcount == 2); // "Owned by e" + 1 + } + + assert(E.instances == 0); + + try + { + throw new E("first"); + } + catch (E first) + { + try + { + throw new E("second"); + } + catch (E second) + { + try + { + throw new E("third"); + } + catch (E third) + { + assert(chain(first, second) is first); + assert(first.next is second); + assert(second.next is null); + + assert(chain(first, third) is first); + assert(first.next is second); + assert(second.next is third); + assert(third.next is null); + + assert(first.refcount == 2); + assert(second.refcount == 3); + assert(third.refcount == 3); + } + } + + assert(E.instances == 3); + } + + assert(E.instances == 0); +} diff --git a/libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions.d b/libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions.d new file mode 100644 index 00000000000..bd0c227e0f6 --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions.d @@ -0,0 +1,15 @@ +// { dg-shouldfail "uncaught exception" } +// { dg-output "gcc.deh.*: uncaught exception" } +// Code adapted from +// http://arsdnet.net/this-week-in-d/2016-aug-07.html +extern extern(C) __gshared bool rt_trapExceptions; +extern extern(C) int _d_run_main(int, char**, void*) @system; + +extern(C) int main(int argc, char** argv) { + rt_trapExceptions = false; + return _d_run_main(argc, argv, &_main); +} + +int _main() { + throw new Exception("this will abort"); +} diff --git a/libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions_drt.d b/libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions_drt.d new file mode 100644 index 00000000000..fc4448cf0bf --- /dev/null +++ b/libphobos/testsuite/libphobos.exceptions/rt_trap_exceptions_drt.d @@ -0,0 +1,11 @@ +// { dg-shouldfail "uncaught exception" } +void test() +{ + int innerLocal = 20; + throw new Exception("foo"); +} +void main(string[] args) +{ + string myLocal = "bar"; + test(); +} diff --git a/libphobos/testsuite/libphobos.exceptions/unknown_gc.d b/libphobos/testsuite/libphobos.exceptions/unknown_gc.d index eb95aeed036..183c0f2969e 100644 --- a/libphobos/testsuite/libphobos.exceptions/unknown_gc.d +++ b/libphobos/testsuite/libphobos.exceptions/unknown_gc.d @@ -2,8 +2,12 @@ // { dg-options "-shared-libphobos" } // { dg-shouldfail "unknowngc" } // { dg-output "No GC was initialized, please recheck the name of the selected GC \\('unknowngc'\\)." } +import core.memory; + extern(C) __gshared string[] rt_options = [ "gcopt=gc:unknowngc" ]; void main() { + // GC initialized upon first call -> Unknown GC error is thrown + GC.enable(); } diff --git a/libphobos/testsuite/libphobos.gc/attributes.d b/libphobos/testsuite/libphobos.gc/attributes.d new file mode 100644 index 00000000000..a7acd6ce550 --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/attributes.d @@ -0,0 +1,30 @@ +import core.memory; + +// TODO: The following should work, but L10 (second assert) fails. +version(none) void dotest(T) (T* ptr) +{ + GC.clrAttr(ptr, uint.max); + assert(GC.getAttr(ptr) == 0); + + GC.setAttr(ptr, GC.BlkAttr.NO_MOVE); + assert(GC.getAttr(ptr) == GC.BlkAttr.NO_MOVE); + + GC.clrAttr(ptr, GC.BlkAttr.NO_MOVE); + assert(GC.getAttr(ptr) == 0); + GC.clrAttr(ptr, GC.BlkAttr.NO_MOVE); + assert(GC.getAttr(ptr) == 0); +} +else void dotest(T) (T* ptr) +{ + // https://issues.dlang.org/show_bug.cgi?id=21484 + GC.clrAttr(ptr, uint.max); + GC.setAttr(ptr, GC.BlkAttr.NO_MOVE); + GC.getAttr(ptr); +} + +void main () +{ + auto ptr = new int; + dotest!(const(int))(ptr); + dotest!(int)(ptr); +} diff --git a/libphobos/testsuite/libphobos.gc/forkgc.d b/libphobos/testsuite/libphobos.gc/forkgc.d new file mode 100644 index 00000000000..9c18dc296f0 --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/forkgc.d @@ -0,0 +1,36 @@ +import core.memory; +import core.stdc.stdio; +import core.sys.posix.sys.wait; +import core.sys.posix.unistd; + +void main() +{ + printf("[parent] Creating garbage...\n"); + foreach (n; 0 .. 1_000) + new uint[10_000]; + printf("[parent] Collecting garbage...\n"); + GC.collect(); + printf("[parent] Forking...\n"); + auto i = fork(); + if (i < 0) + assert(false, "Fork failed"); + if (i == 0) + { + printf("[child] In fork.\n"); + printf("[child] Creating garbage...\n"); + foreach (n; 0 .. 1_000) + new uint[10_000]; + printf("[child] Collecting garbage...\n"); + GC.collect(); + printf("[child] Exiting fork.\n"); + } + else + { + printf("[parent] Waiting for fork (PID %d).\n", i); + int status; + i = waitpid(i, &status, 0); + printf("[parent] Fork %d exited (%d).\n", i, status); + if (status != 0) + assert(false, "child had errors"); + } +} diff --git a/libphobos/testsuite/libphobos.gc/forkgc2.d b/libphobos/testsuite/libphobos.gc/forkgc2.d new file mode 100644 index 00000000000..de7796ced72 --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/forkgc2.d @@ -0,0 +1,22 @@ +import core.stdc.stdlib : exit; +import core.sys.posix.sys.wait : waitpid; +import core.sys.posix.unistd : fork; +import core.thread : Thread; + +void main() +{ + foreach (t; 0 .. 10) + new Thread({ + foreach (n; 0 .. 100) + { + foreach (x; 0 .. 100) + new ubyte[x]; + auto f = fork(); + assert(f >= 0); + if (f == 0) + exit(0); + else + waitpid(f, null, 0); + } + }).start(); +} diff --git a/libphobos/testsuite/libphobos.gc/nocollect.d b/libphobos/testsuite/libphobos.gc/nocollect.d new file mode 100644 index 00000000000..5df1483a284 --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/nocollect.d @@ -0,0 +1,15 @@ +// https://issues.dlang.org/show_bug.cgi?id=20567 + +import core.memory; + +void main() +{ + auto stats = GC.profileStats(); + assert(stats.numCollections == 0); + + char[] sbuf = new char[256]; // small pool + char[] lbuf = new char[2049]; // large pool + + stats = GC.profileStats(); + assert(stats.numCollections == 0); +} \ No newline at end of file diff --git a/libphobos/testsuite/libphobos.gc/precisegc.d b/libphobos/testsuite/libphobos.gc/precisegc.d new file mode 100644 index 00000000000..9bcaf3f4faa --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/precisegc.d @@ -0,0 +1,126 @@ +// precise GC related: +// https://issues.dlang.org/show_bug.cgi?id=3463 +// https://issues.dlang.org/show_bug.cgi?id=4358 +// https://issues.dlang.org/show_bug.cgi?id=9094 +// https://issues.dlang.org/show_bug.cgi?id=13801 +// https://issues.dlang.org/show_bug.cgi?id=18900 +module testgc; + +import core.memory; +import core.stdc.stdio; + +class C +{ + __gshared int dtors; + ~this() { dtors++; } + + C next; + size_t val; +} + +struct S +{ + __gshared int dtors; + ~this() { dtors++; } + + size_t val; + S* next; +} + +struct L +{ + __gshared int dtors; + ~this() { dtors++; } + + size_t[1000] data; + S* node; +} + +struct Roots +{ + C c; + S *s; + L *l; +}; + +Roots* roots; +size_t iroots; + +void init() +{ + roots = new Roots; + roots.c = new C; + roots.c.next = new C; + + roots.s = new S; + roots.s.next = new S; + + roots.l = new L; + roots.l.node = new S; +} + +void verifyPointers() +{ + assert(C.dtors == 0); + assert(S.dtors == 0); + assert(L.dtors == 0); +} + +// compiling with -gx should help eliminating false pointers on the stack +Roots makeFalsePointers() +{ + roots.c.val = cast(size_t) cast(void*) roots.c.next; + roots.c.next = null; + roots.s.val = cast(size_t) cast(void*) roots.s.next; + roots.s.next = null; + roots.l.data[7] = cast(size_t) cast(void*) roots.l.node; + roots.l.node = null; + + return Roots(null, null, null); // try to spill register contents +} + +Roots moveRoot() +{ + iroots = cast(size_t)roots; + roots = null; + + return Roots(null, null, null); // try to spill register contents +} + +// compiling with -gx should help eliminating false pointers on the stack +void verifyFalsePointers() +{ + assert(C.dtors <= 1); + if (C.dtors < 1) printf ("False pointers? C.dtors = %d, 1 expected\n", C.dtors); + assert(S.dtors <= 2); + if (S.dtors < 2) printf ("False pointers? S.dtors = %d, 2 expected\n", S.dtors); + assert(L.dtors == 0); +} + +extern(C) __gshared string[] rt_options = [ "gcopt=gc:precise", "scanDataSeg=precise" ]; + +void main() +{ + GC.collect(); // cleanup from unittests + + init(); + GC.collect(); // should collect nothing + verifyPointers(); + + makeFalsePointers(); + GC.collect(); // should collect roots.c.next, roots.s.next and roots.l.node + verifyFalsePointers(); + + moveRoot(); + GC.collect(); // should collect all + + version(Windows) // precise DATA scanning only implemented on Windows + { + assert(C.dtors <= 2); + if (C.dtors < 2) printf ("False DATA pointers? C.dtors = %d, 2 expected\n", C.dtors); + assert(S.dtors <= 3); + if (S.dtors < 3) printf ("False DATA pointers? S.dtors = %d, 2 expected\n", S.dtors); + assert(L.dtors <= 1); + if (L.dtors < 1) printf ("False DATA pointers? L.dtors = %d, 1 expected\n", L.dtors); + } +} diff --git a/libphobos/testsuite/libphobos.gc/recoverfree.d b/libphobos/testsuite/libphobos.gc/recoverfree.d new file mode 100644 index 00000000000..59c3b4ab597 --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/recoverfree.d @@ -0,0 +1,13 @@ +// https://issues.dlang.org/show_bug.cgi?id=20438 +import core.stdc.stdio; +import core.memory; + +void main() +{ + auto used0 = GC.stats.usedSize; + void* z = GC.malloc(100); + GC.free(z); + GC.collect(); + auto used1 = GC.stats.usedSize; + used1 <= used0 || assert(false); +} diff --git a/libphobos/testsuite/libphobos.gc/sigmaskgc.d b/libphobos/testsuite/libphobos.gc/sigmaskgc.d new file mode 100644 index 00000000000..eb46316d18f --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/sigmaskgc.d @@ -0,0 +1,42 @@ + +// https://issues.dlang.org/show_bug.cgi?id=20256 + +extern(C) __gshared string[] rt_options = [ "gcopt=parallel:1" ]; + +void main() +{ + version (Posix) + { + import core.sys.posix.signal; + import core.sys.posix.unistd; + import core.thread; + import core.memory; + + sigset_t m; + sigemptyset(&m); + sigaddset(&m, SIGHUP); + + auto x = new int[](10000); + foreach (i; 0 .. 10000) + { + x ~= i; + } + GC.collect(); // GC create thread + + sigprocmask(SIG_BLOCK, &m, null); // block SIGHUP from delivery to main thread + + auto parent_pid = getpid(); + auto child_pid = fork(); + assert(child_pid >= 0); + if (child_pid == 0) + { + kill(parent_pid, SIGHUP); // send signal to parent + _exit(0); + } + // parent + Thread.sleep(100.msecs); + // if we are here, then GC threads didn't receive SIGHUP, + // otherwise whole process killed + _exit(0); + } +} diff --git a/libphobos/testsuite/libphobos.gc/startbackgc.d b/libphobos/testsuite/libphobos.gc/startbackgc.d new file mode 100644 index 00000000000..bf51fbdbefe --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/startbackgc.d @@ -0,0 +1,22 @@ +// https://issues.dlang.org/show_bug.cgi?id=20270 +import core.sys.posix.sys.wait : waitpid; +import core.sys.posix.unistd : fork, _exit; +import core.thread : Thread; + +void main() +{ + foreach (t; 0 .. 10) + new Thread({ + foreach (n; 0 .. 100) + { + foreach (x; 0 .. 100) + new ubyte[x]; + auto f = fork(); + assert(f >= 0); + if (f == 0) + _exit(0); + else + waitpid(f, null, 0); + } + }).start(); +} diff --git a/libphobos/testsuite/libphobos.hash/test_hash.d b/libphobos/testsuite/libphobos.hash/test_hash.d index b40626659b7..d0a8e5fb809 100644 --- a/libphobos/testsuite/libphobos.hash/test_hash.d +++ b/libphobos/testsuite/libphobos.hash/test_hash.d @@ -1,3 +1,5 @@ +// { dg-prune-output "Warning: struct HasNonConstToHash has method toHash" } +// { dg-prune-output "HasNonConstToHash.toHash defined here:" } void main() { issue19562(); @@ -8,8 +10,14 @@ void main() issue19005(); issue19204(); issue19262(); + issue19282(); + issue19332(); // Support might be removed in the future! issue19568(); issue19582(); + issue20034(); + issue21642(); + issue22024(); + issue22076(); testTypeInfoArrayGetHash1(); testTypeInfoArrayGetHash2(); pr2243(); @@ -130,6 +138,30 @@ void issue19262() nothrow h = hashOf(aa, h); } +extern(C++) class Issue19282CppClass {} + +/// test that hashOf doesn't crash for non-null C++ objects. +void issue19282() +{ + Issue19282CppClass c = new Issue19282CppClass(); + size_t h = hashOf(c); + h = hashOf(c, h); +} + +/// Ensure hashOf works for const struct that has non-const toHash & has all +/// fields bitwise-hashable. (Support might be removed in the future!) +void issue19332() +{ + static struct HasNonConstToHash + { + int a; + size_t toHash() { return a; } + } + const HasNonConstToHash val; + size_t h = hashOf(val); + h = hashOf!(const HasNonConstToHash)(val); // Ensure doesn't match more than one overload. +} + /// hashOf should not unnecessarily call a struct's fields' postblits & dtors in CTFE void issue19568() { @@ -189,11 +221,99 @@ void issue19582() } } enum b2 = () { - S[10] a; - return ((const S[] a) @nogc nothrow pure @safe => toUbyte(a))(a); + return ((const S[] a) @nogc nothrow pure @safe => toUbyte(a))(new S[10]); }(); } +/// Check core.internal.hash.hashOf works with enums of non-scalar values +void issue20034() +{ + enum E + { + a = "foo" + } + // should compile + assert(hashOf(E.a, 1)); +} + +/// [REG 2.084] hashOf will fail to compile for some structs/unions that recursively contain shared enums +void issue21642() @safe nothrow pure +{ + enum C : char { _ = 1, } + union U { C c; void[0] _; } + shared union V { U u; } + cast(void) hashOf(V.init); + // Also test the underlying reason the above was failing. + import core.internal.convert : toUbyte; + shared C c; + assert(toUbyte(c) == [ubyte(1)]); +} + +/// Accept enum type whose ultimate base type is a SIMD vector. +void issue22024() @nogc nothrow pure @safe +{ + static if (is(__vector(float[2]))) + { + enum E2 : __vector(float[2]) { a = __vector(float[2]).init, } + enum F2 : E2 { a = E2.init, } + assert(hashOf(E2.init) == hashOf(F2.init)); + assert(hashOf(E2.init, 1) == hashOf(F2.init, 1)); + } + static if (is(__vector(float[4]))) + { + enum E4 : __vector(float[4]) { a = __vector(float[4]).init, } + enum F4 : E4 { a = E4.init, } + assert(hashOf(E4.init) == hashOf(F4.init)); + assert(hashOf(E4.init, 1) == hashOf(F4.init, 1)); + } +} + +/// hashOf(S) can segfault if S.toHash is forwarded via `alias this` to a +/// receiver which may be null. +void issue22076() +{ + static struct S0 { Object a; alias a this; } + + static struct S1 + { + S0 a; + inout(S0)* b() inout nothrow { return &a; } + alias b this; + } + + static struct S2 + { + S0 a; + S1 b; + } + + extern(C++) static class C0 + { + int foo() { return 0; } // Need at least one function in vtable. + S0 a; alias a this; + } + + extern(C++) static class C1 + { + S1 a; + inout(S1)* b() inout nothrow { return &a; } + alias b this; + } + + cast(void) hashOf(S0.init); + cast(void) hashOf(S0.init, 0); + cast(void) hashOf(S1.init); + cast(void) hashOf(S1.init, 0); + cast(void) hashOf(S2.init); + cast(void) hashOf(S2.init, 0); + auto c0 = new C0(); + cast(void) hashOf(c0); + cast(void) hashOf(c0, 0); + auto c1 = new C1(); + cast(void) hashOf(c1); + cast(void) hashOf(c1, 0); +} + /// Tests ensure TypeInfo_Array.getHash uses element hash functions instead /// of hashing array data. void testTypeInfoArrayGetHash1() @@ -300,11 +420,9 @@ void pr2243() enum Bar vsexpr = Bar(); enum int[int] aaexpr = [99:2, 12:6, 45:4]; enum Gun eexpr = Gun.A; - enum cdouble cexpr = 7+4i; enum Foo[] staexpr = [Foo(), Foo(), Foo()]; enum Bar[] vsaexpr = [Bar(), Bar(), Bar()]; enum realexpr = 7.88; - enum raexpr = [8.99L+86i, 3.12L+99i, 5.66L+12i]; enum nullexpr = null; enum plstr = Plain(); enum plarrstr = [Plain(), Plain(), Plain()]; @@ -328,7 +446,6 @@ void pr2243() enum h10 = vsexpr.hashOf(); enum h11 = aaexpr.hashOf(); enum h12 = eexpr.hashOf(); - enum h13 = cexpr.hashOf(); enum h14 = hashOf(new Boo); enum h15 = staexpr.hashOf(); enum h16 = hashOf([new Boo, new Boo, new Boo]); @@ -349,7 +466,6 @@ void pr2243() auto h27 = ptrexpr.hashOf(); enum h28 = realexpr.hashOf(); - enum h29 = raexpr.hashOf(); enum h30 = nullexpr.hashOf(); enum h31 = plstr.hashOf(); enum h32 = plarrstr.hashOf(); @@ -367,7 +483,6 @@ void pr2243() auto v10 = vsexpr; auto v11 = aaexpr; auto v12 = eexpr; - auto v13 = cexpr; auto v14 = new Boo; auto v15 = staexpr; auto v16 = [new Boo, new Boo, new Boo]; @@ -389,7 +504,6 @@ void pr2243() auto v26 = dgexpr; auto v27 = ptrexpr; auto v28 = realexpr; - auto v29 = raexpr; //runtime hashes auto rth1 = hashOf(v1); @@ -404,7 +518,6 @@ void pr2243() auto rth10 = hashOf(v10); auto rth11 = hashOf(v11); auto rth12 = hashOf(v12); - auto rth13 = hashOf(v13); auto rth14 = hashOf(v14); auto rth15 = hashOf(v15); auto rth16 = hashOf(v16); @@ -422,7 +535,6 @@ void pr2243() auto rth26 = hashOf(v26); auto rth27 = hashOf(v27); auto rth28 = hashOf(v28); - auto rth29 = hashOf(v29); auto rth31 = hashOf(v31); auto rth32 = hashOf(v32); @@ -440,7 +552,6 @@ void pr2243() assert(h10 == rth10); assert(h11 == rth11); assert(h12 == rth12); - assert(h13 == rth13); assert(h14 == rth14); assert(h15 == rth15); assert(h16 == rth16); @@ -455,8 +566,7 @@ void pr2243() assert(h25 == rth25); assert(h26 == rth26); assert(h27 == rth27); - assert(h28 == rth28); - assert(h29 == rth29);*/ + assert(h28 == rth28);*/ assert(h30 == rth30); assert(h31 == rth31); assert(h32 == rth32); @@ -482,7 +592,6 @@ void pr2243() auto tih10 = tiHashOf(v10); auto tih11 = tiHashOf(v11); auto tih12 = tiHashOf(v12); - auto tih13 = tiHashOf(v13); auto tih14 = tiHashOf(v14); auto tih15 = tiHashOf(v15); auto tih16 = tiHashOf(v16); @@ -498,7 +607,6 @@ void pr2243() auto tih26 = tiHashOf(v26); auto tih27 = tiHashOf(v27); auto tih28 = tiHashOf(v28); - auto tih29 = tiHashOf(v29); auto tih30 = tiHashOf(v30); auto tih31 = tiHashOf(v31); auto tih32 = tiHashOf(v32); @@ -516,7 +624,6 @@ void pr2243() //assert(tih10 == rth10); // need compiler-generated __xtoHash changes assert(tih11 == rth11); assert(tih12 == rth12); - assert(tih13 == rth13); assert(tih14 == rth14); assert(tih15 == rth15); assert(tih16 == rth16); @@ -532,7 +639,6 @@ void pr2243() assert(tih26 == rth26); assert(tih27 == rth27); assert(tih28 == rth28); - assert(tih29 == rth29); assert(tih30 == rth30); assert(tih31 == rth31); assert(tih32 == rth32); diff --git a/libphobos/testsuite/libphobos.imports/bug18193.d b/libphobos/testsuite/libphobos.imports/bug18193.d new file mode 100644 index 00000000000..fc8f5ca6882 --- /dev/null +++ b/libphobos/testsuite/libphobos.imports/bug18193.d @@ -0,0 +1,4 @@ +// { dg-options "-fversion=Shared" } +// { dg-do compile } +import core.runtime; +import core.thread; diff --git a/libphobos/testsuite/libphobos.init_fini/custom_gc.d b/libphobos/testsuite/libphobos.init_fini/custom_gc.d new file mode 100644 index 00000000000..a5e2bf40356 --- /dev/null +++ b/libphobos/testsuite/libphobos.init_fini/custom_gc.d @@ -0,0 +1,203 @@ +import core.gc.registry; +import core.gc.gcinterface; +import core.stdc.stdlib; + +static import core.memory; + +extern (C) __gshared string[] rt_options = ["gcopt=gc:malloc"]; + +extern (C) pragma(crt_constructor) void register_mygc() +{ + registerGCFactory("malloc", &MallocGC.initialize); +} + +extern (C) void register_default_gcs() +{ + // remove default GCs +} + +/** Simple GC that requires any pointers passed to it's API + to point to start of the allocation. + */ +class MallocGC : GC +{ +nothrow @nogc: + static GC initialize() + { + import core.stdc.string : memcpy; + + __gshared ubyte[__traits(classInstanceSize, MallocGC)] buf; + + auto init = typeid(MallocGC).initializer(); + assert(init.length == buf.length); + auto instance = cast(MallocGC) memcpy(buf.ptr, init.ptr, init.length); + instance.__ctor(); + return instance; + } + + this() + { + } + + void Dtor() + { + } + + void enable() + { + } + + void disable() + { + } + + void collect() nothrow + { + } + + void collectNoStack() nothrow + { + } + + void minimize() nothrow + { + } + + uint getAttr(void* p) nothrow + { + return 0; + } + + uint setAttr(void* p, uint mask) nothrow + { + return mask; + } + + uint clrAttr(void* p, uint mask) nothrow + { + return mask; + } + + void* malloc(size_t size, uint bits, const TypeInfo ti) nothrow + { + return sentinelAdd(.malloc(size + sentinelSize), size); + } + + BlkInfo qalloc(size_t size, uint bits, const scope TypeInfo ti) nothrow + { + return BlkInfo(malloc(size, bits, ti), size); + } + + void* calloc(size_t size, uint bits, const TypeInfo ti) nothrow + { + return sentinelAdd(.calloc(1, size + sentinelSize), size); + } + + void* realloc(void* p, size_t size, uint bits, const TypeInfo ti) nothrow + { + return sentinelAdd(.realloc(p - sentinelSize, size + sentinelSize), size); + } + + size_t extend(void* p, size_t minsize, size_t maxsize, const TypeInfo ti) nothrow + { + return 0; + } + + size_t reserve(size_t size) nothrow + { + return 0; + } + + void free(void* p) nothrow + { + free(p - sentinelSize); + } + + void* addrOf(void* p) nothrow + { + return p; + } + + size_t sizeOf(void* p) nothrow + { + return query(p).size; + } + + BlkInfo query(void* p) nothrow + { + return p ? BlkInfo(p, sentinelGet(p)) : BlkInfo.init; + } + + core.memory.GC.Stats stats() nothrow + { + return core.memory.GC.Stats.init; + } + + core.memory.GC.ProfileStats profileStats() nothrow + { + return typeof(return).init; + } + + void addRoot(void* p) nothrow @nogc + { + } + + void removeRoot(void* p) nothrow @nogc + { + } + + @property RootIterator rootIter() @nogc + { + return null; + } + + void addRange(void* p, size_t sz, const TypeInfo ti) nothrow @nogc + { + } + + void removeRange(void* p) nothrow @nogc + { + } + + @property RangeIterator rangeIter() @nogc + { + return null; + } + + void runFinalizers(const scope void[] segment) nothrow + { + } + + bool inFinalizer() nothrow + { + return false; + } + + ulong allocatedInCurrentThread() nothrow + { + return stats().allocatedInCurrentThread; + } + +private: + // doesn't care for alignment + static void* sentinelAdd(void* p, size_t value) + { + *cast(size_t*) p = value; + return p + sentinelSize; + } + + static size_t sentinelGet(void* p) + { + return *cast(size_t*)(p - sentinelSize); + } + + enum sentinelSize = size_t.sizeof; +} + +void main() +{ + // test array append cache + char[] s; + foreach (char c; char.min .. char.max + 1) + s ~= c; +} diff --git a/libphobos/testsuite/libphobos.init_fini/test18996.d b/libphobos/testsuite/libphobos.init_fini/test18996.d new file mode 100644 index 00000000000..01d514cd563 --- /dev/null +++ b/libphobos/testsuite/libphobos.init_fini/test18996.d @@ -0,0 +1,13 @@ +// Issue https://issues.dlang.org/show_bug.cgi?id=18996 +// Array!string calls removeRange without first adding the range, but never +// initializes the GC. The behavior of the default GC is to ignore removing +// ranges when the range wasn't added. The ProtoGC originally would crash when +// this happened. + +import core.memory; + +void main() +{ + GC.removeRange(null); + GC.removeRoot(null); +} diff --git a/libphobos/testsuite/libphobos.lifetime/large_aggregate_destroy_21097.d b/libphobos/testsuite/libphobos.lifetime/large_aggregate_destroy_21097.d new file mode 100644 index 00000000000..bc0695ed57d --- /dev/null +++ b/libphobos/testsuite/libphobos.lifetime/large_aggregate_destroy_21097.d @@ -0,0 +1,78 @@ +// https://issues.dlang.org/show_bug.cgi?id=21097 + +// The crucial part of the test cases is testing `destroy`. At the same time, we test +// `core.internal.lifetime.emplaceInitializer` (which is currently called by `destroy`). + +enum SIZE = 10_000_000; // 10 MB should exhaust the stack on most if not all test systems. + +import core.internal.lifetime; + +void test_largestruct() +{ + static struct LargeStruct + { + int[SIZE/2] a1; + int b = 42; + int[SIZE/2] a2; + } + static LargeStruct s = void; + emplaceInitializer(s); + assert(s.b == 42); + s.b = 101; + destroy(s); + assert(s.b == 42); +} + +void test_largestruct_w_opassign() +{ + static struct LargeStructOpAssign + { + int[SIZE/2] a1; + int b = 420; // non-zero init + int[SIZE/2] a2; + + void opAssign(typeof(this)) {} // hasElaborateAssign == true + } + static LargeStructOpAssign s = void; + emplaceInitializer(s); + assert(s.b == 420); + s.b = 101; + destroy(s); + assert(s.b == 420); +} + +void test_largearray() { + static struct NonZero + { + int i = 123; + } + static NonZero[SIZE] s = void; + emplaceInitializer(s); + assert(s[SIZE/2] == NonZero.init); + s[10] = NonZero(101); + destroy(s); + assert(s[10] == NonZero.init); +} + +void test_largearray_w_opassign() { + static struct NonZeroWithOpAssign + { + int i = 123; + void opAssign(typeof(this)) {} // hasElaborateAssign == true + } + static NonZeroWithOpAssign[SIZE] s = void; + emplaceInitializer(s); + assert(s[SIZE/2] == NonZeroWithOpAssign.init); + s[10] = NonZeroWithOpAssign(101); + destroy(s); + assert(s[10] == NonZeroWithOpAssign.init); +} + +int main() +{ + test_largestruct(); + test_largestruct_w_opassign(); + test_largearray(); + test_largearray_w_opassign(); + return 0; +} diff --git a/libphobos/testsuite/libphobos.shared/host.c b/libphobos/testsuite/libphobos.shared/host.c index 81e896aa3d8..395ad0c3f55 100644 --- a/libphobos/testsuite/libphobos.shared/host.c +++ b/libphobos/testsuite/libphobos.shared/host.c @@ -10,6 +10,11 @@ int main(int argc, char* argv[]) void *druntime = dlopen(argv[1], RTLD_LAZY); // load druntime assert(druntime); #endif +#if defined(__DragonFly__) + // workaround for Bugzilla 14824 + void *druntime = dlopen(argv[1], RTLD_LAZY); // load druntime + assert(druntime); +#endif const size_t pathlen = strrchr(argv[0], '/') - argv[0] + 1; char *name = malloc(pathlen + sizeof("plugin1.so")); @@ -55,6 +60,9 @@ int main(int argc, char* argv[]) #if defined(__FreeBSD__) dlclose(druntime); +#endif +#if defined(__DragonFly__) + dlclose(druntime); #endif return EXIT_SUCCESS; } diff --git a/libphobos/testsuite/libphobos.shared/link_mod_collision.d b/libphobos/testsuite/libphobos.shared/link_mod_collision.d deleted file mode 100644 index 9c3d1c7b235..00000000000 --- a/libphobos/testsuite/libphobos.shared/link_mod_collision.d +++ /dev/null @@ -1,5 +0,0 @@ -module lib; // module collides with lib.so - -void main() -{ -} diff --git a/libphobos/testsuite/libphobos.shared/load.d b/libphobos/testsuite/libphobos.shared/load.d index 5a2dd01b778..0d3ffa65d6e 100644 --- a/libphobos/testsuite/libphobos.shared/load.d +++ b/libphobos/testsuite/libphobos.shared/load.d @@ -2,7 +2,6 @@ import core.runtime; import core.stdc.stdio; import core.stdc.string; import core.thread; - import core.sys.posix.dlfcn; version (DragonFlyBSD) import core.sys.dragonflybsd.dlfcn : RTLD_NOLOAD; diff --git a/libphobos/testsuite/libphobos.shared/load_13414.d b/libphobos/testsuite/libphobos.shared/load_13414.d index f7cbf45190a..047d5079937 100644 --- a/libphobos/testsuite/libphobos.shared/load_13414.d +++ b/libphobos/testsuite/libphobos.shared/load_13414.d @@ -16,8 +16,17 @@ void runTest(string name) *cast(void function()*).dlsym(h, "_D9lib_1341420sharedStaticDtorHookOPFZv") = &sharedStaticDtorHook; Runtime.unloadLibrary(h); - assert(tlsDtor == 1); - assert(dtor == 1); + version (CRuntime_Musl) + { + // On Musl, unloadLibrary is a no-op because dlclose is a no-op + assert(tlsDtor == 0); + assert(dtor == 0); + } + else + { + assert(tlsDtor == 1); + assert(dtor == 1); + } } void main(string[] args) diff --git a/libphobos/testsuite/libphobos.shared/load_mod_collision.d b/libphobos/testsuite/libphobos.shared/load_mod_collision.d deleted file mode 100644 index 64243d4b7bb..00000000000 --- a/libphobos/testsuite/libphobos.shared/load_mod_collision.d +++ /dev/null @@ -1,14 +0,0 @@ -module lib; // module collides with lib.so - -import core.runtime; -import core.stdc.stdio; -import core.stdc.string; -import core.sys.posix.dlfcn; - -void main(string[] args) -{ - auto name = args[0] ~ '\0'; - const pathlen = strrchr(name.ptr, '/') - name.ptr + 1; - name = name[0 .. pathlen] ~ "lib.so"; - auto lib = Runtime.loadLibrary(name); -} diff --git a/libphobos/testsuite/libphobos.thread/external_threads.d b/libphobos/testsuite/libphobos.thread/external_threads.d new file mode 100644 index 00000000000..9c98a3fa13d --- /dev/null +++ b/libphobos/testsuite/libphobos.thread/external_threads.d @@ -0,0 +1,50 @@ +import core.sys.posix.pthread; +import core.memory; +import core.thread; + +extern (C) void rt_moduleTlsCtor(); +extern (C) void rt_moduleTlsDtor(); + +extern(C) +void* entry_point1(void*) +{ + // try collecting - GC must ignore this call because this thread + // is not registered in runtime + GC.collect(); + return null; +} + +extern(C) +void* entry_point2(void*) +{ + // This thread gets registered in druntime, does some work and gets + // unregistered to be cleaned up manually + thread_attachThis(); + rt_moduleTlsCtor(); + + auto x = new int[10]; + + rt_moduleTlsDtor(); + thread_detachThis(); + return null; +} + +void main() +{ + // allocate some garbage + auto x = new int[1000]; + + { + pthread_t thread; + auto status = pthread_create(&thread, null, &entry_point1, null); + assert(status == 0); + pthread_join(thread, null); + } + + { + pthread_t thread; + auto status = pthread_create(&thread, null, &entry_point2, null); + assert(status == 0); + pthread_join(thread, null); + } +} diff --git a/libphobos/testsuite/libphobos.thread/fiber_guard_page.d b/libphobos/testsuite/libphobos.thread/fiber_guard_page.d index ca54a19857f..dbdd0f9d08d 100644 --- a/libphobos/testsuite/libphobos.thread/fiber_guard_page.d +++ b/libphobos/testsuite/libphobos.thread/fiber_guard_page.d @@ -4,6 +4,9 @@ import core.thread; import core.sys.posix.signal; import core.sys.posix.sys.mman; +version (LDC) import ldc.attributes; +else struct optStrategy { string a; } + // this should be true for most architectures // (taken from core.thread) version (GNU_StackGrowsDown) @@ -12,6 +15,7 @@ version (GNU_StackGrowsDown) enum stackSize = MINSIGSTKSZ; // Simple method that causes a stack overflow +@optStrategy("none") void stackMethod() { // Over the stack size, so it overflows the stack diff --git a/libphobos/testsuite/libphobos.thread/join_detach.d b/libphobos/testsuite/libphobos.thread/join_detach.d new file mode 100644 index 00000000000..f1515190171 --- /dev/null +++ b/libphobos/testsuite/libphobos.thread/join_detach.d @@ -0,0 +1,20 @@ +import core.thread; +import core.sync.semaphore; + +__gshared Semaphore sem; + +void thread_main () +{ + sem.notify(); +} + +void main() +{ + auto th = new Thread(&thread_main); + sem = new Semaphore(); + th.start(); + sem.wait(); + while (th.isRunning()) {} + destroy(th); // force detach + th.join(); +} diff --git a/libphobos/testsuite/libphobos.thread/test_import.d b/libphobos/testsuite/libphobos.thread/test_import.d new file mode 100644 index 00000000000..dfa0487d916 --- /dev/null +++ b/libphobos/testsuite/libphobos.thread/test_import.d @@ -0,0 +1,7 @@ +// https://issues.dlang.org/show_bug.cgi?id=20447 +void main() +{ + import core.thread; + int[] x; + auto b = x.dup; +} diff --git a/libphobos/testsuite/libphobos.thread/tlsgc_sections.d b/libphobos/testsuite/libphobos.thread/tlsgc_sections.d index 1421d926a38..1bd3f26cffc 100644 --- a/libphobos/testsuite/libphobos.thread/tlsgc_sections.d +++ b/libphobos/testsuite/libphobos.thread/tlsgc_sections.d @@ -1,39 +1,70 @@ -final class Class +import core.memory; +import core.sync.condition; +import core.sync.mutex; +import core.thread; + +__gshared Condition g_cond; +__gshared Mutex g_mutex; +__gshared int g_step = 0; + +class C { - // This gets triggered although the instance always stays referenced. ~this() { import core.stdc.stdlib; - abort(); + abort(); // this gets triggered although the instance always stays referenced } } -Class obj; +C c; static this() { - obj = new Class; + c = new C; } static ~this() { - // Free without destruction to avoid triggering abort() import core.memory; - GC.free(cast(void*)obj); + GC.free(cast(void*)c); // free without destruction to avoid triggering abort() } -void doit() +void test() { - foreach (i; 0 .. 10_000) - new ubyte[](100_000); + assert(c !is null); + + // notify the main thread of the finished initialization + synchronized (g_mutex) g_step = 1; + g_cond.notifyAll(); + + // wait until the GC collection is done + synchronized (g_mutex) { + while (g_step != 2) + g_cond.wait(); + } } + void main() { - import core.thread; - auto t = new Thread(&doit); - t.start(); + g_mutex = new Mutex; + g_cond = new Condition(g_mutex); + + auto th = new Thread(&test); + th.start(); + + // wait for thread to be fully initialized + synchronized (g_mutex) { + while (g_step != 1) + g_cond.wait(); + } + + // this causes the other thread's C instance to be reaped with the bug present + GC.collect(); + + // allow the thread to shut down + synchronized (g_mutex) g_step = 2; + g_cond.notifyAll(); - // This triggers the GC that frees the still referenced Class instance. - doit(); + th.join(); } diff --git a/libphobos/testsuite/libphobos.thread/tlsstack.d b/libphobos/testsuite/libphobos.thread/tlsstack.d new file mode 100644 index 00000000000..dbd93213bfe --- /dev/null +++ b/libphobos/testsuite/libphobos.thread/tlsstack.d @@ -0,0 +1,38 @@ +module core.thread.test; // needs access to getStackTop()/getStackBottom() + +import core.stdc.stdio; +import core.thread; + +ubyte[16384] data; + +void showThreadInfo() nothrow +{ + try + { + auto top = getStackTop(); + auto bottom = getStackBottom(); + printf("tlsdata: %p\n", data.ptr); + printf("stack top: %p\n", getStackTop()); + printf("stack bottom:%p\n", getStackBottom()); + printf("used stack: %lld\n", cast(ulong)(bottom - top)); + } + catch(Exception e) + { + assert(false, e.msg); + } +} + +void main() +{ + printf("### main\n"); + showThreadInfo(); + + printf("### thread\n"); + auto th = new Thread(&showThreadInfo, 16384); + th.start(); + th.join(); + + printf("### lowlevel thread\n"); + auto llth = createLowLevelThread(() { showThreadInfo(); }); + joinLowLevelThread(llth); +} diff --git a/libphobos/testsuite/libphobos.typeinfo/enum_.d b/libphobos/testsuite/libphobos.typeinfo/enum_.d new file mode 100644 index 00000000000..58cfbe34d60 --- /dev/null +++ b/libphobos/testsuite/libphobos.typeinfo/enum_.d @@ -0,0 +1,21 @@ +// https://issues.dlang.org/show_bug.cgi?id=21441 + +int dtorCount; +int postblitCount; + +struct S +{ + this(this) { ++postblitCount; } + ~this() { ++dtorCount; } +} + +enum E : S { _ = S.init } + +void main() +{ + E e; + typeid(e).destroy(&e); + assert(dtorCount == 1); + typeid(e).postblit(&e); + assert(postblitCount == 1); +} diff --git a/libphobos/testsuite/libphobos.typeinfo/isbaseof.d b/libphobos/testsuite/libphobos.typeinfo/isbaseof.d new file mode 100644 index 00000000000..26dd5a66e3e --- /dev/null +++ b/libphobos/testsuite/libphobos.typeinfo/isbaseof.d @@ -0,0 +1,46 @@ +// https://issues.dlang.org/show_bug.cgi?id=20178 + +interface I {} +interface J : I {} +interface K(T) {} +class C1 : I {} +class C2 : C1 {} +class C3 : J {} +class C4(T) : C3, K!T {} +class C5(T) : C4!T {} + +void main() @nogc nothrow pure @safe +{ + assert(typeid(C1).isBaseOf(typeid(C1))); + assert(typeid(C1).isBaseOf(typeid(C2))); + + assert(!typeid(C2).isBaseOf(typeid(C1))); + assert(typeid(C2).isBaseOf(typeid(C2))); + + assert(!typeid(C1).isBaseOf(typeid(Object))); + assert(!typeid(C2).isBaseOf(typeid(Object))); + assert(typeid(Object).isBaseOf(typeid(C1))); + assert(typeid(Object).isBaseOf(typeid(C2))); + + assert(typeid(I).isBaseOf(typeid(I))); + assert(typeid(I).isBaseOf(typeid(J))); + assert(typeid(I).isBaseOf(typeid(C1))); + assert(typeid(I).isBaseOf(typeid(C2))); + assert(typeid(I).isBaseOf(typeid(C3))); + assert(!typeid(I).isBaseOf(typeid(Object))); + + assert(!typeid(J).isBaseOf(typeid(I))); + assert(typeid(J).isBaseOf(typeid(J))); + assert(!typeid(J).isBaseOf(typeid(C1))); + assert(!typeid(J).isBaseOf(typeid(C2))); + assert(typeid(J).isBaseOf(typeid(C3))); + assert(!typeid(J).isBaseOf(typeid(Object))); + + assert(typeid(C4!int).isBaseOf(typeid(C5!int))); + assert(typeid(K!int).isBaseOf(typeid(C5!int))); + assert(!typeid(C4!Object).isBaseOf(typeid(C5!int))); + assert(!typeid(K!Object).isBaseOf(typeid(C5!int))); + + static assert(!__traits(compiles, TypeInfo.init.isBaseOf(typeid(C1)))); + static assert(!__traits(compiles, typeid(C1).isBaseOf(TypeInfo.init))); +} diff --git a/libphobos/testsuite/libphobos.unittest/customhandler.d b/libphobos/testsuite/libphobos.unittest/customhandler.d new file mode 100644 index 00000000000..f5a04350d9c --- /dev/null +++ b/libphobos/testsuite/libphobos.unittest/customhandler.d @@ -0,0 +1,21 @@ +import core.runtime; + +UnitTestResult customModuleUnitTester() +{ + version(GoodTests) return UnitTestResult(100, 100, false, true); + version(FailedTests) return UnitTestResult(100, 0, false, true); + version(NoTests) return UnitTestResult(0, 0, true, false); + version(FailNoPrintout) return UnitTestResult(100, 0, false, false); + version(PassNoPrintout) return UnitTestResult(100, 100, false, false); +} + +shared static this() +{ + Runtime.extendedModuleUnitTester = &customModuleUnitTester; +} + +void main() +{ + import core.stdc.stdio; + fprintf(stderr, "main\n"); +} From patchwork Tue Nov 30 15:14:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 48297 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5B3F385C407 for ; Tue, 30 Nov 2021 15:15:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5B3F385C407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638285339; bh=vJsX7o0xvKdu2Zux4rGw7CG5McVPq8ZCenMpKq6Fibc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=S6IF3XAO1u0GFTjEhvkJ10l4a/9K6LsYNpAZpf/fGpLJkaPLHJlkGKAHiDI4xNimH P8Umai3TTFuzumi5i4EtHLetprmWu8jdon8GNR/blsvKcSu80cCC+tkBRzd2E/6CbL 9igID7fUDqquyF6D+K9oot74JA+53FN7Yy+PJBCQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-102.mailbox.org (mout-p-102.mailbox.org [80.241.56.152]) by sourceware.org (Postfix) with ESMTPS id A122F385C40A for ; Tue, 30 Nov 2021 15:14:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A122F385C40A Received: from smtp102.mailbox.org (smtp102.mailbox.org [80.241.60.233]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4J3Qk12BzwzQjbk; Tue, 30 Nov 2021 16:14:33 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de To: gcc-patches@gcc.gnu.org Subject: [committed 18/19] testsuite: Update gdc testsuite to pass on latest version Date: Tue, 30 Nov 2021 16:14:24 +0100 Message-Id: <20211130151424.646687-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This updates the GDC testsuite parts to be compatible with the current language features/deprecations. The dejagnu gdc-utils helper has also been updated to handle the new options and directives added to the D2 testsuite tests. Bootstrapped, regression tested, and committed to mainline. Regards, Iain. --- gcc/testsuite/ChangeLog: * gdc.dg/Wcastresult2.d: Update test. * gdc.dg/asm1.d: Likewise. * gdc.dg/asm2.d: Likewise. * gdc.dg/asm3.d: Likewise. * gdc.dg/gdc282.d: Likewise. * gdc.dg/imports/gdc170.d: Likewise. * gdc.dg/intrinsics.d: Likewise. * gdc.dg/pr101672.d: Likewise. * gdc.dg/pr90650a.d: Likewise. * gdc.dg/pr90650b.d: Likewise. * gdc.dg/pr94777a.d: Likewise. * gdc.dg/pr95250.d: Likewise. * gdc.dg/pr96869.d: Likewise. * gdc.dg/pr98277.d: Likewise. * gdc.dg/pr98457.d: Likewise. * gdc.dg/simd1.d: Likewise. * gdc.dg/simd2a.d: Likewise. * gdc.dg/simd2b.d: Likewise. * gdc.dg/simd2c.d: Likewise. * gdc.dg/simd2d.d: Likewise. * gdc.dg/simd2e.d: Likewise. * gdc.dg/simd2f.d: Likewise. * gdc.dg/simd2g.d: Likewise. * gdc.dg/simd2h.d: Likewise. * gdc.dg/simd2i.d: Likewise. * gdc.dg/simd2j.d: Likewise. * gdc.dg/simd7951.d: Likewise. * gdc.dg/torture/gdc309.d: Likewise. * gdc.dg/torture/pr94424.d: Likewise. * gdc.dg/torture/pr94777b.d: Likewise. * lib/gdc-utils.exp (gdc-convert-args): Handle new compiler options. (gdc-convert-test): Handle CXXFLAGS, EXTRA_OBJC_SOURCES, and ARG_SETS test directives. (gdc-do-test): Only import modules in the test run directory. * gdc.dg/pr94777c.d: New test. * gdc.dg/pr96156b.d: New test. * gdc.dg/pr96157c.d: New test. * gdc.dg/simd_ctfe.d: New test. * gdc.dg/torture/simd17344.d: New test. * gdc.dg/torture/simd20052.d: New test. * gdc.dg/torture/simd6.d: New test. * gdc.dg/torture/simd7.d: New test. --- gcc/testsuite/gdc.dg/Wcastresult2.d | 2 +- gcc/testsuite/gdc.dg/asm1.d | 18 +-- gcc/testsuite/gdc.dg/asm2.d | 2 +- gcc/testsuite/gdc.dg/asm3.d | 10 +- gcc/testsuite/gdc.dg/gdc282.d | 6 +- gcc/testsuite/gdc.dg/imports/gdc170.d | 8 +- gcc/testsuite/gdc.dg/intrinsics.d | 36 +++--- gcc/testsuite/gdc.dg/pr101672.d | 2 +- gcc/testsuite/gdc.dg/pr90650a.d | 2 +- gcc/testsuite/gdc.dg/pr90650b.d | 2 +- gcc/testsuite/gdc.dg/pr94777a.d | 2 +- gcc/testsuite/gdc.dg/pr94777c.d | 62 +++++++++++ gcc/testsuite/gdc.dg/pr95250.d | 2 +- gcc/testsuite/gdc.dg/pr96156b.d | 17 +++ gcc/testsuite/gdc.dg/pr96157c.d | 40 +++++++ gcc/testsuite/gdc.dg/pr96869.d | 26 ++--- gcc/testsuite/gdc.dg/pr98277.d | 2 +- gcc/testsuite/gdc.dg/pr98457.d | 6 +- gcc/testsuite/gdc.dg/simd1.d | 8 -- gcc/testsuite/gdc.dg/simd2a.d | 8 -- gcc/testsuite/gdc.dg/simd2b.d | 8 -- gcc/testsuite/gdc.dg/simd2c.d | 8 -- gcc/testsuite/gdc.dg/simd2d.d | 8 -- gcc/testsuite/gdc.dg/simd2e.d | 8 -- gcc/testsuite/gdc.dg/simd2f.d | 8 -- gcc/testsuite/gdc.dg/simd2g.d | 8 -- gcc/testsuite/gdc.dg/simd2h.d | 8 -- gcc/testsuite/gdc.dg/simd2i.d | 8 -- gcc/testsuite/gdc.dg/simd2j.d | 8 -- gcc/testsuite/gdc.dg/simd7951.d | 1 + gcc/testsuite/gdc.dg/simd_ctfe.d | 87 +++++++++++++++ gcc/testsuite/gdc.dg/torture/gdc309.d | 1 + gcc/testsuite/gdc.dg/torture/pr94424.d | 16 +++ gcc/testsuite/gdc.dg/torture/pr94777b.d | 135 ----------------------- gcc/testsuite/gdc.dg/torture/simd17344.d | 11 ++ gcc/testsuite/gdc.dg/torture/simd20052.d | 17 +++ gcc/testsuite/gdc.dg/torture/simd6.d | 26 +++++ gcc/testsuite/gdc.dg/torture/simd7.d | 18 +++ gcc/testsuite/lib/gdc-utils.exp | 81 ++++++++++++-- 39 files changed, 435 insertions(+), 291 deletions(-) create mode 100644 gcc/testsuite/gdc.dg/pr94777c.d create mode 100644 gcc/testsuite/gdc.dg/pr96156b.d create mode 100644 gcc/testsuite/gdc.dg/pr96157c.d create mode 100644 gcc/testsuite/gdc.dg/simd_ctfe.d create mode 100644 gcc/testsuite/gdc.dg/torture/simd17344.d create mode 100644 gcc/testsuite/gdc.dg/torture/simd20052.d create mode 100644 gcc/testsuite/gdc.dg/torture/simd6.d create mode 100644 gcc/testsuite/gdc.dg/torture/simd7.d diff --git a/gcc/testsuite/gdc.dg/Wcastresult2.d b/gcc/testsuite/gdc.dg/Wcastresult2.d index 56d2dd20e82..83d189a6adf 100644 --- a/gcc/testsuite/gdc.dg/Wcastresult2.d +++ b/gcc/testsuite/gdc.dg/Wcastresult2.d @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-Wcast-result" } +// { dg-options "-Wcast-result -Wno-deprecated" } void test() { diff --git a/gcc/testsuite/gdc.dg/asm1.d b/gcc/testsuite/gdc.dg/asm1.d index dce36769370..1b249ee7b35 100644 --- a/gcc/testsuite/gdc.dg/asm1.d +++ b/gcc/testsuite/gdc.dg/asm1.d @@ -24,9 +24,9 @@ void parse3() { asm { "" [; } // { dg-error "expression expected, not ';'" "" { target *-*-* } .-1 } - // { dg-error "found 'EOF' when expecting ','" "" { target *-*-* } .-2 } - // { dg-error "found 'EOF' when expecting ']'" "" { target *-*-* } .-3 } - // { dg-error "found 'EOF' when expecting ';'" "" { target *-*-* } .-4 } + // { dg-error "found 'End of File' when expecting ','" "" { target *-*-* } .-2 } + // { dg-error "found 'End of File' when expecting ']'" "" { target *-*-* } .-3 } + // { dg-error "found 'End of File' when expecting ';'" "" { target *-*-* } .-4 } } void parse4() @@ -46,8 +46,8 @@ void semantic1() ; } asm { "" : : : : L1, L2; } - // { dg-error "goto skips declaration of variable asm1.semantic1.one" "" { target *-*-* } .-1 } - // { dg-error "goto skips declaration of variable asm1.semantic1.two" "" { target *-*-* } .-2 } + // { dg-error "'goto' skips declaration of variable 'asm1.semantic1.one'" "" { target *-*-* } .-1 } + // { dg-error "'goto' skips declaration of variable 'asm1.semantic1.two'" "" { target *-*-* } .-2 } { int two; L2: @@ -58,19 +58,19 @@ void semantic1() void semantic2a(X...)(X expr) { alias X[0] var1; - asm { "%0" : "=m" (var1); } // { dg-error "double 'double' is a type, not an lvalue" } + asm { "%0" : "=m" (var1); } // { dg-error "double' is a 'double' definition and cannot be modified" } } void semantic2() { - semantic2a(3.6); // { dg-error "template instance asm1.semantic2a!double error instantiating" } + semantic2a(3.6); // { dg-error "template instance 'asm1.semantic2a!double' error instantiating" } } void semantic3() { asm { - unknown; // { dg-error "undefined identifier" } + unknown; // { dg-error "undefined identifier 'unknown'" } } } @@ -86,6 +86,6 @@ void semantic4() { asm { - "%0" : : "m" (S4.foo); // { dg-error "template instance opDispatch!\"foo\" has no value" } + "%0" : : "m" (S4.foo); // { dg-error "template instance 'opDispatch!\"foo\"' has no value" } } } diff --git a/gcc/testsuite/gdc.dg/asm2.d b/gcc/testsuite/gdc.dg/asm2.d index bce0e41a60f..5b86e3564ef 100644 --- a/gcc/testsuite/gdc.dg/asm2.d +++ b/gcc/testsuite/gdc.dg/asm2.d @@ -3,6 +3,6 @@ module asm2; void test() { - asm const shared { } // { dg-error "const/immutable/shared/inout attributes are not allowed on asm blocks" } + asm const shared { } // { dg-error "'const'/'immutable'/'shared'/'inout' attributes are not allowed on 'asm' blocks" } } diff --git a/gcc/testsuite/gdc.dg/asm3.d b/gcc/testsuite/gdc.dg/asm3.d index 333d83ec99b..d792b2474be 100644 --- a/gcc/testsuite/gdc.dg/asm3.d +++ b/gcc/testsuite/gdc.dg/asm3.d @@ -2,23 +2,23 @@ // { dg-options "-Wall -Wdeprecated -Werror" } module asm3; -void test1() nothrow // { dg-error "nothrow function 'asm3.test1' may throw" } +void test1() nothrow { - asm { } // { dg-error "asm statement is assumed to throw - mark it with 'nothrow' if it does not" } + asm { } // { dg-error "'asm' statement is assumed to throw - mark it with 'nothrow' if it does not" } } void test2() pure { - asm { } // { dg-error "asm statement is assumed to be impure - mark it with 'pure' if it is not" } + asm { } // { dg-error "'asm' statement is assumed to be impure - mark it with 'pure' if it is not" } } void test3() @nogc { - asm { } // { dg-error "asm statement is assumed to use the GC - mark it with '@nogc' if it does not" } + asm { } // { dg-error "'asm' statement is assumed to use the GC - mark it with '@nogc' if it does not" } } void test4() @safe { - asm { } // { dg-error "asm statement is assumed to be @system - mark it with '@trusted' if it is not" } + asm { } // { dg-error "'asm' statement is assumed to be '@system' - mark it with '@trusted' if it is not" } } diff --git a/gcc/testsuite/gdc.dg/gdc282.d b/gcc/testsuite/gdc.dg/gdc282.d index ce840501d64..93e11fa0cbc 100644 --- a/gcc/testsuite/gdc.dg/gdc282.d +++ b/gcc/testsuite/gdc.dg/gdc282.d @@ -12,7 +12,7 @@ class C282a { } - void f282() // { dg-error "conflicts with gdc282.C282a.f282" } + void f282() // { dg-error "conflicts with previous declaration" } { } } @@ -27,7 +27,7 @@ class C282b { } - void f282() // { dg-error "conflicts with gdc282.C282b.f282" } + void f282() // { dg-error "conflicts with previous declaration" } { } } @@ -42,7 +42,7 @@ class C282c { } - void f282() // { dg-error "conflicts with gdc282.C282c.f282" } + void f282() // { dg-error "conflicts with previous declaration" } { } } diff --git a/gcc/testsuite/gdc.dg/imports/gdc170.d b/gcc/testsuite/gdc.dg/imports/gdc170.d index f9fea1f483c..aedef60c6b4 100644 --- a/gcc/testsuite/gdc.dg/imports/gdc170.d +++ b/gcc/testsuite/gdc.dg/imports/gdc170.d @@ -7,12 +7,12 @@ class bar(T) template foo(T) { - bar!T foo1(T2)() if (true) body { return null; } + bar!T foo1(T2)() if (true) do { return null; } bar!T foo2(T2)() { return null; } - bar!T foo3(T2 = void)() if (true) body { return null; } + bar!T foo3(T2 = void)() if (true) do { return null; } bar!T foo4(T2 = void)() { return null; } - void foo5(T2)(bar!T x) if (true) body {} + void foo5(T2)(bar!T x) if (true) do {} void foo6(T2)(bar!T x) {} - void foo7(T2 = void)(bar!T x) if (true) body {} + void foo7(T2 = void)(bar!T x) if (true) do {} void foo8(T2 = void)(bar!T x) {} } diff --git a/gcc/testsuite/gdc.dg/intrinsics.d b/gcc/testsuite/gdc.dg/intrinsics.d index d9ccc0ec5ce..dca40d2cf69 100644 --- a/gcc/testsuite/gdc.dg/intrinsics.d +++ b/gcc/testsuite/gdc.dg/intrinsics.d @@ -35,22 +35,6 @@ ulong test_bswap(ulong a) { return bswap(a); } int test_popcnt(uint a) { return popcnt(a); } // { dg-final { scan-tree-dump " __builtin_popcount(l|ll) " "original" } } int test_popcnt(ulong a) { return popcnt(a); } -// { dg-final { scan-tree-dump "\\(volatile ubyte \\*\\) a;" "original" } } -ubyte test_volatileLoad(ubyte *a) { return volatileLoad(a); } -// { dg-final { scan-tree-dump "\\(volatile ushort \\*\\) a;" "original" } } -ushort test_volatileLoad(ushort *a) { return volatileLoad(a); } -// { dg-final { scan-tree-dump "\\(volatile uint \\*\\) a;" "original" } } -uint test_volatileLoad(uint *a) { return volatileLoad(a); } -// { dg-final { scan-tree-dump "\\(volatile ulong \\*\\) a;" "original" } } -ulong test_volatileLoad(ulong *a) { return volatileLoad(a); } -// { dg-final { scan-tree-dump "\\(volatile ubyte \\*\\) a = b" "original" } } -void test_volatileStore(ubyte *a, ubyte b) { return volatileStore(a, b); } -// { dg-final { scan-tree-dump "\\(volatile ushort \\*\\) a = b" "original" } } -void test_volatileStore(ushort *a, ushort b) { return volatileStore(a, b); } -// { dg-final { scan-tree-dump "\\(volatile uint \\*\\) a = b" "original" } } -void test_volatileStore(uint *a, uint b) { return volatileStore(a, b); } -// { dg-final { scan-tree-dump "\\(volatile ulong \\*\\) a = b" "original" } } -void test_volatileStore(ulong *a, ulong b) { return volatileStore(a, b); } // { dg-final { scan-tree-dump " a r<< b;" "original" } } ubyte test_rol(ubyte a, uint b) { return rol!ubyte(a, b); } // { dg-final { scan-tree-dump " a r>> 31;" "original" } } @@ -140,6 +124,26 @@ real test_toPrecl(float a) { return toPrec!real(a); } real test_toPrecl(double a) { return toPrec!real(a); } real test_toPrecl(real a) { return toPrec!real(a); } +////////////////////////////////////////////////////// +// core.volatile + +// { dg-final { scan-tree-dump "\\(volatile ubyte \\*\\) a;" "original" } } +ubyte test_volatileLoad(ubyte *a) { return volatileLoad(a); } +// { dg-final { scan-tree-dump "\\(volatile ushort \\*\\) a;" "original" } } +ushort test_volatileLoad(ushort *a) { return volatileLoad(a); } +// { dg-final { scan-tree-dump "\\(volatile uint \\*\\) a;" "original" } } +uint test_volatileLoad(uint *a) { return volatileLoad(a); } +// { dg-final { scan-tree-dump "\\(volatile ulong \\*\\) a;" "original" } } +ulong test_volatileLoad(ulong *a) { return volatileLoad(a); } +// { dg-final { scan-tree-dump "\\(volatile ubyte \\*\\) a = b" "original" } } +void test_volatileStore(ubyte *a, ubyte b) { return volatileStore(a, b); } +// { dg-final { scan-tree-dump "\\(volatile ushort \\*\\) a = b" "original" } } +void test_volatileStore(ushort *a, ushort b) { return volatileStore(a, b); } +// { dg-final { scan-tree-dump "\\(volatile uint \\*\\) a = b" "original" } } +void test_volatileStore(uint *a, uint b) { return volatileStore(a, b); } +// { dg-final { scan-tree-dump "\\(volatile ulong \\*\\) a = b" "original" } } +void test_volatileStore(ulong *a, ulong b) { return volatileStore(a, b); } + ////////////////////////////////////////////////////// // core.stdc.stdarg diff --git a/gcc/testsuite/gdc.dg/pr101672.d b/gcc/testsuite/gdc.dg/pr101672.d index 292fd761fb1..8b337a4cf19 100644 --- a/gcc/testsuite/gdc.dg/pr101672.d +++ b/gcc/testsuite/gdc.dg/pr101672.d @@ -8,7 +8,7 @@ interface I101672 static int i101672; } -class A101672 : I101672 // { dg-error "class object.A101672 missing or corrupt object.d" } +class A101672 : I101672 { static int a101672; } diff --git a/gcc/testsuite/gdc.dg/pr90650a.d b/gcc/testsuite/gdc.dg/pr90650a.d index 57228cab19f..62b79941f20 100644 --- a/gcc/testsuite/gdc.dg/pr90650a.d +++ b/gcc/testsuite/gdc.dg/pr90650a.d @@ -10,5 +10,5 @@ class c void g () { - if (0 & [0] & c.f()) {} // { dg-error "array operation \\\[0\\\] & 0 & f\\(\\) without destination memory not allowed" } + if (0 & [0] & c.f()) {} // { dg-error "array operation .\\\[0\\\] & 0 & f\\(\\). without destination memory not allowed" } } diff --git a/gcc/testsuite/gdc.dg/pr90650b.d b/gcc/testsuite/gdc.dg/pr90650b.d index 2b3192ed2b6..11a02259481 100644 --- a/gcc/testsuite/gdc.dg/pr90650b.d +++ b/gcc/testsuite/gdc.dg/pr90650b.d @@ -9,5 +9,5 @@ class c } void g () { - if ([0] & c.f()) {} // { dg-error "array operation \\\[0\\\] & f\\(\\) without destination memory not allowed" } + if ([0] & c.f()) {} // { dg-error "array operation .\\\[0\\\] & f\\(\\). without destination memory not allowed" } } diff --git a/gcc/testsuite/gdc.dg/pr94777a.d b/gcc/testsuite/gdc.dg/pr94777a.d index a58fa557e35..d0cb5569e46 100644 --- a/gcc/testsuite/gdc.dg/pr94777a.d +++ b/gcc/testsuite/gdc.dg/pr94777a.d @@ -11,5 +11,5 @@ void f94777() this(this) { } } auto var = S94777(0); - variadic(var, S94777(1)); + variadic(var, S94777(1)); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" } } diff --git a/gcc/testsuite/gdc.dg/pr94777c.d b/gcc/testsuite/gdc.dg/pr94777c.d new file mode 100644 index 00000000000..9b725c052c3 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr94777c.d @@ -0,0 +1,62 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777 +// { dg-additional-options "-funittest" } +// { dg-do compile } + +void testVariadic(T)(int nargs, ...) +{ + import core.stdc.stdarg; + foreach(i; 0 .. nargs) + { + auto arg = va_arg!T(_argptr); + static if (__traits(compiles, arg.value)) + { + assert(arg.value == i); + } + else static if (__traits(compiles, arg[0])) + { + foreach (value; arg) + assert(value == i); + } + else + { + assert(arg == T.init); + } + } +} + +/******************************************/ + +struct Postblit +{ + static int count = 0; + int value; + this(this) { count++; } +} + +unittest +{ + auto a0 = Postblit(0); + auto a1 = Postblit(1); + auto a2 = Postblit(2); + testVariadic!Postblit(3, a0, a1, a2); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" } + assert(Postblit.count == 3); +} + +/******************************************/ + +struct CopyConstructor +{ + static int count = 0; + int value; + this(int v) { this.value = v; } + this(ref typeof(this) other) { count++; this.value = other.value; } +} + +unittest +{ + auto a0 = CopyConstructor(0); + auto a1 = CopyConstructor(1); + auto a2 = CopyConstructor(2); + testVariadic!CopyConstructor(3, a0, a1, a2); // { dg-error "cannot pass types with postblits or copy constructors as variadic arguments" } + assert(CopyConstructor.count == 3); +} diff --git a/gcc/testsuite/gdc.dg/pr95250.d b/gcc/testsuite/gdc.dg/pr95250.d index dfb8abb732f..ba0adeac521 100644 --- a/gcc/testsuite/gdc.dg/pr95250.d +++ b/gcc/testsuite/gdc.dg/pr95250.d @@ -15,4 +15,4 @@ void* f(T)(T a, T b) } static assert(is(typeof(f!(void*)(null, null)) == void*)); -// { dg-error "static assert \(.*\) is false" "" { target *-*-* } .-1 } +// { dg-error "static assert: \(.*\) is false" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/gdc.dg/pr96156b.d b/gcc/testsuite/gdc.dg/pr96156b.d new file mode 100644 index 00000000000..ae79d568ec6 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96156b.d @@ -0,0 +1,17 @@ +@safe unittest +{ + struct CustomString + { + @safe: + string _impl; + @property bool empty() const { return !_impl.length; } + } + + CustomString find(CustomString a, CustomString b) + { + return CustomString.init; + } + + auto r = find(CustomString("a"), CustomString("b")); + assert(r.empty); +} diff --git a/gcc/testsuite/gdc.dg/pr96157c.d b/gcc/testsuite/gdc.dg/pr96157c.d new file mode 100644 index 00000000000..8f48cbdc1b4 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr96157c.d @@ -0,0 +1,40 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96157 +// { dg-options "-fno-moduleinfo -fno-rtti" } +// { dg-do compile } + +struct CodepointSet +{ + CowArray!string data; +} + +struct CowArray(SP) +{ + ~this() + { + if (data.length) + refCount; + } + @property refCount() { return data[$-1]; } + + uint[] data; +} + +int ucmp() { return 1; } + +bool loadProperty () { + + CodepointSet target; + if (ucmp) + CodepointSet(); + else if (ucmp|| ucmp) + target = CodepointSet(); + else if (ucmp|| ucmp) + target = CodepointSet(); + else if (ucmp|| ucmp) + target = CodepointSet(); + else if (ucmp) + target = CodepointSet(); + else if (ucmp) + target = CodepointSet(); + return true; +} diff --git a/gcc/testsuite/gdc.dg/pr96869.d b/gcc/testsuite/gdc.dg/pr96869.d index c4ace30a546..348da1bcb3d 100644 --- a/gcc/testsuite/gdc.dg/pr96869.d +++ b/gcc/testsuite/gdc.dg/pr96869.d @@ -2,31 +2,31 @@ // { dg-do compile } __vector(float[0]) var01; -// { dg-error "0 byte vector type __vector\\\(float\\\[0\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "0 byte vector type '__vector\\\(float\\\[0\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(float[3]) var02; -// { dg-error "12 byte vector type __vector\\\(float\\\[3\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "12 byte vector type '__vector\\\(float\\\[3\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(float[][4]) var03; -// { dg-error "vector type __vector\\\(float\\\[\\\]\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(float\\\[\\\]\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(float[4][4]) var04; -// { dg-error "vector type __vector\\\(float\\\[4\\\]\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(float\\\[4\\\]\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(float[float][4]) var05; -// { dg-error "vector type __vector\\\(float\\\[float\\\]\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(float\\\[float\\\]\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(float function()[4]) var06; -// { dg-error "vector type __vector\\\(float function\\\(\\\)\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(float function\\\(\\\)\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(float delegate()[4]) var07; -// { dg-error "vector type __vector\\\(float delegate\\\(\\\)\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(float delegate\\\(\\\)\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } enum E { a, b, c } __vector(E[4]) var08; -// { dg-error "vector type __vector\\\(E\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(E\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } struct S { float a; } __vector(S[4]) var09; -// { dg-error "vector type __vector\\\(S\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(S\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } class C { float a; } __vector(C[4]) var10; -// { dg-error "vector type __vector\\\(C\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(C\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(cfloat[4]) var11; -// { dg-error "vector type __vector\\\(cfloat\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(cfloat\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(bool[4]) var12; -// { dg-error "vector type __vector\\\(bool\\\[4\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(bool\\\[4\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } __vector(real[128]) var13; -// { dg-error "vector type __vector\\\(real\\\[128\\\]\\\) is not supported on this platform" "" { target *-*-* } .-1 } +// { dg-error "vector type '__vector\\\(real\\\[128\\\]\\\)' is not supported on this platform" "" { target *-*-* } .-1 } diff --git a/gcc/testsuite/gdc.dg/pr98277.d b/gcc/testsuite/gdc.dg/pr98277.d index d3b859fcbda..0dff142a6ef 100644 --- a/gcc/testsuite/gdc.dg/pr98277.d +++ b/gcc/testsuite/gdc.dg/pr98277.d @@ -7,7 +7,7 @@ enum Side right } -ref int getSide(Side side, ref int left, ref int right) +ref int getSide(Side side, return ref int left, return ref int right) { return side == Side.left ? left : right; } diff --git a/gcc/testsuite/gdc.dg/pr98457.d b/gcc/testsuite/gdc.dg/pr98457.d index bc0d8af5d4a..0cc83aca064 100644 --- a/gcc/testsuite/gdc.dg/pr98457.d +++ b/gcc/testsuite/gdc.dg/pr98457.d @@ -3,7 +3,7 @@ void main() { - writef!"%s"; // { dg-error "template instance writef!\"%s\" template .writef. is not defined" } - writef!"`%s"; // { dg-error "template instance writef!\"`%s\" template .writef. is not defined" } - writef!"%%s`"; // { dg-error "template instance writef!\"%%s`\" template .writef. is not defined" } + writef!"%s"; // { dg-error "template instance .writef!\"%s\". template .writef. is not defined" } + writef!"`%s"; // { dg-error "template instance .writef!\"`%s\". template .writef. is not defined" } + writef!"%%s`"; // { dg-error "template instance .writef!\"%%s`\". template .writef. is not defined" } } diff --git a/gcc/testsuite/gdc.dg/simd1.d b/gcc/testsuite/gdc.dg/simd1.d index 374dcae5e94..b25b99e3e1d 100644 --- a/gcc/testsuite/gdc.dg/simd1.d +++ b/gcc/testsuite/gdc.dg/simd1.d @@ -26,14 +26,6 @@ void test1() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); diff --git a/gcc/testsuite/gdc.dg/simd2a.d b/gcc/testsuite/gdc.dg/simd2a.d index b630a473b18..0fb391cc057 100644 --- a/gcc/testsuite/gdc.dg/simd2a.d +++ b/gcc/testsuite/gdc.dg/simd2a.d @@ -24,14 +24,6 @@ void test2a() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2b.d b/gcc/testsuite/gdc.dg/simd2b.d index 35c42880ce2..41a4eb3c34a 100644 --- a/gcc/testsuite/gdc.dg/simd2b.d +++ b/gcc/testsuite/gdc.dg/simd2b.d @@ -24,14 +24,6 @@ void test2b() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2c.d b/gcc/testsuite/gdc.dg/simd2c.d index 2f19e75a35b..a9957094998 100644 --- a/gcc/testsuite/gdc.dg/simd2c.d +++ b/gcc/testsuite/gdc.dg/simd2c.d @@ -24,14 +24,6 @@ void test2c() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2d.d b/gcc/testsuite/gdc.dg/simd2d.d index 9d378e4cdba..d578734368e 100644 --- a/gcc/testsuite/gdc.dg/simd2d.d +++ b/gcc/testsuite/gdc.dg/simd2d.d @@ -24,14 +24,6 @@ void test2d() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2e.d b/gcc/testsuite/gdc.dg/simd2e.d index 30d7c1aa165..d33574ad005 100644 --- a/gcc/testsuite/gdc.dg/simd2e.d +++ b/gcc/testsuite/gdc.dg/simd2e.d @@ -24,14 +24,6 @@ void test2e() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2f.d b/gcc/testsuite/gdc.dg/simd2f.d index f8448801dba..5845249e693 100644 --- a/gcc/testsuite/gdc.dg/simd2f.d +++ b/gcc/testsuite/gdc.dg/simd2f.d @@ -24,14 +24,6 @@ void test2f() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2g.d b/gcc/testsuite/gdc.dg/simd2g.d index 8e8bc15623c..ce438f2c3db 100644 --- a/gcc/testsuite/gdc.dg/simd2g.d +++ b/gcc/testsuite/gdc.dg/simd2g.d @@ -24,14 +24,6 @@ void test2g() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2h.d b/gcc/testsuite/gdc.dg/simd2h.d index f7542e83b8c..c631c760ffb 100644 --- a/gcc/testsuite/gdc.dg/simd2h.d +++ b/gcc/testsuite/gdc.dg/simd2h.d @@ -24,14 +24,6 @@ void test2h() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); v1 = v2 << 1; v1 = v2 >> 1; v1 = v2 >>> 1; diff --git a/gcc/testsuite/gdc.dg/simd2i.d b/gcc/testsuite/gdc.dg/simd2i.d index 2e3587dce77..6946c79987a 100644 --- a/gcc/testsuite/gdc.dg/simd2i.d +++ b/gcc/testsuite/gdc.dg/simd2i.d @@ -24,14 +24,6 @@ void test2i() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); diff --git a/gcc/testsuite/gdc.dg/simd2j.d b/gcc/testsuite/gdc.dg/simd2j.d index 7b607848580..ecfdbf3bbc1 100644 --- a/gcc/testsuite/gdc.dg/simd2j.d +++ b/gcc/testsuite/gdc.dg/simd2j.d @@ -24,14 +24,6 @@ void test2j() static assert(!__traits(compiles, v1 > v2)); static assert(!__traits(compiles, v1 <= v2)); static assert(!__traits(compiles, v1 >= v2)); - static assert(!__traits(compiles, v1 <> v2)); - static assert(!__traits(compiles, v1 !< v2)); - static assert(!__traits(compiles, v1 !> v2)); - static assert(!__traits(compiles, v1 !<> v2)); - static assert(!__traits(compiles, v1 <>= v2)); - static assert(!__traits(compiles, v1 !<= v2)); - static assert(!__traits(compiles, v1 !>= v2)); - static assert(!__traits(compiles, v1 !<>= v2)); static assert(!__traits(compiles, v1 << 1)); static assert(!__traits(compiles, v1 >> 1)); static assert(!__traits(compiles, v1 >>> 1)); diff --git a/gcc/testsuite/gdc.dg/simd7951.d b/gcc/testsuite/gdc.dg/simd7951.d index 99ce1510f8f..4e467ef0f96 100644 --- a/gcc/testsuite/gdc.dg/simd7951.d +++ b/gcc/testsuite/gdc.dg/simd7951.d @@ -19,4 +19,5 @@ void test7951_2() f1.array = v1; f2.array = v2; f3 = f1 + f2; + assert((cast(float[4])f3)[2] == 6); } diff --git a/gcc/testsuite/gdc.dg/simd_ctfe.d b/gcc/testsuite/gdc.dg/simd_ctfe.d new file mode 100644 index 00000000000..b254cf312cb --- /dev/null +++ b/gcc/testsuite/gdc.dg/simd_ctfe.d @@ -0,0 +1,87 @@ +// { dg-do compile } +import core.simd; + +// https://issues.dlang.org/show_bug.cgi?id=19627 +enum int[4] fail19627 = cast(int[4])int4(0); + +// https://issues.dlang.org/show_bug.cgi?id=19628 +enum ice19628a = int4.init[0]; +enum ice19628b = int4.init.array[0]; +enum ice19628c = (cast(int[4])int4.init.array)[0]; +enum ice19628d = (cast(int[4])int4.init)[0]; + +// https://issues.dlang.org/show_bug.cgi?id=19629 +enum fail19629a = int4(0)[0]; +enum fail19629b = int4(0).array[0]; +enum fail19629c = (cast(int[4])int4(0).array)[0]; +enum fail19628d = (cast(int[4])int4(0))[0]; + +// https://issues.dlang.org/show_bug.cgi?id=19630 +enum fail19630a = int4.init[1..2]; +enum fail19630b = int4.init.array[1..2]; +enum fail19630c = (cast(int[4])int4.init.array)[1..2]; +enum fail19630d = int4(0)[1..2]; +enum fail19630e = int4(0).array[1..2]; +enum fail19630f = (cast(int[4])int4(0).array)[1..2]; +enum fail19630g = (cast(int[4])int4.init)[1..2]; +enum fail19630h = (cast(int[4])int4(0))[1..2]; + +// Same tests as above, but use access via enum. +enum int4 V1 = int4.init; +enum int[4] V2 = int4.init.array; +enum int[4] V3 = cast(int[4])int4.init; +enum int[4] V4 = cast(int[4])int4.init.array; +enum int4 V5 = int4(0); +enum int[4] V6 = int4(0).array; +enum int[4] V7 = cast(int[4])int4(0); +enum int[4] V8 = cast(int[4])int4(0).array; + +// CTFE index tests +enum I1 = V1[0]; static assert(I1 == 0); +enum I2 = V2[0]; static assert(I2 == 0); +enum I3 = V3[0]; static assert(I3 == 0); +enum I4 = V4[0]; static assert(I4 == 0); +enum I5 = V5[0]; static assert(I5 == 0); +enum I6 = V6[0]; static assert(I6 == 0); +enum I7 = V7[0]; static assert(I7 == 0); +enum I8 = V8[0]; static assert(I8 == 0); + +// CTFE slice tests +enum S1 = V1[1..2]; static assert(S1 == [0]); +enum S2 = V2[1..2]; static assert(S2 == [0]); +enum S3 = V3[1..2]; static assert(S3 == [0]); +enum S4 = V4[1..2]; static assert(S4 == [0]); +enum S5 = V5[1..2]; static assert(S5 == [0]); +enum S6 = V6[1..2]; static assert(S6 == [0]); +enum S7 = V7[1..2]; static assert(S7 == [0]); +enum S8 = V8[1..2]; static assert(S8 == [0]); + +// Same tests as above, but use access via immutable. +//immutable int4 v1 = int4.init; // Cannot cast to immutable at compile time +immutable int[4] v2 = int4.init.array; +immutable int[4] v3 = cast(int[4])int4.init; +immutable int[4] v4 = cast(int[4])int4.init.array; +//immutable int4 v5 = int4(0); // Cannot cast to immutable at compile time +immutable int[4] v6 = int4(0).array; +immutable int[4] v7 = cast(int[4])int4(0); +immutable int[4] v8 = cast(int[4])int4(0).array; + +// CTFE index tests +//immutable i1 = v1[0]; static assert(i1 == 0); +immutable i2 = v2[0]; static assert(i2 == 0); +immutable i3 = v3[0]; static assert(i3 == 0); +immutable i4 = v4[0]; static assert(i4 == 0); +//immutable i5 = v5[0]; static assert(i5 == 0); +immutable i6 = v6[0]; static assert(i6 == 0); +immutable i7 = v7[0]; static assert(i7 == 0); +immutable i8 = v8[0]; static assert(i8 == 0); + +// CTFE slice tests +//immutable s1 = v1[1..2]; static assert(s1 == [0]); +immutable s2 = v2[1..2]; static assert(s2 == [0]); +immutable s3 = v3[1..2]; static assert(s3 == [0]); +immutable s4 = v4[1..2]; static assert(s4 == [0]); +//immutable s5 = v5[1..2]; static assert(s5 == [0]); +immutable s6 = v6[1..2]; static assert(s6 == [0]); +immutable s7 = v7[1..2]; static assert(s7 == [0]); +immutable s8 = v8[1..2]; static assert(s8 == [0]); diff --git a/gcc/testsuite/gdc.dg/torture/gdc309.d b/gcc/testsuite/gdc.dg/torture/gdc309.d index d14634a2f1f..acda2bb8f5a 100644 --- a/gcc/testsuite/gdc.dg/torture/gdc309.d +++ b/gcc/testsuite/gdc.dg/torture/gdc309.d @@ -1,4 +1,5 @@ // https://bugzilla.gdcproject.org/show_bug.cgi?id=309 +// { dg-additional-options "-Wno-deprecated" } // { dg-do run } // { dg-skip-if "needs gcc/config.d" { ! d_runtime } } diff --git a/gcc/testsuite/gdc.dg/torture/pr94424.d b/gcc/testsuite/gdc.dg/torture/pr94424.d index 2910c9ae139..dc30639ab2a 100644 --- a/gcc/testsuite/gdc.dg/torture/pr94424.d +++ b/gcc/testsuite/gdc.dg/torture/pr94424.d @@ -17,3 +17,19 @@ assert(__cmp([c2, c2], [c1, c1]) > 0); assert(__cmp([c2, c2], [c2, c1]) > 0); } + +@safe unittest +{ + struct C + { + char i; + this(char i) { this.i = i; } + } + + auto c1 = C(1); + auto c2 = C(2); + + assert(__cmp([c1, c1][], [c2, c2][]) < 0); + assert(__cmp([c2, c2], [c1, c1]) > 0); + assert(__cmp([c2, c2], [c2, c1]) > 0); +} diff --git a/gcc/testsuite/gdc.dg/torture/pr94777b.d b/gcc/testsuite/gdc.dg/torture/pr94777b.d index 2f0f9d9affb..e9da63fdc9d 100644 --- a/gcc/testsuite/gdc.dg/torture/pr94777b.d +++ b/gcc/testsuite/gdc.dg/torture/pr94777b.d @@ -27,42 +27,6 @@ void testVariadic(T)(int nargs, ...) /******************************************/ -struct Constructor -{ - static int count; - int value; - this(int v) { count++; this.value = v; } -} - -unittest -{ - auto a0 = Constructor(0); - auto a1 = Constructor(1); - auto a2 = Constructor(2); - testVariadic!Constructor(3, a0, a1, a2); - assert(Constructor.count == 3); -} - -/******************************************/ - -struct Postblit -{ - static int count = 0; - int value; - this(this) { count++; } -} - -unittest -{ - auto a0 = Postblit(0); - auto a1 = Postblit(1); - auto a2 = Postblit(2); - testVariadic!Postblit(3, a0, a1, a2); - assert(Postblit.count == 3); -} - -/******************************************/ - struct Destructor { static int count = 0; @@ -80,102 +44,3 @@ unittest } assert(Destructor.count == 3); } - -/******************************************/ - -struct CopyConstructor -{ - static int count = 0; - int value; - this(int v) { this.value = v; } - this(ref typeof(this) other) { count++; this.value = other.value; } -} - -unittest -{ - auto a0 = CopyConstructor(0); - auto a1 = CopyConstructor(1); - auto a2 = CopyConstructor(2); - testVariadic!CopyConstructor(3, a0, a1, a2); - // NOTE: Cpctors are not implemented yet. - assert(CopyConstructor.count == 0 || CopyConstructor.count == 3); -} - -/******************************************/ - -unittest -{ - struct Nested - { - int value; - } - - auto a0 = Nested(0); - auto a1 = Nested(1); - auto a2 = Nested(2); - testVariadic!Nested(3, a0, a1, a2); -} - -/******************************************/ - -unittest -{ - struct Nested2 - { - int value; - } - - void testVariadic2(int nargs, ...) - { - import core.stdc.stdarg; - foreach(i; 0 .. nargs) - { - auto arg = va_arg!Nested2(_argptr); - assert(arg.value == i); - } - } - - auto a0 = Nested2(0); - auto a1 = Nested2(1); - auto a2 = Nested2(2); - testVariadic2(3, a0, a1, a2); -} - -/******************************************/ - -struct EmptyStruct -{ -} - -unittest -{ - auto a0 = EmptyStruct(); - auto a1 = EmptyStruct(); - auto a2 = EmptyStruct(); - testVariadic!EmptyStruct(3, a0, a1, a2); -} - -/******************************************/ - -alias StaticArray = int[4]; - -unittest -{ - StaticArray a0 = 0; - StaticArray a1 = 1; - StaticArray a2 = 2; - // XBUG: Front-end rewrites static arrays as dynamic arrays. - //testVariadic!StaticArray(3, a0, a1, a2); -} - -/******************************************/ - -alias EmptyArray = void[0]; - -unittest -{ - auto a0 = EmptyArray.init; - auto a1 = EmptyArray.init; - auto a2 = EmptyArray.init; - testVariadic!EmptyArray(3, a0, a1, a2); -} diff --git a/gcc/testsuite/gdc.dg/torture/simd17344.d b/gcc/testsuite/gdc.dg/torture/simd17344.d new file mode 100644 index 00000000000..fd5ffbe8a3a --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd17344.d @@ -0,0 +1,11 @@ +// https://issues.dlang.org/show_bug.cgi?id=17344 +// { dg-additional-options "-mavx" { target avx_runtime } } +// { dg-do run { target { avx_runtime || vect_sizes_16B_8B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } + +void main() +{ + __vector(int[4]) vec1 = 2, vec2 = vec1++; + assert(cast(int[4])vec1 == [3, 3, 3, 3]); + assert(cast(int[4])vec2 == [2, 2, 2, 2]); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd20052.d b/gcc/testsuite/gdc.dg/torture/simd20052.d new file mode 100644 index 00000000000..4587351a851 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd20052.d @@ -0,0 +1,17 @@ +// { dg-additional-options "-mavx2" { target avx2_runtime } } +// { dg-do run { target { avx2_runtime || vect_sizes_32B_16B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +auto test20052() +{ + struct S { long4 v; } + S s; + return s; +} + +void main() +{ + test20052(); +} + diff --git a/gcc/testsuite/gdc.dg/torture/simd6.d b/gcc/testsuite/gdc.dg/torture/simd6.d new file mode 100644 index 00000000000..d8de02edf72 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd6.d @@ -0,0 +1,26 @@ +// { dg-additional-options "-mavx2" { target avx2_runtime } } +// { dg-do run { target { avx2_runtime || vect_sizes_32B_16B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +void test6a() +{ + // stack occasionally misaligned + float f = 0; + long4 v; + assert((cast(size_t)&v) % 32 == 0); + v += 1; +} + +void test6b() +{ + struct S {long4 v;} + S s; + assert((cast(size_t)&s) % 32 == 0); +} + +void main() +{ + test6a(); + test6b(); +} diff --git a/gcc/testsuite/gdc.dg/torture/simd7.d b/gcc/testsuite/gdc.dg/torture/simd7.d new file mode 100644 index 00000000000..6e890defca7 --- /dev/null +++ b/gcc/testsuite/gdc.dg/torture/simd7.d @@ -0,0 +1,18 @@ +// { dg-additional-options "-mavx2" { target avx2_runtime } } +// { dg-do run { target { avx2_runtime || vect_sizes_32B_16B } } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } +import core.simd; + +double4 test7r(double4 v) +{ + return v; +} + +void main() +{ + // 32 bytes sliced down to 16 bytes + double4 v = 1; + double4 r = test7r(v); + assert(v[2] == r[2]); + assert(v[3] == r[3]); +} diff --git a/gcc/testsuite/lib/gdc-utils.exp b/gcc/testsuite/lib/gdc-utils.exp index 33c01450eb4..b3da7889bc0 100644 --- a/gcc/testsuite/lib/gdc-utils.exp +++ b/gcc/testsuite/lib/gdc-utils.exp @@ -35,6 +35,15 @@ proc gdc-convert-args { args } { set compilable_output_file_ext "di" lappend out "-H" + } elseif [string match "-HC" $arg] { + upvar 1 compilable_output_file_ext compilable_output_file_ext + upvar 1 name name + set compilable_output_file_ext "h" + lappend out "-fdump-c++-spec=[file rootname $name].h" + + } elseif [string match "-HC=verbose" $arg] { + lappend out "-fdump-c++-spec-verbose" + } elseif { [regexp -- {^-I([\w+/-]+)} $arg pattern path] } { lappend out "-I$path" @@ -54,11 +63,11 @@ proc gdc-convert-args { args } { } elseif { [string match "-boundscheck" $arg] || [string match "-boundscheck=on" $arg] } { - lappend out "-fbounds-check" + lappend out "-fbounds-check=on" } elseif { [string match "-boundscheck=off" $arg] || [string match "-noboundscheck" $arg] } { - lappend out "-fno-bounds-check" + lappend out "-fbounds-check=off" } elseif [string match "-boundscheck=safeonly" $arg] { lappend out "-fbounds-check=safeonly" @@ -66,6 +75,12 @@ proc gdc-convert-args { args } { } elseif [string match "-c" $arg] { lappend out "-c" + } elseif [regexp -- {^-check=(\w+)=off} $arg pattern value] { + lappend out "-fno-check=$value" + + } elseif [string match "-checkaction=context" $arg] { + lappend out "-fcheckaction=context" + } elseif [string match "-d" $arg] { lappend out "-Wno-deprecated" @@ -79,23 +94,35 @@ proc gdc-convert-args { args } { } elseif [regexp -- {^-debug=(\w+)} $arg pattern value] { lappend out "-fdebug=$value" + } elseif [string match "-dip25" $arg] { + lappend out "-fpreview=dip25" + } elseif [string match "-dip1000" $arg] { - lappend out "-ftransition=dip1000" + lappend out "-fpreview=dip1000" - } elseif [string match "-dip25" $arg] { - lappend out "-ftransition=dip25" + } elseif [string match "-dip1008" $arg] { + lappend out "-fpreview=dip1008" } elseif [string match "-dw" $arg] { lappend out "-Wdeprecated" lappend out "-Wno-error" + } elseif [regexp -- {^-extern-std=([\w+]+)} $arg pattern value] { + lappend out "-fextern-std=$value" + } elseif [string match "-fPIC" $arg] { lappend out "-fPIC" + } elseif [string match "-fPIE" $arg] { + lappend out "-fPIE" + } elseif { [string match "-g" $arg] || [string match "-gc" $arg] } { lappend out "-g" + } elseif [string match "-ignore" $arg] { + lappend out "-fignore-unknown-pragmas" + } elseif [string match "-inline" $arg] { lappend out "-finline-functions" @@ -108,11 +135,17 @@ proc gdc-convert-args { args } { } elseif [string match "-O" $arg] { lappend out "-O2" + } elseif [regexp -- {^-preview=(\w+)} $arg pattern value] { + lappend out "-fpreview=[string tolower $value]" + } elseif [string match "-release" $arg] { lappend out "-frelease" + } elseif [regexp -- {^-revert=(\w+)} $arg pattern value] { + lappend out "-frevert=[string tolower $value]" + } elseif [regexp -- {^-transition=(\w+)} $arg pattern value] { - lappend out "-ftransition=$value" + lappend out "-ftransition=[string tolower $value]" } elseif [string match "-unittest" $arg] { lappend out "-funittest" @@ -126,6 +159,16 @@ proc gdc-convert-args { args } { } elseif [regexp -- {^-version=(\w+)} $arg pattern value] { lappend out "-fversion=$value" + } elseif [string match "-o-" $arg] { + upvar 2 compilable_do_what compilable_do_what + set compilable_do_what "compile" + + } elseif [string match "-vgc" $arg] { + lappend out "-ftransition=nogc" + + } elseif [string match "-vtemplates" $arg] { + lappend out "-ftransition=templates" + } elseif [string match "-vtls" $arg] { lappend out "-ftransition=tls" @@ -184,10 +227,15 @@ proc gdc-copy-file { srcdir filename } { # the test. # EXTRA_CPP_SOURCES: List of extra C++ files to build and link along with # the test. +# CXXFLAGS: list of extra arguments passed when compiling C++ +# sources defined in EXTRA_CPP_SOURCES. +# EXTRA_OBJC_SOURCES: List of extra Objective-C file to build and link along +# with the test. Currently not handled. # EXTRA_FILES: List of extra files to copy for the test runs. # PERMUTE_ARGS: The set of arguments to permute in multiple compiler # invocations. An empty set means only one permutation # with no arguments. +# ARG_SETS: Not handled. # LINK: Enables linking. # TEST_OUTPUT: The output expected from the compilation. # POST_SCRIPT: Not handled. @@ -241,6 +289,10 @@ proc gdc-convert-test { base test } { # LINK sets dg-do-what-default "link" set compilable_do_what "link" + } elseif [regexp -- {ARG_SETS} $copy_line] { + # ARG_SETS is not handled. + regsub -- {ARG_SETS.*$} $copy_line "" out_line + } elseif [regexp -- {POST_SCRIPT} $copy_line] { # POST_SCRIPT is not handled @@ -279,6 +331,16 @@ proc gdc-convert-test { base test } { lappend extra_sources "extra-files/$srcfile" } + } elseif [regexp -- {CXXFLAGS\s*:\s*(.*)} $copy_line match args] { + # Both C++ and D sources are compiled together, so include each + # other's command line flags too. + set new_option "{ dg-additional-options \"$args\" }" + regsub -- {CXXFLAGS.*$} $copy_line $new_option out_line + + } elseif [regexp -- {EXTRA_OBJC_SOURCES\s*:\s*(.*)} $copy_line match sources] { + # EXTRA_OBJC_SOURCES is not handled. + regsub -- {EXTRA_OBJC_SOURCES.*$} $copy_line "" out_line + } elseif [regexp -- {EXTRA_FILES\s*:\s*(.*)} $copy_line match files] { # EXTRA_FILES are appended to extra_files list foreach file $files { @@ -365,6 +427,11 @@ proc gdc-convert-test { base test } { } fail_compilation { + # Fail compilation tests only check for language errors from the + # front-end. No need to run all permutations of the default DFLAGS. + if { $PERMUTE_ARGS == $DEFAULT_DFLAGS } { + set PERMUTE_ARGS "" + } puts $fdout "// { dg-final { output-exists-not } }" } } @@ -434,7 +501,7 @@ proc gdc-do-test { testcases } { regexp -- "(.*)/(.+)/(.+)\.(.+)$" $test match base type name ext # Convert to DG test. - set imports [format "-I%s/%s" $base $type] + set imports [format "-I%s" $type] set cleanup_extra_files "" set compilable_do_what "compile" set filename "[gdc-convert-test $base $type/$name.$ext]" From patchwork Tue Nov 30 15:24:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Buclaw X-Patchwork-Id: 48299 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B9181385BF83 for ; Tue, 30 Nov 2021 15:24:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B9181385BF83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638285898; bh=xLZPS6okYryqcM44Gfw/0OiebDkrnNF1Pyn+P1ZhSAQ=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=iseiLXzHVkwQfJ3/FvBlsMqVUYUFgknLPYuclOIUWwvX7fEyjQCAq6p+znm0zSN2+ IKSppIIx3sxPYxLkpLdfb/MmjLv8Rvq560makT/nAynt/oD5W8r/5j7+MrEV3eWZDe faXukjtu/MUGIWSdyNBzvpTE/mIf1OlOlTdoykL4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) by sourceware.org (Postfix) with ESMTPS id 117BA3858D28 for ; Tue, 30 Nov 2021 15:24:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 117BA3858D28 Received: from smtp202.mailbox.org (smtp202.mailbox.org [80.241.60.245]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4J3QxP1NvvzQk4J; Tue, 30 Nov 2021 16:24:25 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de To: gcc-patches@gcc.gnu.org Subject: [committed 19/19] libphobos: Update libphobos testsuite to pass on latest version Date: Tue, 30 Nov 2021 16:24:17 +0100 Message-Id: <20211130152417.740788-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Iain Buclaw via Gcc-patches From: Iain Buclaw Reply-To: Iain Buclaw Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This adds new, or updates the dejagu testing scripts for the suite of libphobos tests. Bootstrapped, regression tested, and committed to mainline. Regards, Iain. --- libphobos/ChangeLog: * testsuite/lib/libphobos.exp (libphobos-dg-test): Handle assembly compile types. (dg-test): Override. (additional_prunes): Define. (libphobos-dg-prune): Filter any additional_prunes set by tests. * testsuite/libphobos.druntime/druntime.exp (version_flags): Add -fversion=CoreUnittest. * testsuite/libphobos.druntime_shared/druntime_shared.exp (version_flags): Add -fversion=CoreUnittest -fversion=Shared. * testsuite/libphobos.phobos/phobos.exp (version_flags): Add -fversion=StdUnittest * testsuite/libphobos.phobos_shared/phobos_shared.exp (version_flags): Likewise. * testsuite/testsuite_flags.in: Add -fpreview=dip1000 to --gdcflags. * testsuite/libphobos.betterc/betterc.exp: New test. * testsuite/libphobos.config/config.exp: New test. * testsuite/libphobos.gc/gc.exp: New test. * testsuite/libphobos.imports/imports.exp: New test. * testsuite/libphobos.lifetime/lifetime.exp: New test. * testsuite/libphobos.unittest/unittest.exp: New test. --- libphobos/testsuite/lib/libphobos.exp | 60 +++++++++++++++++++ .../testsuite/libphobos.betterc/betterc.exp | 27 +++++++++ .../testsuite/libphobos.config/config.exp | 46 ++++++++++++++ .../testsuite/libphobos.druntime/druntime.exp | 2 +- .../druntime_shared.exp | 2 +- libphobos/testsuite/libphobos.gc/gc.exp | 27 +++++++++ .../testsuite/libphobos.imports/imports.exp | 29 +++++++++ .../testsuite/libphobos.lifetime/lifetime.exp | 27 +++++++++ .../testsuite/libphobos.phobos/phobos.exp | 2 +- .../libphobos.phobos_shared/phobos_shared.exp | 2 +- .../testsuite/libphobos.unittest/unittest.exp | 53 ++++++++++++++++ libphobos/testsuite/testsuite_flags.in | 2 +- 12 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 libphobos/testsuite/libphobos.betterc/betterc.exp create mode 100644 libphobos/testsuite/libphobos.config/config.exp create mode 100644 libphobos/testsuite/libphobos.gc/gc.exp create mode 100644 libphobos/testsuite/libphobos.imports/imports.exp create mode 100644 libphobos/testsuite/libphobos.lifetime/lifetime.exp create mode 100644 libphobos/testsuite/libphobos.unittest/unittest.exp diff --git a/libphobos/testsuite/lib/libphobos.exp b/libphobos/testsuite/lib/libphobos.exp index 2af430a0e45..66e3e80105f 100644 --- a/libphobos/testsuite/lib/libphobos.exp +++ b/libphobos/testsuite/lib/libphobos.exp @@ -54,6 +54,10 @@ proc libphobos-dg-test { prog do_what extra_tool_flags } { # Set up the compiler flags, based on what we're going to do. switch $do_what { + "compile" { + set compile_type "assembly" + set output_file "[file rootname [file tail $prog]].s" + } "run" { set compile_type "executable" # FIXME: "./" is to cope with "." not being in $PATH. @@ -89,8 +93,52 @@ proc libphobos-dg-test { prog do_what extra_tool_flags } { return [list $comp_output $output_file] } +# Override the DejaGnu dg-test in order to clear flags after a test, as +# is done for compiler tests in gcc-dg.exp. + +if { [info procs saved-dg-test] == [list] } { + rename dg-test saved-dg-test + + proc dg-test { args } { + global additional_prunes + global errorInfo + global testname_with_flags + global shouldfail + + if { [ catch { eval saved-dg-test $args } errmsg ] } { + set saved_info $errorInfo + set additional_prunes "" + set shouldfail 0 + if [info exists testname_with_flags] { + unset testname_with_flags + } + unset_timeout_vars + error $errmsg $saved_info + } + set additional_prunes "" + set shouldfail 0 + unset_timeout_vars + if [info exists testname_with_flags] { + unset testname_with_flags + } + } +} + +# Prune messages from gdc that aren't useful. + +set additional_prunes "" + proc libphobos-dg-prune { system text } { + global additional_prunes + + foreach p $additional_prunes { + if { [string length $p] > 0 } { + # Following regexp matches a complete line containing $p. + regsub -all "(^|\n)\[^\n\]*$p\[^\n\]*" $text "" text + } + } + # Ignore harmless warnings from Xcode. regsub -all "(^|\n)\[^\n\]*ld: warning: could not create compact unwind for\[^\n\]*" $text "" text @@ -281,6 +329,18 @@ proc libphobos_skipped_test_p { test } { return "skipped test" } +# Prune any messages matching ARGS[1] (a regexp) from test output. +proc dg-prune-output { args } { + global additional_prunes + + if { [llength $args] != 2 } { + error "[lindex $args 1]: need one argument" + return + } + + lappend additional_prunes [lindex $args 1] +} + # Return true if the curl library is supported on the target. proc check_effective_target_libcurl_available { } { return [check_no_compiler_messages libcurl_available executable { diff --git a/libphobos/testsuite/libphobos.betterc/betterc.exp b/libphobos/testsuite/libphobos.betterc/betterc.exp new file mode 100644 index 00000000000..e5e9b84829d --- /dev/null +++ b/libphobos/testsuite/libphobos.betterc/betterc.exp @@ -0,0 +1,27 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Initialize dg. +dg-init + +# Gather a list of all tests. +set tests [lsort [find $srcdir/$subdir *.d]] + +# Main loop. +dg-runtest $tests "-fno-druntime" $DEFAULT_DFLAGS + +# All done. +dg-finish diff --git a/libphobos/testsuite/libphobos.config/config.exp b/libphobos/testsuite/libphobos.config/config.exp new file mode 100644 index 00000000000..e8f4d943ff3 --- /dev/null +++ b/libphobos/testsuite/libphobos.config/config.exp @@ -0,0 +1,46 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +load_lib libphobos-dg.exp + +set dg-output-text [list] + +# Test, arguments to pass to the test program, and return code. +set config_test_list [list \ + { test19433 "--DRT-dont-eat-me" 0 } \ + { test20459 "foo bar -- --DRT-gcopts=profile:1" 0 } \ +] + +# Initialize dg. +dg-init + +# Main loop. +foreach config_test $config_test_list { + set test "$srcdir/$subdir/[lindex $config_test 0].d" + + set libphobos_run_args "[lindex $config_test 1]" + set shouldfail [lindex $config_test 2] + set libphobos_test_name "[dg-trim-dirname $srcdir $test] $libphobos_run_args" + + dg-runtest $test "" $DEFAULT_DFLAGS + + set libphobos_test_name "" + set shouldfail 0 + set libphobos_run_args "" +} + +# All done. +dg-finish diff --git a/libphobos/testsuite/libphobos.druntime/druntime.exp b/libphobos/testsuite/libphobos.druntime/druntime.exp index daedfd71ebb..5342d45386f 100644 --- a/libphobos/testsuite/libphobos.druntime/druntime.exp +++ b/libphobos/testsuite/libphobos.druntime/druntime.exp @@ -22,7 +22,7 @@ if { ![isnative] } { # Gather a list of all tests. set tests [lsort [filter_libphobos_unittests [find $srcdir/../libdruntime "*.d"]]] -set version_flags "" +set version_flags "-fversion=CoreUnittest" if { [is-effective-target linux_pre_2639] } { lappend version_flags "-fversion=Linux_Pre_2639" diff --git a/libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp b/libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp index 51f9c2cf1d6..67edab95cff 100644 --- a/libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp +++ b/libphobos/testsuite/libphobos.druntime_shared/druntime_shared.exp @@ -22,7 +22,7 @@ if { ![isnative] || ![is-effective-target shared] } { # Gather a list of all tests. set tests [lsort [filter_libphobos_unittests [find $srcdir/../libdruntime "*.d"]]] -set version_flags "" +set version_flags "-fversion=CoreUnittest -fversion=Shared" if { [is-effective-target linux_pre_2639] } { lappend version_flags "-fversion=Linux_Pre_2639" diff --git a/libphobos/testsuite/libphobos.gc/gc.exp b/libphobos/testsuite/libphobos.gc/gc.exp new file mode 100644 index 00000000000..cb785382f51 --- /dev/null +++ b/libphobos/testsuite/libphobos.gc/gc.exp @@ -0,0 +1,27 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Initialize dg. +dg-init + +# Gather a list of all tests. +set tests [lsort [find $srcdir/$subdir *.d]] + +# Main loop. +dg-runtest $tests "" $DEFAULT_DFLAGS + +# All done. +dg-finish diff --git a/libphobos/testsuite/libphobos.imports/imports.exp b/libphobos/testsuite/libphobos.imports/imports.exp new file mode 100644 index 00000000000..344e415fa53 --- /dev/null +++ b/libphobos/testsuite/libphobos.imports/imports.exp @@ -0,0 +1,29 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +load_lib libphobos-dg.exp + +# Initialize dg. +dg-init + +# Gather a list of all tests. +set tests [lsort [find $srcdir/$subdir *.d]] + +# Main loop. +dg-runtest $tests "" $DEFAULT_DFLAGS + +# All done. +dg-finish diff --git a/libphobos/testsuite/libphobos.lifetime/lifetime.exp b/libphobos/testsuite/libphobos.lifetime/lifetime.exp new file mode 100644 index 00000000000..cb785382f51 --- /dev/null +++ b/libphobos/testsuite/libphobos.lifetime/lifetime.exp @@ -0,0 +1,27 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +# Initialize dg. +dg-init + +# Gather a list of all tests. +set tests [lsort [find $srcdir/$subdir *.d]] + +# Main loop. +dg-runtest $tests "" $DEFAULT_DFLAGS + +# All done. +dg-finish diff --git a/libphobos/testsuite/libphobos.phobos/phobos.exp b/libphobos/testsuite/libphobos.phobos/phobos.exp index 937849eebd7..84e989837fe 100644 --- a/libphobos/testsuite/libphobos.phobos/phobos.exp +++ b/libphobos/testsuite/libphobos.phobos/phobos.exp @@ -27,7 +27,7 @@ if { ![is-effective-target d_runtime_has_std_library] } { # Gather a list of all tests. set tests [lsort [filter_libphobos_unittests [find $srcdir/../src "*.d"]]] -set version_flags "" +set version_flags "-fversion=StdUnittest" if { [is-effective-target linux_pre_2639] } { lappend version_flags "-fversion=Linux_Pre_2639" diff --git a/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp b/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp index 8498522d4d4..b8f8e42f612 100644 --- a/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp +++ b/libphobos/testsuite/libphobos.phobos_shared/phobos_shared.exp @@ -27,7 +27,7 @@ if { ![is-effective-target d_runtime_has_std_library] } { # Gather a list of all tests. set tests [lsort [filter_libphobos_unittests [find $srcdir/../src "*.d"]]] -set version_flags "" +set version_flags "-fversion=StdUnittest" if { [is-effective-target linux_pre_2639] } { lappend version_flags "-fversion=Linux_Pre_2639" diff --git a/libphobos/testsuite/libphobos.unittest/unittest.exp b/libphobos/testsuite/libphobos.unittest/unittest.exp new file mode 100644 index 00000000000..ba2fc6e32af --- /dev/null +++ b/libphobos/testsuite/libphobos.unittest/unittest.exp @@ -0,0 +1,53 @@ +# Copyright (C) 2021 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GCC; see the file COPYING3. If not see +# . + +load_lib libphobos-dg.exp + +set dg-output-text [list] + +# Arguments to pass to the compiler, expected output, and return code. +set unit_test_list [list \ + { "-fversion=PassNoPrintout" 0 } \ + { "-fversion=GoodTests" 0 } \ + { "-fversion=FailNoPrintout" 1 } \ + { "-fversion=FailedTests" 1 } \ + { "-fversion=NoTests" 0 } \ +] + +# Initialize dg. +dg-init + +# Gather a list of all tests. +set tests [lsort [find $srcdir/$subdir *.d]] + +# Main loop. +foreach unit_test $unit_test_list { + # The version flags to build the program with. + set test_flags [lindex $unit_test 0] + + # Whether the program is expected to fail. + set expected_fail [lindex $unit_test 1] + + foreach test $tests { + set shouldfail $expected_fail + dg-test $test "" $test_flags + } + + set shouldfail 0 +} + +# All done. +dg-finish diff --git a/libphobos/testsuite/testsuite_flags.in b/libphobos/testsuite/testsuite_flags.in index bafd5ad4502..93bf7cbfba2 100755 --- a/libphobos/testsuite/testsuite_flags.in +++ b/libphobos/testsuite/testsuite_flags.in @@ -29,7 +29,7 @@ case ${query} in --gdcflags) GDCFLAGS_default="-fmessage-length=0 -fno-show-column" GDCFLAGS_config="@WARN_DFLAGS@ @GDCFLAGS@ @CET_DFLAGS@ - @phobos_compiler_shared_flag@ -fno-release -funittest" + @phobos_compiler_shared_flag@ -fpreview=dip1000 -fno-release -funittest" echo ${GDCFLAGS_default} ${GDCFLAGS_config} ;; --gdcpaths)