diff options
author | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-04-26 23:39:32 +0200 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gdcproject.org> | 2020-04-27 02:47:26 +0200 |
commit | 2370bdbb0b29b14401d8508d846c0e01c64d82fc (patch) | |
tree | 43016d247bb7f8fa7a5b397e862e30f29ef07456 /gcc/testsuite | |
parent | f82e3a12955e484b4da7fcca93655a2a2e785e5b (diff) | |
download | gcc-2370bdbb0b29b14401d8508d846c0e01c64d82fc.zip gcc-2370bdbb0b29b14401d8508d846c0e01c64d82fc.tar.gz gcc-2370bdbb0b29b14401d8508d846c0e01c64d82fc.tar.bz2 |
d: Fix ICE in assign_temp, at function.c:984 (PR94777)
Named arguments were being passed around by invisible reference, just
not variadic arguments. There is a need to de-duplicate the routines
that handle declaration/parameter promotion and reference checking.
However for now, the parameter helper functions have just been renamed
to parameter_reference_p and parameter_type, to make it more clear that
it is the Parameter equivalent to declaration_reference_p and
declaration_type.
On writing the tests, a forward-reference bug was discovered on x86_64
during va_list type semantic. This was due to fields not having their
parent set-up correctly.
gcc/d/ChangeLog:
PR d/94777
* d-builtins.cc (build_frontend_type): Set parent for generated
fields of built-in types.
* d-codegen.cc (argument_reference_p): Rename to ...
(parameter_reference_p): ... this.
(type_passed_as): Rename to ...
(parameter_type): ... this. Make TREE_ADDRESSABLE types restrict.
(d_build_call): Move handling of non-POD types here from ...
* d-convert.cc (convert_for_argument): ... here.
* d-tree.h (argument_reference_p): Rename declaration to ...
(parameter_reference_p): ... this.
(type_passed_as): Rename declaration to ...
(parameter_type): ... this.
* types.cc (TypeVisitor::visit (TypeFunction *)): Update caller.
gcc/testsuite/ChangeLog:
PR d/94777
* gdc.dg/pr94777a.d: New test.
* gdc.dg/pr94777b.d: New test.
Diffstat (limited to 'gcc/testsuite')
-rw-r--r-- | gcc/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/pr94777a.d | 15 | ||||
-rw-r--r-- | gcc/testsuite/gdc.dg/pr94777b.d | 181 |
3 files changed, 202 insertions, 0 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 07fe8a6..1f412a0 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2020-04-27 Iain Buclaw <ibuclaw@gdcproject.org> + + PR d/94777 + * gdc.dg/pr94777a.d: New test. + * gdc.dg/pr94777b.d: New test. + 2020-04-26 Iain Sandoe <iain@sandoe.co.uk> PR c++/94752 diff --git a/gcc/testsuite/gdc.dg/pr94777a.d b/gcc/testsuite/gdc.dg/pr94777a.d new file mode 100644 index 0000000..a58fa55 --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr94777a.d @@ -0,0 +1,15 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777 +// { dg-do compile } + +extern void variadic(...); + +void f94777() +{ + struct S94777 + { + int fld; + this(this) { } + } + auto var = S94777(0); + variadic(var, S94777(1)); +} diff --git a/gcc/testsuite/gdc.dg/pr94777b.d b/gcc/testsuite/gdc.dg/pr94777b.d new file mode 100644 index 0000000..a230adb --- /dev/null +++ b/gcc/testsuite/gdc.dg/pr94777b.d @@ -0,0 +1,181 @@ +// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94777 +// { dg-additional-options "-fmain -funittest" } +// { dg-do run { target hw } } +// { dg-skip-if "needs gcc/config.d" { ! d_runtime } } + +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 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; + int value; + ~this() { count++; } +} + +unittest +{ + { + auto a0 = Destructor(0); + auto a1 = Destructor(1); + auto a2 = Destructor(2); + static assert(!__traits(compiles, testVariadic!Destructor(3, a0, a1, a2))); + } + 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); +} |