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

Cameron McInally cameron.mcinally at nyu.edu
Wed Jan 8 07:48:55 PST 2014


Rafael,

Is this patch what you had in mind?

Thx,
Cameron


On Tue, Jan 7, 2014 at 7:14 PM, Rafael Espíndola
<rafael.espindola at gmail.com> wrote:
> On 7 January 2014 17:12, Cameron McInally <cameron.mcinally at nyu.edu> wrote:
>> Hey Rafael,
>>
>> I don't know. My project has its own build system and build requirements.
>>
>> Your solution of using report_fatal_error(…) also avoids the warning
>> with a release build. Is that the preferred fix? Seems like it would
>> save an initialization, but introduce a runtime check into a release
>> compiler.
>
> I think it should be a report_fatal_error anyway. Currently a
> non-assert llvm silently accepts a broken file with
>
> target datalayout = "i:64:6x"
>
> for example. While no valid "user" tool produces these files, we do
> tend to have reasonable errors when given a broken .ll file.
>
> If gcc still warns with that change, we should probably just suppress
> the warning. The main issue is not the performance cost of zeroing, it
> is that it prevents tools like asan and valgrind from finding real
> use-befere-init bugs.
>
> Cheers,
> Rafael
-------------- next part --------------
Index: lib/IR/DataLayout.cpp
===================================================================
--- lib/IR/DataLayout.cpp	(revision 198702)
+++ lib/IR/DataLayout.cpp	(working copy)
@@ -207,9 +207,10 @@
 
 /// Get an unsigned integer, including error checks.
 static unsigned getInt(StringRef R) {
-  unsigned Result = 0;
+  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;
 }
 


More information about the llvm-commits mailing list