https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88384

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
I think both C and C++ get this wrong, just in different order.  The test case
below shows the difference.  GCC (in C mode) evaluates __alignof__ of a mixed
expression to the alignment of the second operand while G++ to that of the
first operand.  In G++ this changed in GCC 4.5.  Prior versions evaluated both
expressions to the alignment of the resulting type (i.e., that of a
default-aligned int).  That's also what Clang and ICC do.  In GCC (i.e., in C
mode) it has always worked this way.

$ (set -x && cat t.c && gcc -O2 -c -Wall -fdump-tree-optimized=/dev/stdout t.c
&& gcc -O2 -c -Wall -fdump-tree-optimized=/dev/stdout -xc++ t.c)
+ cat t.c
typedef __attribute__ ((aligned (8))) int I8;
typedef __attribute__ ((aligned (16))) int I16;

extern I8 *p8;
extern I16 *p16;

int f (void)
{
  return __alignof__ (*p16 + *p8);
}

int g (void)
{
  return __alignof__ (*p8 + *p16);
}

+ gcc -O2 -c -Wall -fdump-tree-optimized=/dev/stdout t.c

;; Function f (f, funcdef_no=0, decl_uid=1910, cgraph_uid=1, symbol_order=0)

f ()
{
  <bb 2> [local count: 1073741824]:
  return 8;

}



;; Function g (g, funcdef_no=1, decl_uid=1913, cgraph_uid=2, symbol_order=1)

g ()
{
  <bb 2> [local count: 1073741824]:
  return 16;

}


+ gcc -O2 -c -Wall -fdump-tree-optimized=/dev/stdout -xc++ t.c

;; Function f (_Z1fv, funcdef_no=0, decl_uid=2302, cgraph_uid=1,
symbol_order=0)

f ()
{
  <bb 2> [local count: 1073741824]:
  return 16;

}



;; Function g (_Z1gv, funcdef_no=1, decl_uid=2304, cgraph_uid=2,
symbol_order=1)

g ()
{
  <bb 2> [local count: 1073741824]:
  return 8;

}

Reply via email to