This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] fix powerpc64le bootstrap failure caused by r243661 (PR 78817)


On 12/19/2016 10:31 AM, Jeff Law wrote:
On 12/17/2016 02:55 PM, Martin Sebor wrote:
On 12/17/2016 01:01 PM, Markus Trippelsdorf wrote:

I agree that these warnings should probably not be issued, though
it's interesting to see where they come from.  The calls are in
the code emitted by GCC, are reachable, and end up taking place
with the right Ubsan runtime recovery options.  It turns out that
Ubsan transforms calls to nonnull functions into conditional
branches testing the argument for null, like so:

    if (s == 0)
      __builtin___ubsan_handle_nonnull_arg();
    n = strlen (s);

and GCC then transforms those into

    if (s == 0)
      {
        __builtin___ubsan_handle_nonnull_arg();
        n = strlen (NULL);
      }

When the ubsan_handle_nonnull_arg function returns to the caller
the call to strlen(NULL) is made.
So I'd like to see more complete dumps here.

The -Wnonnull warning can be reproduced with this C test case and
-fsantize=undefined:

  char* f (const char *s)
  {
    unsigned n = __builtin_strlen (s) + 1;
    char *d = __builtin_malloc (n);

    if (!d)
      return 0;

    __builtin_memcpy (d, s, n);
    return d;
  }

The sanitizer emits the following code (I snipped the rest after
the call to malloc):

  <bb 2> [0.00%]:
  if (s_8(D) == 0B)
    goto <bb 7>; [0.04%]
  else
    goto <bb 6>; [99.96%]

  <bb 7> [0.00%]:
  __builtin___ubsan_handle_nonnull_arg (&*.Lubsan_data0);

  <bb 6> [0.00%]:
  _1 = __builtin_strlen (s_8(D));
  _2 = (unsigned int) _1;
  n_9 = _2 + 1;
  _3 = (long unsigned int) n_9;
  d_11 = __builtin_malloc (_3);
  ...

This is then transformed by the third thread jumping pass into:

  <bb 2> [100.00%]:
  if (s_7(D) == 0B)
    goto <bb 3>; [0.04%]
  else
    goto <bb 8>; [99.96%]

  <bb 3> [0.04%]:
  __builtin___ubsan_handle_nonnull_arg (&*.Lubsan_data0);
  _24 = __builtin_strlen (0B);
  _25 = (unsigned int) _24;
  n_26 = _25 + 1;
  _27 = (long unsigned int) n_26;
  d_29 = __builtin_malloc (_27);
  if (d_29 == 0B)
    goto <bb 4>; [4.07%]
  else
    goto <bb 5>; [95.93%]

  <bb 4> [4.07%]:
  goto <bb 7>; [100.00%]

  <bb 5> [0.04%]:
  __builtin___ubsan_handle_nonnull_arg (&*.Lubsan_data2);

  <bb 6> [95.93%]:
  # _30 = PHI <_19(8), _27(5)>
  # d_31 = PHI <d_22(8), d_29(5)>
  __builtin_memcpy (d_31, s_7(D), _30);

  <bb 7> [100.00%]:
  # _4 = PHI <0B(4), d_31(6)>
  return _4;

  <bb 8> [99.96%]:
  _16 = __builtin_strlen (s_7(D));
  _21 = (unsigned int) _16;
  n_20 = _21 + 1;
  _19 = (long unsigned int) n_20;
  d_22 = __builtin_malloc (_19);
  if (d_22 == 0B)
    goto <bb 4>; [4.07%]
  else
    goto <bb 6>; [95.93%]

(If you'd like to see more context please let me know.)

Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]