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]

[patch] avoid ICE due to NULL pointer dereference in ipa-comdats.c


Hi,

I got an ICE while building libstdc++ of a cross compiler x86 to aarch64.  I
have a testcase that ICEs on current GCC trunk.  I was trying to painfully
reduce it with creduce, and it is still several thousand lines of c++. Frustrated
that it does not reduce anymore, I decided to have a look with gdb at why the
compiler was iceing: the code dereferences a NULL pointer that we get by looking
up the value of a symbol in a map.  Around that place, there is another pattern
that first makes sure that the pointer we get from the map is non NULL: I copied
that code around and that seemed to have solved the ICE.

Regtested on x86-64-linux, and also checked that my aarch64 cross compilers are
now building correctly libstdc++.

Ok to commit?

Thanks,
Sebastian

>From f5934ecdee5d7e8e143310c21906d5099b9e7d23 Mon Sep 17 00:00:00 2001
From: Sebastian Pop <s.pop@samsung.com>
Date: Wed, 17 Sep 2014 14:04:20 -0500
Subject: [PATCH] avoid dereferencing a NULL pointer

2014-09-17  Sebastian Pop  <s.pop@samsung.com>

	* ipa-comdats.c (ipa_comdats): Check that the value in the map is non
	NULL before dereferencing it.
---
 gcc/ipa-comdats.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-comdats.c b/gcc/ipa-comdats.c
index b270d97..57e8239 100644
--- a/gcc/ipa-comdats.c
+++ b/gcc/ipa-comdats.c
@@ -317,7 +317,13 @@ ipa_comdats (void)
 	  && !symbol->alias
 	  && symbol->real_symbol_p ())
 	{
-	  tree group = *map.get (symbol);
+	  tree group = NULL;
+	  /* Get current lattice value of SYMBOL.  */
+	  tree *val = map.get (symbol);
+	  if (val)
+	    group = *val;
+	  else
+	    continue;
 
 	  if (group == error_mark_node)
 	    continue;
-- 
1.9.1


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