[PATCH] D14817: [sanitizer] Avoid -Wmaybe-uninitialized related warnings when building ASan with GCC.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 19 11:04:26 PST 2015


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.

On Thu, Nov 19, 2015 at 6:08 AM, Maxim Ostapenko via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> m.ostepenko created this revision.
> m.ostepenko added reviewers: kcc, samsonov.
> m.ostepenko added subscribers: llvm-commits, ygribov.
> m.ostepenko set the repository for this revision to rL LLVM.
> Herald added a subscriber: aemerson.
>
> 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.
>
> Repository:
>   rL LLVM
>
> http://reviews.llvm.org/D14817
>
> Files:
>   lib/sanitizer_common/sanitizer_common_interceptors.inc
>   lib/sanitizer_common/sanitizer_posix.cc
>
> Index: lib/sanitizer_common/sanitizer_posix.cc
> ===================================================================
> --- lib/sanitizer_common/sanitizer_posix.cc
> +++ lib/sanitizer_common/sanitizer_posix.cc
> @@ -177,6 +177,7 @@
>      case RdOnly: flags = O_RDONLY; break;
>      case WrOnly: flags = O_WRONLY | O_CREAT; break;
>      case RdWr: flags = O_RDWR | O_CREAT; break;
> +    default: flags = O_RDONLY; break;
>    }
>    fd_t res = internal_open(filename, flags, 0660);
>    if (internal_iserror(res, errno_p))
> Index: lib/sanitizer_common/sanitizer_common_interceptors.inc
> ===================================================================
> --- lib/sanitizer_common/sanitizer_common_interceptors.inc
> +++ lib/sanitizer_common/sanitizer_common_interceptors.inc
> @@ -2448,7 +2448,7 @@
>  INTERCEPTOR(uptr, ptrace, int request, int pid, void *addr, void *data) {
>    void *ctx;
>    COMMON_INTERCEPTOR_ENTER(ctx, ptrace, request, pid, addr, data);
> -  __sanitizer_iovec local_iovec;
> +  __sanitizer_iovec local_iovec = {0, 0};
>
>    if (data) {
>      if (request == ptrace_setregs)
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://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/20151119/893e6eba/attachment.html>


More information about the llvm-commits mailing list