[llvm] r355818 - [MIPS GlobalISel] Silence uninitialized variable warning

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 14:22:14 PDT 2019


On Mon, Mar 11, 2019 at 3:38 AM Benjamin Kramer via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: d0k
> Date: Mon Mar 11 03:39:15 2019
> New Revision: 355818
>
> URL: http://llvm.org/viewvc/llvm-project?rev=355818&view=rev
> Log:
> [MIPS GlobalISel] Silence uninitialized variable warning
>
> The control flow here cannot ever use the uninitialized value, but it's
> too hard for the compiler to figure that out. Clang warns:
>

Clang's uninitialized warning is pretty careful about false positives - I
beileve you either need an always-true condition (might happen if you do
something like "if (sizeof(int) == 4) else if (sizeof(int) == 8)", for
instance) or it really is use-of-uninitialized.

In this case it looks like CarrySum is assigned to CarrySumPrevDstIdx
unconditionally after the if/else, but is not initialized in the else block
at all. That seems like a true-positive & an open question as to what value
should be assigned to CarrySum in the else block, right? Is this codepath
tested & is the zero the right answer here?


>
> llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:2600:28: error: variable
> 'CarrySum' is used uninitialized whenever 'for' loop exits because its
> condition is false [-Werror,-Wsometimes-uninitialized]
>       for (unsigned i = 2; i < Factors.size(); ++i)
>                            ^~~~~~~~~~~~~~~~~~
> llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:2604:26: note:
> uninitialized use occurs here
>     CarrySumPrevDstIdx = CarrySum;
>                          ^~~~~~~~
> llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:2600:28: note: remove the
> condition if it is always true
>       for (unsigned i = 2; i < Factors.size(); ++i)
>                            ^~~~~~~~~~~~~~~~~~
> llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp:2583:22: note: initialize
> the variable 'CarrySum' to silence this warning
>     unsigned CarrySum;
>                      ^
>                       = 0
>
> Modified:
>     llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
>
> Modified: llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp?rev=355818&r1=355817&r2=355818&view=diff
>
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp (original)
> +++ llvm/trunk/lib/CodeGen/GlobalISel/LegalizerHelper.cpp Mon Mar 11
> 03:39:15 2019
> @@ -2581,7 +2581,7 @@ void LegalizerHelper::multiplyRegisters(
>        Factors.push_back(CarrySumPrevDstIdx);
>      }
>
> -    unsigned CarrySum;
> +    unsigned CarrySum = 0;
>      // Add all factors and accumulate all carries into CarrySum.
>      if (DstIdx != DstParts - 1) {
>        MachineInstrBuilder Uaddo =
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190311/8fd2018b/attachment.html>


More information about the llvm-commits mailing list