This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Fix UBSAN ICE with C++ attribute types (PR c++/88215)


On Wed, 28 Nov 2018, Jakub Jelinek wrote:

> Hi!
> 
> On the following testcase we ICE, because op1 doesn't have normal
> int type, but a distinct attribute type, while their main variants
> are different, they are still treated as compatible types and the C++ FE
> doesn't actually try to ensure both arguments have the same type.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

LGTM.

> 2018-11-28  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/88215
> 	* c-ubsan.c: Include langhooks.h.
> 	(ubsan_instrument_division): Change gcc_assert that main variants
> 	of op0 and op1 types are equal to gcc_checking_assert that the
> 	main variants are compatible types.
> 
> 	* c-c++-common/ubsan/pr88215.c: New test.
> 
> --- gcc/c-family/c-ubsan.c.jj	2018-11-14 17:44:02.159912988 +0100
> +++ gcc/c-family/c-ubsan.c	2018-11-27 12:30:15.211687948 +0100
> @@ -31,6 +31,7 @@ along with GCC; see the file COPYING3.
>  #include "stringpool.h"
>  #include "attribs.h"
>  #include "asan.h"
> +#include "langhooks.h"
>  
>  /* Instrument division by zero and INT_MIN / -1.  If not instrumenting,
>     return NULL_TREE.  */
> @@ -44,8 +45,9 @@ ubsan_instrument_division (location_t lo
>    /* At this point both operands should have the same type,
>       because they are already converted to RESULT_TYPE.
>       Use TYPE_MAIN_VARIANT since typedefs can confuse us.  */
> -  gcc_assert (TYPE_MAIN_VARIANT (TREE_TYPE (op0))
> -	      == TYPE_MAIN_VARIANT (TREE_TYPE (op1)));
> +  tree top0 = TYPE_MAIN_VARIANT (type);
> +  tree top1 = TYPE_MAIN_VARIANT (TREE_TYPE (op1));
> +  gcc_checking_assert (lang_hooks.types_compatible_p (top0, top1));
>  
>    op0 = unshare_expr (op0);
>    op1 = unshare_expr (op1);
> --- gcc/testsuite/c-c++-common/ubsan/pr88215.c.jj	2018-11-27 12:33:59.102998653 +0100
> +++ gcc/testsuite/c-c++-common/ubsan/pr88215.c	2018-11-27 12:33:35.694384374 +0100
> @@ -0,0 +1,11 @@
> +/* PR c++/88215 */
> +/* { dg-do compile } */
> +/* { dg-options "-fsanitize=integer-divide-by-zero" } */
> +
> +int
> +foo (void)
> +{
> +  int a = 2, __attribute__ ((__unused__)) b = 1;
> +  int f = a / b;
> +  return f;
> +}
> 
> 	Jakub
> 
> 

-- 
Richard Biener <rguenther@suse.de>
SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]