diff mbox series

[3/3] combine: initialize a local var

Message ID 20240502185924.2060196-4-vineetg@rivosinc.com
State New
Headers show
Series Miscll fixlets | expand

Commit Message

Vineet Gupta May 2, 2024, 6:59 p.m. UTC
This is no logic change (but technically still a functional change).

Ran into this when stepping thru combine code.
@newpat has some random garbage for a bit until it is actually set.
With the fix it remains 0 until actually set.

gcc/ChangeLog:
	* combine.cc (try_combine): Initialize newpat.

CC: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Vineet Gupta <vineetg@rivosinc.com>
---
 gcc/combine.cc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jeff Law May 2, 2024, 8:38 p.m. UTC | #1
On 5/2/24 12:59 PM, Vineet Gupta wrote:
> This is no logic change (but technically still a functional change).
> 
> Ran into this when stepping thru combine code.
> @newpat has some random garbage for a bit until it is actually set.
> With the fix it remains 0 until actually set.
> 
> gcc/ChangeLog:
> 	* combine.cc (try_combine): Initialize newpat.
Isn't the same true even after this change if you turn on the optimizer? 
  And isn't the same true for many other objects that are initialized 
lazily?

Ultimately I'll defer to Segher on this.

jeff
Vineet Gupta May 2, 2024, 8:40 p.m. UTC | #2
On 5/2/24 13:38, Jeff Law wrote:
>
> On 5/2/24 12:59 PM, Vineet Gupta wrote:
>> This is no logic change (but technically still a functional change).
>>
>> Ran into this when stepping thru combine code.
>> @newpat has some random garbage for a bit until it is actually set.
>> With the fix it remains 0 until actually set.
>>
>> gcc/ChangeLog:
>> 	* combine.cc (try_combine): Initialize newpat.
> Isn't the same true even after this change if you turn on the optimizer? 

You are right. And the reason I was seeing a difference at all is all my
local toolchain builds are -g3 -O0 :-)

> And isn't the same true for many other objects that are initialized 
> lazily?
>
> Ultimately I'll defer to Segher on this.

Of course.

Thx for taking a look.
-Vineet
Segher Boessenkool May 3, 2024, 8:26 a.m. UTC | #3
On Thu, May 02, 2024 at 11:59:24AM -0700, Vineet Gupta wrote:
> This is no logic change (but technically still a functional change).

Where are 1/3 and 2/3?  Or are those unrelated?  Please don't make
series like that.

> Ran into this when stepping thru combine code.
> @newpat has some random garbage for a bit until it is actually set.
> With the fix it remains 0 until actually set.

The same is true for all uninitialised variables.  Setting everything
to zero explicitly is a) quite a bit slower, and b) just as wrong!
For example, here, newpat should never be zero.  Never.  It does not
make any sense.

Is there any place where newpat is used uninitialised?


Segher
Segher Boessenkool May 3, 2024, 8:30 a.m. UTC | #4
On Thu, May 02, 2024 at 02:38:12PM -0600, Jeff Law wrote:
> 
> 
> On 5/2/24 12:59 PM, Vineet Gupta wrote:
> >This is no logic change (but technically still a functional change).
> >
> >Ran into this when stepping thru combine code.
> >@newpat has some random garbage for a bit until it is actually set.
> >With the fix it remains 0 until actually set.
> >
> >gcc/ChangeLog:
> >	* combine.cc (try_combine): Initialize newpat.
> Isn't the same true even after this change if you turn on the optimizer? 
>  And isn't the same true for many other objects that are initialized 
> lazily?

For all, even.

Without this change the compiler can (in theory, anyway) diagnose the
uninitialised use.  After, there *is* no uninitialised use anymore.

Please don't do this.  It is not an improvement, it is several steps
back, to satisfy a misguides sense of "security".


Segher
Vineet Gupta May 3, 2024, 4:41 p.m. UTC | #5
On 5/3/24 01:26, Segher Boessenkool wrote:
> On Thu, May 02, 2024 at 11:59:24AM -0700, Vineet Gupta wrote:
>> This is no logic change (but technically still a functional change).
> Where are 1/3 and 2/3?  Or are those unrelated? 

Yes they were unrelated (minor doc fixes) hence didn't want to spam you,
but you are right just because they were piled up in my spring cleaning
branch doesn't mean I send them out that way.

> Please don't make series like that.

Noted for future.

>
>> Ran into this when stepping thru combine code.
>> @newpat has some random garbage for a bit until it is actually set.
>> With the fix it remains 0 until actually set.
> The same is true for all uninitialised variables.  Setting everything
> to zero explicitly is a) quite a bit slower, and b) just as wrong!
> For example, here, newpat should never be zero.  Never.  It does not
> make any sense.
>
> Is there any place where newpat is used uninitialised?

As I mentioned this patch was the outcome of my "debugging" experience
and agree I should not conflate between what the compiler does and what
is needed to debug the compiler itself.

I've dropped this one.

Thx,
-Vineet
diff mbox series

Patch

diff --git a/gcc/combine.cc b/gcc/combine.cc
index 92b8d98e6c15..0b5fe00c8c5b 100644
--- a/gcc/combine.cc
+++ b/gcc/combine.cc
@@ -2522,7 +2522,7 @@  try_combine (rtx_insn *i3, rtx_insn *i2, rtx_insn *i1, rtx_insn *i0,
 	     bool *new_direct_jump_p, rtx_insn *last_combined_insn)
 {
   /* New patterns for I3 and I2, respectively.  */
-  rtx newpat, newi2pat = 0;
+  rtx newpat = 0, newi2pat = 0;
   rtvec newpat_vec_with_clobbers = 0;
   bool substed_i2 = false, substed_i1 = false, substed_i0 = false;
   /* Indicates need to preserve SET in I0, I1 or I2 in I3 if it is not