Bug 81981 - [8 Regression] -fsanitize=undefined makes a -Wmaybe-uninitialized warning disappear
Summary: [8 Regression] -fsanitize=undefined makes a -Wmaybe-uninitialized warning dis...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: 8.0
Assignee: Jakub Jelinek
URL:
Keywords: diagnostic, missed-optimization
Depends on:
Blocks:
 
Reported: 2017-08-25 13:08 UTC by Vincent Lefèvre
Modified: 2018-08-21 03:01 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-25 00:00:00


Attachments
gcc8-pr81981.patch (1003 bytes, patch)
2017-08-29 18:14 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2017-08-25 13:08:04 UTC
Consider:

int foo (int i)
{
  int t[1], u[1];
  int n = 0;

  if (i)
    {
      t[n] = i;
      u[0] = i;
    }

  return t[0] + u[0];
}

With gcc (Debian 20170823-1) 8.0.0 20170823 (experimental) [trunk revision 251306], I get:

zira% gcc-snapshot -Wmaybe-uninitialized -O2 -c tst.c -fsanitize=undefined
tst.c: In function 'foo':
tst.c:12:15: warning: 'u[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return t[0] + u[0];
          ~~~~~^~~~~~

zira% gcc-snapshot -Wmaybe-uninitialized -O2 -c tst.c                     
tst.c: In function 'foo':
tst.c:12:15: warning: 'u[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   return t[0] + u[0];
          ~~~~~^~~~~~
tst.c:12:15: warning: 't[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]

i.e. with -fsanitize=undefined, I do not get the warning on t[0].

This is a regression. No such problem with GCC 7.2.0, 6.4.0 and 5.4.1.
Comment 1 Marek Polacek 2017-08-25 13:15:23 UTC
Started with r250656.
Comment 2 Marek Polacek 2017-08-25 13:33:47 UTC
Looks like the problem is that since that revision in .uninit there's
UBSAN_PTR (&t, 0);
and so the warning probably thinks that t escapes and so doesn't warn.
Comment 3 Jakub Jelinek 2017-08-29 18:14:27 UTC
Created attachment 42080 [details]
gcc8-pr81981.patch

Untested fix.
Comment 4 Jakub Jelinek 2017-09-04 08:13:11 UTC
Author: jakub
Date: Mon Sep  4 08:11:44 2017
New Revision: 251641

URL: https://gcc.gnu.org/viewcvs?rev=251641&root=gcc&view=rev
Log:
	PR sanitizer/81981
	* gimple-fold.c (gimple_fold_call): Optimize away useless UBSAN_PTR
	and UBSAN_BOUNDS internal calls.  Clean up IFN_UBSAN_OBJECT_SIZE
	handling.  Use replace_call_with_value with NULL instead of
	gsi_replace, unlink_stmt_vdef and release_defs.

	* gcc.dg/ubsan/pr81981.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/ubsan/pr81981.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Jakub Jelinek 2017-09-04 13:22:11 UTC
Fixed.
Comment 6 Jakub Jelinek 2017-10-11 10:38:32 UTC
.