The -Wnonnull warning improvement (PR c/17308 - nonnull attribute
not as useful as it could be) causes a couple of false positives
in a powerpc64le bootstrap.  The attached fix suppresses them.
It passes bootstrap on powerpc64le but tests are still running.

I couldn't reproduce the bootstrap comparison failure that Segher
mentioned in his comment on the bug.  I've gone over the patch
again to see if I could spot what could possibly be behind it
but couldn't really see anything.  Jeff, you mentioned attribute
nonnull is exploited by the null pointer optimization.  Do you
think it could possibly have this effect in GCC?

Martin
PR bootstrap/78817 - stage2 bootstrap failure in vec.h:1613:5: error: argument 1 null where non-null expected after r243661

gcc/ChangeLog:

	PR bootstrap/78817
	* vec.h (vec<T, A, vl_embed>::quick_grow_cleared): Assert postcondition.
	( vec<T, va_heap, vl_ptr>::safe_grow_cleared): Ditto.

diff --git a/gcc/vec.h b/gcc/vec.h
index aa93411..80a6ef0 100644
--- a/gcc/vec.h
+++ b/gcc/vec.h
@@ -1092,10 +1092,16 @@ inline void
 vec<T, A, vl_embed>::quick_grow_cleared (unsigned len)
 {
   unsigned oldlen = length ();
-  size_t sz = sizeof (T) * (len - oldlen);
-  quick_grow (len);
-  if (sz != 0)
-    memset (&(address ()[oldlen]), 0, sz);
+  gcc_checking_assert (oldlen <= len);
+
+  if (size_t sz = sizeof (T) * (len - oldlen))
+    {
+      quick_grow (len);
+
+      T *p = address ();
+      gcc_assert (p != NULL);
+      memset (p + oldlen, 0, sz);
+    }
 }
 
 
@@ -1607,10 +1613,16 @@ inline void
 vec<T, va_heap, vl_ptr>::safe_grow_cleared (unsigned len MEM_STAT_DECL)
 {
   unsigned oldlen = length ();
-  size_t sz = sizeof (T) * (len - oldlen);
-  safe_grow (len PASS_MEM_STAT);
-  if (sz != 0)
-    memset (&(address ()[oldlen]), 0, sz);
+  gcc_checking_assert (oldlen <= len);
+
+  if (size_t sz = sizeof (T) * (len - oldlen))
+    {
+      safe_grow (len PASS_MEM_STAT);
+
+      T *p = address ();
+      gcc_assert (p != NULL);
+      memset (p + oldlen, 0, sz);
+    }
 }
 
 

Reply via email to