[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2015-06-09 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=6681

Andrei Alexandrescu and...@erdani.com changed:

   What|Removed |Added

   Target Milestone|2.059   |---
Version|D1  D2 |D2

--


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-03-15 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #15 from github-bugzi...@puremagic.com 2012-03-15 18:30:16 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/296b99db347ace5e166120564146277788957eaf
Merge pull request #803 from donc/ctfeunion6681yebblies

Fix issue 6681 - struct constructor call is converted to struct literal ...

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-03-14 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #14 from github-bugzi...@puremagic.com 2012-03-14 20:16:07 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/7cecf0090f7d22caf0efd2e1a558171013a387a5
Merge pull request #493 from donc/bug6681

Supplemental change required by regression bug 6681

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-03-13 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #12 from Don clugd...@yahoo.com.au 2012-03-13 05:15:23 PDT ---
https://github.com/D-Programming-Language/phobos/pull/493
and then
https://github.com/D-Programming-Language/dmd/pull/803

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-03-13 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #13 from yebblies yebbl...@gmail.com 2012-03-13 23:32:59 EST ---
Thanks for doing this.  I think my branch was still letting you return
partially uninitialized arrays/structs from ctfe.  I also think the following
should work:

union U
{
   int a, b;
}
int func()
{
   U u;
   u.a = 3;
   assert(u.b == 3);
   return 1;
}
static assert(func());

But I don't know how to implement it. (it might not be worth it)

Umm, test cases. (some pass, some fail, some pulled out of other test cases in
dmd/phobos.)  The last one should fail, I doubt it's useful leave a variable
partially initialized.


/*
version(none)
{
struct S
{
this(int a, int b) { this.a = b; this.b = a; }
union {
ulong g;
struct
{
int a;
int b;
}
}
}

static immutable S s = S(1, 0);

extern(C) int printf(const char *, ...);

void main()
{
S s = .s;
printf(%d %d %d\n, s.g, s.a, s.b);
}
}

version(none)
{
union in6_addr
{
private union _in6_u_t
{
ubyte[16] u6_addr8;
ushort[8] u6_addr16;
uint[4] u6_addr32;
}
_in6_u_t in6_u;

ubyte[16] s6_addr8;
ushort[8] s6_addr16;
uint[4] s6_addr32;

alias s6_addr8 s6_addr;
}


const in6_addr IN6ADDR_ANY = { s6_addr8: [0] };
}


version(none)
{
struct Zadok
{
char [4] s = void;
}

int quop()
{
Zadok pong;
pong.s = ['z','x','f', 'g'];
return 1;
}

static assert(quop()==1);
static assert(quop()==1); // check for clobbering
}


//version = testc;
version(testc)
{
union U
{
int a;
int b;
}

int testxx()
{
U u;
u.a = 7;
u.b = 4;
assert(u.a == 7);
assert(u.b == 4);
return 1;
}

static assert(testxx());
}

//version = testb;
version(testb)
{
void fillWithZero(T)(T[] arr)
{
foreach(ref x; arr)
x = 7;
}

T[4] f(T)()
{
T[4] stackSpace = void;
T[4] x = stackSpace;
int y = x[0];
//int z = y + y;
fillWithZero(stackSpace[]);
return stackSpace;
}

static assert(f!int() == [7,7,7,7]); 
}

//version = testa;
version(testa)
{
interface SomeInterface
{
  int daz();
  float bar(char);
  int baz();
}

interface SomeOtherInterface
{
int xxx();
}

class TheBase : SomeInterface, SomeOtherInterface
{
int q = 88;
int rad = 61;
int a = 14;
int somebaseclassfunc() { return 28;}
int daz() { return 0; }
int baz() { return 0; }
int xxx() { return 762; }
int foo() { return q; }
float bar(char c) { return 3.6; }
}

class SomeClass : TheBase, SomeInterface
{
int gab = 9;
int fab;
int a = 17;
int b = 23;
int foo() { return gab + a; }
float bar(char c) { return 2.6; }
int something() { return 0; }
int daz() { return 0; }
int baz() { return 0; }
}

class Unrelated : TheBase {
this(int x) { a = x; }
}

auto classtest1(int n)
{
SomeClass c = new SomeClass;
assert(c.a == 17);
assert(c.q == 88);
TheBase d = c;
assert(d.a == 14);
assert(d.q == 88);
if (n==7)
{   // bad cast -- should fail
Unrelated u = cast(Unrelated)d;
assert(u is null);
}
SomeClass e = cast(SomeClass)d;
d.q = 35;
assert(c.q == 35);
assert(c.foo() == 9 + 17);
++c.a;
assert(c.foo() == 9 + 18);
assert(d.foo() == 9 + 18);
d = new TheBase;
SomeInterface fc = c;
SomeOtherInterface ot = c;
assert(fc.bar('x') == 2.6);
assert(ot.xxx() == 762);
fc = d;
ot = d;
assert(fc.bar('x') == 3.6);
assert(ot.xxx() == 762);

Unrelated u2 = new Unrelated(7);
assert(u2.a == 7);
return 6;
}
static assert(classtest1(1));
static assert(classtest1(2));
static assert(classtest1(7)); // bug 7154
}

//version = testd;
version(testd)
{
struct XY { union { int x, y; } }
struct AHolder {
XY aa;
void a(XY x) { aa = x; }
}
struct AB {
AHolder aHolder;
XY b;
void a(XY x) { aHolder.a(x); }
}
struct Main {
AB ab;

void setB() { ab.b = XY(); }
void f() {
ab.a(XY.init);
setB();
}
}
}

//version = teste;
version(teste)
{
union U
{
int a;
long b;
}

long test()
{
U u;
u.a = 3;
u.b = 8;
return u.a + u.b;
}

static assert(test() == 11);
}

//version = testf;
version(testf)

[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-03-03 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #10 from Walter Bright bugzi...@digitalmars.com 2012-03-03 
21:30:50 PST ---
It's a compiler structural problem: there's no way to specify a
struct literal with missing fields.

I don't know about in CTFE, but in the rest of the compiler the code is in
place to just have elements[i] be NULL for missing fields.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-03-03 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #11 from yebblies yebbl...@gmail.com 2012-03-04 16:45:03 EST ---
(In reply to comment #10)
 It's a compiler structural problem: there's no way to specify a
 struct literal with missing fields.
 
 I don't know about in CTFE, but in the rest of the compiler the code is in
 place to just have elements[i] be NULL for missing fields.

I have branch for this that mostly works, but no time to work on it at the
moment.

https://github.com/yebblies/dmd/tree/ctfeunion

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-02-17 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

   Keywords||rejects-valid
 AssignedTo|nob...@puremagic.com|yebbl...@gmail.com


--- Comment #9 from yebblies yebbl...@gmail.com 2012-02-17 21:07:11 EST ---
I think for this to work, the interpreter needs to be able to handle
uninitialized values, and unions need to default to void initializers.  I have
a patch for this that is nearly ready, and solves issue 6438 at the same time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-02-02 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #8 from Don clugd...@yahoo.com.au 2012-02-02 03:26:11 PST ---
(In reply to comment #7)
 Ok, I'll take a look at it tomorrow unless you want it.  I know there are at
 least two places it checks for overlapping union initialization, one in
 expression.c and one somewhere in the glue, maybe e2ir?

The big one is in init.c. Around line 340 there's code I wrote (to replace the
code in 320..340). Walter disabled that code a bit later, but he didn't say
why. 

Would be great if you could take a fresh look at it.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681


yebblies yebbl...@gmail.com changed:

   What|Removed |Added

   Platform|Other   |All
Summary|bogus duplicate union   |struct constructor call is
   |initialization or   |converted to struct literal
   |overlapping initialization  |that breaks union
   |errors  |initialization
 OS/Version|Mac OS X|All


--- Comment #3 from yebblies yebbl...@gmail.com 2012-02-01 23:10:11 EST ---
Got my test cases a little mixed up there, but it's still mostly valid.

All of the non-struct-literal struct construction seems to be converted into
struct literals.  eg.

struct S
{
this(int a, int b) { this.a = b; this.b = a; }
union {
ulong g;
struct {int a, b; };
}
}

static immutable S s = S(0, 1);

Prints: (with a little extra debug output)

StructLiteralExp::semantic('S(0LU,1,0)')
S
Error: duplicate union initialization for a
Error: duplicate union initialization for b

As you can see, it make a struct literal with every field accounted for.

So this is a bug in the constfolding/ctfe code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #5 from yebblies yebbl...@gmail.com 2012-02-02 00:02:06 EST ---
(In reply to comment #4)
 Not exactly. It's a compiler structural problem: there's no way to specify a
 struct literal with missing fields. Struct static initializers can do it, but
 struct literals cannot.
 
 I think the solution is to merge struct literals with struct static
 initializers, as it says in a TODO in the code.

One of the D1 cases seems to have the same problem with struct static
initializers.  Can't this be done by just nulling out the untouched fields in
the Expressions array and ensuring at least one field gets initialized?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #6 from Don clugd...@yahoo.com.au 2012-02-01 07:13:36 PST ---
(In reply to comment #5)
 (In reply to comment #4)
  Not exactly. It's a compiler structural problem: there's no way to specify a
  struct literal with missing fields. Struct static initializers can do it, 
  but
  struct literals cannot.
  
  I think the solution is to merge struct literals with struct static
  initializers, as it says in a TODO in the code.
 
 One of the D1 cases seems to have the same problem with struct static
 initializers.  Can't this be done by just nulling out the untouched fields in
 the Expressions array and ensuring at least one field gets initialized?

Maybe. The order of fields in a struct is fixed, so in theory that ought to
work.
It's a while since I last looked at it, but I remember there were severe
problems with anonymous unions nested inside anonymous unions. There's code
elsewhere in the compiler which tries to identify fields based on their type +
offset, but that cannot work. It appears to work at the moment, but only
because it assumes when fields are initialized in order with no gaps.
Still, I've fixed some of those compiler bugs recently, so maybe it's more
possible now.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---


[Issue 6681] struct constructor call is converted to struct literal that breaks union initialization

2012-02-01 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6681



--- Comment #7 from yebblies yebbl...@gmail.com 2012-02-02 03:38:36 EST ---
Ok, I'll take a look at it tomorrow unless you want it.  I know there are at
least two places it checks for overlapping union initialization, one in
expression.c and one somewhere in the glue, maybe e2ir?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
--- You are receiving this mail because: ---