[llvm] bcb47bb - Fix "use of uninitialized variable" static analyzer warnings. NFCI.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 26 18:54:10 PDT 2020


Please don't add initializations to variables that aren't needed for
program correctness - if the static analyzer can't figure this out that's
for it to be fixed, or to add annotations that explain these guarantees to
it, without changing the source code to add initializations that, if ever
used, may hide further bugs (since tools like MSan won't be able to
diagnose those errors)

In this case, these variables don't appear to need any initialization -
they're guaranteed to be initialized if isBasePlusOffsetMemoryAccess
returns true. (& in fact IsStore is guaranteed to be initialized regardless)

Refactoring the API might be an idea - isBasePlusOffsetMemoryAccess could
return Optional<struct { IsMemAccess, AddrIdx }> instead, then this would
all be clear to both programmers, static analyzers, and runtime checking.

On Tue, Jan 7, 2020 at 2:56 AM Simon Pilgrim via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

>
> Author: Simon Pilgrim
> Date: 2020-01-07T10:55:38Z
> New Revision: bcb47bbd7214b2795eb114df22ef745850abccb2
>
> URL:
> https://github.com/llvm/llvm-project/commit/bcb47bbd7214b2795eb114df22ef745850abccb2
> DIFF:
> https://github.com/llvm/llvm-project/commit/bcb47bbd7214b2795eb114df22ef745850abccb2.diff
>
> LOG: Fix "use of uninitialized variable" static analyzer warnings. NFCI.
>
> Added:
>
>
> Modified:
>     llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
>
> Removed:
>
>
>
>
> ################################################################################
> diff  --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
> b/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
> index 2d53750ad0ee..0544758f8a25 100644
> --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
> +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsNaClELFStreamer.cpp
> @@ -154,8 +154,8 @@ class MipsNaClELFStreamer : public MipsELFStreamer {
>      }
>
>      // Sandbox loads, stores and SP changes.
> -    unsigned AddrIdx;
> -    bool IsStore;
> +    unsigned AddrIdx = 0;
> +    bool IsStore = false;
>      bool IsMemAccess = isBasePlusOffsetMemoryAccess(Inst.getOpcode(),
> &AddrIdx,
>                                                      &IsStore);
>      bool IsSPFirstOperand = isStackPointerFirstOperand(Inst);
>
>
>
> _______________________________________________
> 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/20200326/55a11ca6/attachment.html>


More information about the llvm-commits mailing list