[32/77] Check is_a <scalar_int_mode> before calling valid_pointer_mode

Message ID 87bmooiuv5.fsf@linaro.org
State New
Headers show
Series
  • Add wrapper classes for machine_modes
Related show

Commit Message

Richard Sandiford July 13, 2017, 8:50 a.m.
A future patch will make valid_pointer_mode take a scalar_int_mode
instead of a machine_mode.  is_a <...> rather than as_a <...> is
needed here because we're checking a mode supplied by the user.

2017-07-13  Richard Sandiford  <richard.sandiford@linaro.org>
	    Alan Hayward  <alan.hayward@arm.com>
	    David Sherwood  <david.sherwood@arm.com>

gcc/c-family/
	* c-attribs.c (handle_mode_attribute): Check for a scalar_int_mode
	before calling targetm.addr_space.valid_pointer_mode.

Comments

Jeff Law Aug. 14, 2017, 8:47 p.m. | #1
On 07/13/2017 02:50 AM, Richard Sandiford wrote:
> A future patch will make valid_pointer_mode take a scalar_int_mode

> instead of a machine_mode.  is_a <...> rather than as_a <...> is

> needed here because we're checking a mode supplied by the user.

> 

> 2017-07-13  Richard Sandiford  <richard.sandiford@linaro.org>

> 	    Alan Hayward  <alan.hayward@arm.com>

> 	    David Sherwood  <david.sherwood@arm.com>

> 

> gcc/c-family/

> 	* c-attribs.c (handle_mode_attribute): Check for a scalar_int_mode

> 	before calling targetm.addr_space.valid_pointer_mode.

OK.
jeff

Patch

Index: gcc/c-family/c-attribs.c
===================================================================
--- gcc/c-family/c-attribs.c	2017-06-30 12:50:37.302706033 +0100
+++ gcc/c-family/c-attribs.c	2017-07-13 09:18:37.622901759 +0100
@@ -1438,10 +1438,12 @@  handle_mode_attribute (tree *node, tree
 
       if (POINTER_TYPE_P (type))
 	{
+	  scalar_int_mode addr_mode;
 	  addr_space_t as = TYPE_ADDR_SPACE (TREE_TYPE (type));
 	  tree (*fn)(tree, machine_mode, bool);
 
-	  if (!targetm.addr_space.valid_pointer_mode (mode, as))
+	  if (!is_a <scalar_int_mode> (mode, &addr_mode)
+	      || !targetm.addr_space.valid_pointer_mode (addr_mode, as))
 	    {
 	      error ("invalid pointer mode %qs", p);
 	      return NULL_TREE;
@@ -1451,7 +1453,7 @@  handle_mode_attribute (tree *node, tree
 	    fn = build_pointer_type_for_mode;
 	  else
 	    fn = build_reference_type_for_mode;
-	  typefm = fn (TREE_TYPE (type), mode, false);
+	  typefm = fn (TREE_TYPE (type), addr_mode, false);
 	}
       else
 	{