This is the mail archive of the gcc-bugs@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]

[Bug sanitizer/71962] error: ‘((& x) != 0u)’ is not a constant expression


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71962

--- Comment #8 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #7)

The null pointer check inserted by the sanitizer is eventually removed (see
below) so there's obviously no point in emitting it to begin with.  The DSP
case you mention simply isn't important to worry about, and certainly not worth
pessimizing the common case for.  If there really were a need to handle this
corner case then it should be provided as a separate feature, under its own
option, and be disabled by default (even with -fsantize=undefined).  It should
also be tested, which judging by the absence of test suite failures with the
patch, it currently isn't.

$ cat a.C && gcc -O2 -S -Wall -Wpedantic -fsanitize=undefined
-fdump-tree-ubsan=/dev/stdout -fdump-tree-optimized=/dev/stdout a.C
int f ()
{
  static int i = 1;

  int *p = &i;

  return *p;
}


;; Function int f() (_Z1fv, funcdef_no=0, decl_uid=2604, cgraph_uid=0,
symbol_order=1)

Introduced new external node (long unsigned int __builtin_object_size(const
void*, int)/2).

Symbols to be put in SSA form
{ D.2610 }
Incremental SSA update started at block: 0
Number of blocks in CFG: 3
Number of blocks to update: 2 ( 67%)


int f() ()
{
  int * p;
  static int i = 1;
  int _3;
  long unsigned int _4;

  <bb 2> [0.00%] [count: INV]:
  p_1 = &i;
  UBSAN_NULL (p_1, 0B, 4);
  _4 = __builtin_object_size (p_1, 0);
  UBSAN_OBJECT_SIZE (p_1, 4, _4, 0);
  _3 = *p_1;
  return _3;

}



;; Function int f() (_Z1fv, funcdef_no=0, decl_uid=2604, cgraph_uid=0,
symbol_order=1)

Removing basic block 4
Merging blocks 2 and 3
int f() ()
{
  static int i = 1;
  int _2;

  <bb 2> [100.00%] [count: INV]:
  _2 = i;
  return _2;

}

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