[C++] Fix g++.dg/cpp0x/nullptr21.C on IA64 HP-UX

Message ID 201106131759.p5DHxcB08717@lucas.cup.hp.com
State New
Headers show

Commit Message

Steve Ellcey June 13, 2011, 5:59 p.m.
The test g++.dg/cpp0x/nullptr21.C fails on IA64 HP-UX in 32 bit mode and
in looking at the problem I tracked it down to some code in
cxx_init_decl_processing that was added in r159131 to create nullptr_node:

2010-05-06  Magnus Fromreide  <magfr@lysator.liu.se>
            Jason Merrill  <jason@redhat.com>

        Add support for C++0x nullptr.

The type for nullptr_node is nullptr_type_node and it is set up with a type,
size, and alignment of ptr_mode.  But the actual mode set with SET_TYPE_MODE
is set to Pmode instead of ptr_mode.  I don't know why, it may just be a typo.

This causes problems on IA64 HP-UX in 32 bit mode because ptr_mode is 4 bytes
(and 4 byte aligned) but Pmode is 8 bytes and 8 byte aligned.  The code
generated for nullptr21.C winds up doing an 8 byte load for nullptr on an
address that is only 4 btye aligned and the code seg faults with a misaligned

This patch changes Pmode to ptr_mode in the SET_TYPE_MODE call and that fixes
the problem.  It also caused no regressions on IA64 HP-UX, IA64 Linux, or
x86 Linux.

OK for checkin?

Steve Ellcey

2011-06-13  Steve Ellcey  <sje@cup.hp.com>

	* decl.c (cxx_init_decl_processing): Use ptr_mode instead of Pmode.


Jason Merrill June 13, 2011, 6:03 p.m. | #1



Index: decl.c
--- decl.c	(revision 174979)
+++ decl.c	(working copy)
@@ -3672,7 +3672,7 @@ 
     TYPE_SIZE_UNIT (nullptr_type_node) = size_int (GET_MODE_SIZE (ptr_mode));
     TYPE_UNSIGNED (nullptr_type_node) = 1;
     TYPE_PRECISION (nullptr_type_node) = GET_MODE_BITSIZE (ptr_mode);
-    SET_TYPE_MODE (nullptr_type_node, Pmode);
+    SET_TYPE_MODE (nullptr_type_node, ptr_mode);
     record_builtin_type (RID_MAX, "decltype(nullptr)", nullptr_type_node);
     nullptr_node = build_int_cst (nullptr_type_node, 0);