[llvm] r199147 - Fix uninitialized warning in llvm/lib/IR/DataLayout.cpp.

dblaikie at gmail.com dblaikie at gmail.com
Mon Jan 13 16:14:57 PST 2014


On Mon Jan 13 2014 at 2:12:08 PM, Cameron McInally <cameron.mcinally at nyu.edu>
wrote:

> Author: mcinally
> Date: Mon Jan 13 16:04:55 2014
> New Revision: 199147
>
> URL: http://llvm.org/viewvc/llvm-project?rev=199147&view=rev
> Log:
> Fix uninitialized warning in llvm/lib/IR/DataLayout.cpp.
>
> Added:
>     llvm/trunk/test/Assembler/getInt.ll
> Modified:
>     llvm/trunk/lib/IR/DataLayout.cpp
>
> Modified: llvm/trunk/lib/IR/DataLayout.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/
> DataLayout.cpp?rev=199147&r1=199146&r2=199147&view=diff
> ============================================================
> ==================
> --- llvm/trunk/lib/IR/DataLayout.cpp (original)
> +++ llvm/trunk/lib/IR/DataLayout.cpp Mon Jan 13 16:04:55 2014
> @@ -207,9 +207,10 @@ static std::pair<StringRef, StringRef> s
>
>  /// Get an unsigned integer, including error checks.
>  static unsigned getInt(StringRef R) {
> -  unsigned Result = 0;
>

Was this a Clang -Wuninitialized? I owuldn't think so.

If GCC was warning here and Clang wasn't, we would generally prefer /not/
to initialize this variable (and possibly suppress the GCC warning).

The reason for this is that if there is no use-of-uninitialized (which
there isn't, with your fix, by the looks of it) at runtime, the code is
correct and runtime tools like Valgrind and MSan can detect bugs that may
be introduced. If we initialize the variable to suppress the warning, the
runtime tools will never tell us about our bugs.

- David


> +  unsigned Result;
>    bool error = R.getAsInteger(10, Result); (void)error;
> -  assert(!error && "not a number, or does not fit in an unsigned int");
> +  if (error)
> +    report_fatal_error("not a number, or does not fit in an unsigned
> int");
>    return Result;
>  }
>
>
> Added: llvm/trunk/test/Assembler/getInt.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/
> Assembler/getInt.ll?rev=199147&view=auto
> ============================================================
> ==================
> --- llvm/trunk/test/Assembler/getInt.ll (added)
> +++ llvm/trunk/test/Assembler/getInt.ll Mon Jan 13 16:04:55 2014
> @@ -0,0 +1,4 @@
> +; RUN: opt < %s
> +; XFAIL: *
> +
> +target datalayout = "p:4294967296:64:64"
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140114/1563c493/attachment.html>


More information about the llvm-commits mailing list