[PR debug/77773] segfault when compiling __simd64_float16_t with -g

Aldy Hernandez aldyh@redhat.com
Wed Oct 26 19:18:00 GMT 2016


The following one-liner segfaults on arm-eabi when compiled with 
-mfloat-abi=hard -g:

	__simd64_float16_t usingit;

The problem is that the pretty printer (in simple_type_specificer()) is 
dereferencing a NULL result from c_common_type_for_mode:

	  int prec = TYPE_PRECISION (t);
	  if (ALL_FIXED_POINT_MODE_P (TYPE_MODE (t)))
	    t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
	  else
	    t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
	  if (TYPE_NAME (t))

The type in question is:

	<real_type 0x7fffefdeb150 HF ...>

which corresponds to HFmode and which AFAICT, does not have a type by 
design.

I see that other uses of *type_for_node() throughout the compiler check 
the result for NULL, so perhaps we should do the same here.

The attached patch fixes the problem.

OK for trunk?
-------------- next part --------------
commit 10c5a54cb1bf4684864b01cb965d83f3fe474797
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Wed Oct 26 12:06:09 2016 -0700

    	PR debug/77773
    	* c-pretty-print.c (simple_type_specifier): Do not dereference `t'
    	if NULL.

diff --git a/gcc/c-family/c-pretty-print.c b/gcc/c-family/c-pretty-print.c
index 90428ca..6bb38a9 100644
--- a/gcc/c-family/c-pretty-print.c
+++ b/gcc/c-family/c-pretty-print.c
@@ -348,7 +348,7 @@ c_pretty_printer::simple_type_specifier (tree t)
 	    t = c_common_type_for_mode (TYPE_MODE (t), TYPE_SATURATING (t));
 	  else
 	    t = c_common_type_for_mode (TYPE_MODE (t), TYPE_UNSIGNED (t));
-	  if (TYPE_NAME (t))
+	  if (t && TYPE_NAME (t))
 	    {
 	      simple_type_specifier (t);
 	      if (TYPE_PRECISION (t) != prec)
@@ -362,6 +362,7 @@ c_pretty_printer::simple_type_specifier (tree t)
 	      switch (code)
 		{
 		case INTEGER_TYPE:
+		  gcc_assert (t != NULL);
 		  translate_string (TYPE_UNSIGNED (t)
                                     ? "<unnamed-unsigned:"
                                     : "<unnamed-signed:");


More information about the Gcc-patches mailing list