This is an archive of the discontinued LLVM Phabricator instance.

[sanitizer] Avoid -Wmaybe-uninitialized related warnings when building ASan with GCC.
AbandonedPublic

Authored by m.ostapenko on Nov 19 2015, 6:08 AM.

Details

Reviewers
kcc
samsonov
Summary

Hi!

Since "Use same shadow offset for aarch64" and "Enable optional ASan recovery" patches seem to work robustly in LLVM, I would like to perform another merge to GCC (GCC is on stage 3 now, but it is OK to perform merge now). For now, everything seems OK with library, except some warnings I got in GCC due to -Wmaybe-uninitialized switch:

/home/max/workspace/downloads/trunk/libsanitizer/asan/asan_interceptors.cc: In function ‘__sanitizer::uptr __interceptor_ptrace(int, int, void*, void*)’:
/home/max/workspace/downloads/trunk/libsanitizer/asan/asan_interceptors.cc:59:29: warning: ‘local_iovec.__sanitizer::__sanitizer_iovec::iov_len’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     if (__offset > __offset + __size) {                                 \
                             ^

In file included from /home/max/workspace/downloads/trunk/libsanitizer/asan/asan_interceptors.cc:196:0:
/home/max/workspace/downloads/trunk/libsanitizer/sanitizer_common/sanitizer_common_interceptors.inc:2449:21: note: ‘local_iovec.__sanitizer::__sanitizer_iovec::iov_len’ was declared here
   __sanitizer_iovec local_iovec;
                     ^~~~~~~~~~~

This patch just adds proper default values to local variables in several places.

Diff Detail

Repository
rL LLVM

Event Timeline

m.ostapenko retitled this revision from to [sanitizer] Avoid -Wmaybe-uninitialized related warnings when building ASan with GCC..
m.ostapenko updated this object.
m.ostapenko added reviewers: kcc, samsonov.
m.ostapenko set the repository for this revision to rL LLVM.
m.ostapenko added subscribers: llvm-commits, ygribov.
ygribov added inline comments.Nov 19 2015, 6:23 AM
lib/sanitizer_common/sanitizer_posix.cc
180

What not CHECK here?

Perhaps we could just disable this warning for building this code?

Usually the argument is that we shouldn't prematurely initialize variables
because it hinders analysis and runtime tools. Though the latter argument
probably isn't applicable to the sanitizer runtime/interceptors itself,
though.

In both cases it seems the intent is that the values you've added would
never be used - so in some sense better not to have them so that we can
continue to strive for that to be the case rather than having dead stores
that could come alive at some point & just defer the unexpected behavior
until later.

Perhaps we could just disable this warning for building this code?
...

I've thought about this a little bit more and I think you are right. The code itself is valid and we don't need to worry about these bogus warnings (GCC's -Wmaybe-uninitialized warnings sometimes are really annoying).

m.ostapenko abandoned this revision.Nov 23 2015, 2:34 AM

Ok, abandon this one.