public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pph] Initialize cache_ix in all paths in pph_start_record (issue4642045)
@ 2011-06-17 23:18 Gabriel Charette
  0 siblings, 0 replies; 3+ messages in thread
From: Gabriel Charette @ 2011-06-17 23:18 UTC (permalink / raw)
  To: reply, crowl, dnovillo, gcc-patches

Read the comment in the diff for all the details.

I found this while working on my current patch, adding some assertion at the
end of the function would create a new build error and moving it around in the
function would stop showing the error.

I discussed this with Collin and Jeff and it appears that the compiler
changes it's inlining decisions based on very picky details. In this particular
case, inlining the function resulted in an error.

Tested with bootstrap build and pph regression testing.

2011-06-17  Gabriel Charette  <gchare@google.com>

	* gcc/cp/pph-streamer-in.c (pph_start_record):
	Initialize cache_ix in all paths.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index b3c2ac9..186100f 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -204,7 +204,15 @@ pph_start_record (pph_stream *stream, unsigned *cache_ix)
   if (marker == PPH_RECORD_START || marker == PPH_RECORD_SHARED)
     *cache_ix = pph_in_uint (stream);
   else
-    gcc_assert (marker == PPH_RECORD_END);
+    {
+      gcc_assert (marker == PPH_RECORD_END);
+      /* Initialize CACHE_IX to an invalid index. Even though this
+	 is never used in practice, the compiler will throw an error
+	 if the optimizer inlines this function and discards the asserts
+	 in a given build as it will complain that " 'ix' may be used
+	 unititialized".  */
+      *cache_ix = -1;
+    }
 
   return marker;
 }

--
This patch is available for review at http://codereview.appspot.com/4642045

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pph] Initialize cache_ix in all paths in pph_start_record (issue4642045)
@ 2011-06-22 19:10 dnovillo
  0 siblings, 0 replies; 3+ messages in thread
From: dnovillo @ 2011-06-22 19:10 UTC (permalink / raw)
  To: gchare, crowl; +Cc: gcc-patches, reply

On 2011/06/18 01:29:31, Gabriel Charette wrote:

> 2011-06-17  Gabriel Charette  <mailto:gchare@google.com>

> 	* gcc/cp/pph-streamer-in.c (pph_start_record):
> 	Initialize cache_ix in all paths.

OK.  Applied to branch.


Diego.

http://codereview.appspot.com/4642045/

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pph] Initialize cache_ix in all paths in pph_start_record (issue4642045)
@ 2011-06-18  2:49 Gabriel Charette
  0 siblings, 0 replies; 3+ messages in thread
From: Gabriel Charette @ 2011-06-18  2:49 UTC (permalink / raw)
  To: reply, gcc-patches

Clarified comment from v1 of this patch.

2011-06-17  Gabriel Charette  <gchare@google.com>

	* gcc/cp/pph-streamer-in.c (pph_start_record):
	Initialize cache_ix in all paths.

diff --git a/gcc/cp/pph-streamer-in.c b/gcc/cp/pph-streamer-in.c
index b3c2ac9..186100f 100644
--- a/gcc/cp/pph-streamer-in.c
+++ b/gcc/cp/pph-streamer-in.c
@@ -204,7 +204,15 @@ pph_start_record (pph_stream *stream, unsigned *cache_ix)
   if (marker == PPH_RECORD_START || marker == PPH_RECORD_SHARED)
     *cache_ix = pph_in_uint (stream);
   else
-    gcc_assert (marker == PPH_RECORD_END);
+    {
+      gcc_assert (marker == PPH_RECORD_END);
+      /* Initialize CACHE_IX to an invalid index. Even though this
+	 is never used in practice, the compiler will throw an error
+	 if the optimizer inlines this function in a given build as
+	 it will complain that " 'ix' may be used uninitialized".  */
+      *cache_ix = -1;
+    }
 
   return marker;
 }

--
This patch is available for review at http://codereview.appspot.com/4642045

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-22 18:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-17 23:18 [pph] Initialize cache_ix in all paths in pph_start_record (issue4642045) Gabriel Charette
2011-06-18  2:49 Gabriel Charette
2011-06-22 19:10 dnovillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).