[llvm] r176134 - Try to get rid of a -wunitialized warning: explicitly initialize the pointer

Eli Bendersky eliben at google.com
Tue Feb 26 16:54:27 PST 2013


>> > I thought we turned that off due to the false positives like this.
>> >
>>
>> Yes, gcc 4.6.3. This is after a vanilla cmake+ninja configure and build.
>>
>> > I'm really opposed to littering the code with dead stores to placate
>> > this
>> > warning. It undermines our ability to use Valgrind to catch actual
>> > uninitialized bugs.
>>
>> In this case I initialized the pointer to NULL and added asserts, so
>> hopefully any real mis-usage will be detected easily?
>
>
> Until someone else fails to add the assert.
>
> I'd rather have a consistent practice here.

Chandler, sorry but I don't understand what it is that you're asking
of me here, exactly.

If you now (after my commit) run:

$ llvm-mc -mdis -filetype=obj foo.o

You get:

llvm-mc: /usr/local/google/home/eliben/llvm/llvm_svn_rw/tools/llvm-mc/llvm-mc.cpp:468:
int main(int, char**): Assertion `IP && "Expected assembly output"'
failed.
0  llvm-mc         0x0000000000659daa
1  llvm-mc         0x000000000065a031
2  llvm-mc         0x0000000000659a80
3  libpthread.so.0 0x00007f24aa14bcb0
4  libc.so.6       0x00007f24a939d425 gsignal + 53
5  libc.so.6       0x00007f24a93a0b8b abort + 379
6  libc.so.6       0x00007f24a93960ee
7  libc.so.6       0x00007f24a9396192
8  llvm-mc         0x000000000040882d
9  libc.so.6       0x00007f24a938876d __libc_start_main + 237
10 llvm-mc         0x0000000000404b49
Stack dump:
0. Program arguments:
/usr/local/google/home/eliben/llvm/build_llvm_svn_rw/Debug+Asserts/bin/llvm-mc
-mdis -filetype=obj rsmall.o
Aborted (core dumped)


Yes, the command-line args make no sense. But without the NULL
initialization and assertion, this would simply dereference arbitrary
memory and could be trickier to diagnose. So gcc is right here - a
path in the code exists that can dereference an un-initialized
pointer. Do you suggest that we should not fix such paths for the sake
of not "undermining our ability to use Valgrind"? Do you want me to
revert the change and leave the pointer uninitialized? Please state
your request explicitly so we can have a constructive discussion.

Eli



More information about the llvm-commits mailing list