diff mbox series

Fix unguarded uses of tree_to_uhwi

Message ID 87fubh1s88.fsf@linaro.org
State New
Headers show
Series Fix unguarded uses of tree_to_uhwi | expand

Commit Message

Richard Sandiford Sept. 20, 2017, 12:15 p.m. UTC
This patch uses tree_fits_uhwi_p to protect a previously unguarded
use of tree_to_uhwi.  Without this we would ICE for variable-sized types.

Tested on aarch64-linux-gnu, x86_64-linux-gnu and powerpc64le-linus-gnu.
OK to install?

Richard


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

gcc/
	* tree.c (find_atomic_core_type): Check tree_fits_uhwi_p before
	calling tree_to_uhwi.

Comments

Richard Biener Sept. 20, 2017, 2:52 p.m. UTC | #1
On September 20, 2017 2:15:19 PM GMT+02:00, Richard Sandiford <richard.sandiford@linaro.org> wrote:
>This patch uses tree_fits_uhwi_p to protect a previously unguarded

>use of tree_to_uhwi.  Without this we would ICE for variable-sized

>types.

>

>Tested on aarch64-linux-gnu, x86_64-linux-gnu and

>powerpc64le-linus-gnu.

>OK to install?


OK. 

Richard. 

>Richard

>

>

>2017-09-20  Richard Sandiford  <richard.sandiford@linaro.org>

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

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

>

>gcc/

>	* tree.c (find_atomic_core_type): Check tree_fits_uhwi_p before

>	calling tree_to_uhwi.

>

>Index: gcc/tree.c

>===================================================================

>--- gcc/tree.c	2017-09-14 16:45:44.199522746 +0100

>+++ gcc/tree.c	2017-09-20 13:13:43.953534150 +0100

>@@ -5821,11 +5821,10 @@ find_atomic_core_type (tree type)

>   tree base_atomic_type;

> 

>   /* Only handle complete types.  */

>-  if (TYPE_SIZE (type) == NULL_TREE)

>+  if (!tree_fits_uhwi_p (TYPE_SIZE (type)))

>     return NULL_TREE;

> 

>-  HOST_WIDE_INT type_size = tree_to_uhwi (TYPE_SIZE (type));

>-  switch (type_size)

>+  switch (tree_to_uhwi (TYPE_SIZE (type)))

>     {

>     case 8:

>       base_atomic_type = atomicQI_type_node;
diff mbox series

Patch

Index: gcc/tree.c
===================================================================
--- gcc/tree.c	2017-09-14 16:45:44.199522746 +0100
+++ gcc/tree.c	2017-09-20 13:13:43.953534150 +0100
@@ -5821,11 +5821,10 @@  find_atomic_core_type (tree type)
   tree base_atomic_type;
 
   /* Only handle complete types.  */
-  if (TYPE_SIZE (type) == NULL_TREE)
+  if (!tree_fits_uhwi_p (TYPE_SIZE (type)))
     return NULL_TREE;
 
-  HOST_WIDE_INT type_size = tree_to_uhwi (TYPE_SIZE (type));
-  switch (type_size)
+  switch (tree_to_uhwi (TYPE_SIZE (type)))
     {
     case 8:
       base_atomic_type = atomicQI_type_node;