[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

2018-01-27 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

--- Comment #6 from Jakub Jelinek  ---
Zero sized object occupies zero bytes, if you have an array of them,
necessarily all the elements of the array need to have the same address.  While
individual variables could be in theory padded, it would be a waste of address
space for something that doesn't need to occupy any address space. 
Furthermore, in your testcase the objects are common variables, so it is the
linker that allocates them.  If you need unique addresses, just don't use zero
sized objects, if you don't mind them, forcing everyone to have unique
addresses might be a misoptimization for them.

[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

2018-01-27 Thread uecker at eecs dot berkeley.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

--- Comment #5 from Martin Uecker  ---
(In reply to Jakub Jelinek from comment #4)
> If you want aggregate with size 1 and isn't used to store information, use
> typedef struct { char : 1; } zero;
> instead.

Yes, thank you.

But for my understanding: Is there a reason why it is important that zero-sized
objects should sometimes have the same address? I am wondering because I think
zero-sized arrays would make sense to allow in C (it sometimes makes
programming edge cases simpler in numerical code) and at the same time I think
it might be a nice principle to require that all unique objects existing at the
same time should also have a unique address.

[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

2018-01-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

--- Comment #4 from Jakub Jelinek  ---
If you want aggregate with size 1 and isn't used to store information, use
typedef struct { char : 1; } zero;
instead.

[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

2018-01-26 Thread uecker at eecs dot berkeley.edu
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

--- Comment #3 from Martin Uecker  ---


(In reply to Richard Biener from comment #1)
> Confirmed.  I think the C language doesn't specify this since zero-sized
> arrays are a GNU extension and thus in C no zero-sized types/decls exist?
> 
> So not sure if there's anything to fix - Joseph?
> 
> Note that for global unique addresses you can use global objects of size 1,
> like a char object.  Not sure why you think using a GNU extension is
> superior?

It makes it clear in a nice way that these variables are not used to store
information.


(In reply to Jakub Jelinek from comment #2)
> Zero sized objects of course can have the same address and always had.
> Just in your testcase the comparison used to be optimized away before
> r218462.
> If you hide it from the optimizers, like with:
>   int *p = a;
>   int *q = b;
>   asm ("" : "+r" (p), "+r" (q));
> if(p == q) __builtin_abort ();
> you'll get aborts all the way to r104500 (oldest revision I have around).

Oh well, so this was simply an incorrect optimization.

[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

2018-01-26 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

Jakub Jelinek  changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 CC||jakub at gcc dot gnu.org
 Resolution|--- |INVALID

--- Comment #2 from Jakub Jelinek  ---
Zero sized objects of course can have the same address and always had.
Just in your testcase the comparison used to be optimized away before r218462.
If you hide it from the optimizers, like with:
int *p = a;
int *q = b;
asm ("" : "+r" (p), "+r" (q));
if(p == q) __builtin_abort ();
you'll get aborts all the way to r104500 (oldest revision I have around).

[Bug c/84046] [6/7/8 Regression] global zero-sized objects may have same address

2018-01-26 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84046

Richard Biener  changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
  Known to work||4.9.4
Version|unknown |8.0
   Keywords||wrong-code
   Last reconfirmed||2018-01-26
 CC||jsm28 at gcc dot gnu.org
 Ever confirmed|0   |1
Summary|global zero-sized objects   |[6/7/8 Regression] global
   |may have same address   |zero-sized objects may have
   ||same address
   Target Milestone|--- |6.5
  Known to fail||5.1.0

--- Comment #1 from Richard Biener  ---
Confirmed.  I think the C language doesn't specify this since zero-sized arrays
are a GNU extension and thus in C no zero-sized types/decls exist?

So not sure if there's anything to fix - Joseph?

Note that for global unique addresses you can use global objects of size 1,
like a char object.  Not sure why you think using a GNU extension is
superior?