From: Richard Biener Date: Fri, 15 Dec 2017 13:43:30 +0000 (+0000) Subject: re PR sanitizer/83388 (reference statement index not found error with -fsanitize... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87a5e0e8c65c0066f497d54e88ff2c1dc6eb3a97;p=gcc.git re PR sanitizer/83388 (reference statement index not found error with -fsanitize=null) 2017-12-15 Richard Biener PR lto/83388 * internal-fn.def (IFN_NOP): Add. * internal-fn.c (expand_NOP): Do nothing. * lto-streamer-in.c (input_function): Instead of removing sanitizer calls replace them with IFN_NOP calls. * gcc.dg/lto/pr83388_0.c: New testcase. From-SVN: r255694 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e83d5beaa1a..3282f489370 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-12-15 Richard Biener + + PR lto/83388 + * internal-fn.def (IFN_NOP): Add. + * internal-fn.c (expand_NOP): Do nothing. + * lto-streamer-in.c (input_function): Instead of removing + sanitizer calls replace them with IFN_NOP calls. + 2017-12-15 Richard Sandiford Alan Hayward David Sherwood diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index 7ddc5246e3c..21e7b104eec 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -2722,6 +2722,14 @@ expand_DIVMOD (internal_fn, gcall *call_stmt) target, VOIDmode, EXPAND_NORMAL); } +/* Expand a NOP. */ + +static void +expand_NOP (internal_fn, gcall *) +{ + /* Nothing. But it shouldn't really prevail. */ +} + /* Expand a call to FN using the operands in STMT. FN has a single output operand and NARGS input operands. */ diff --git a/gcc/internal-fn.def b/gcc/internal-fn.def index d6ab03112b0..07f9208b0ac 100644 --- a/gcc/internal-fn.def +++ b/gcc/internal-fn.def @@ -254,6 +254,9 @@ DEF_INTERNAL_FN (LAUNDER, ECF_LEAF | ECF_NOTHROW | ECF_NOVOPS, NULL) /* Divmod function. */ DEF_INTERNAL_FN (DIVMOD, ECF_CONST | ECF_LEAF, NULL) +/* A NOP function with arbitrary arguments and return value. */ +DEF_INTERNAL_FN (NOP, ECF_CONST | ECF_LEAF | ECF_NOTHROW, NULL) + #undef DEF_INTERNAL_INT_FN #undef DEF_INTERNAL_FLT_FN #undef DEF_INTERNAL_FLT_FLOATN_FN diff --git a/gcc/lto-streamer-in.c b/gcc/lto-streamer-in.c index 9b785ff365d..a313b25907d 100644 --- a/gcc/lto-streamer-in.c +++ b/gcc/lto-streamer-in.c @@ -1136,41 +1136,47 @@ input_function (tree fn_decl, struct data_in *data_in, if (is_gimple_call (stmt) && gimple_call_internal_p (stmt)) { + bool replace = false; switch (gimple_call_internal_fn (stmt)) { case IFN_UBSAN_NULL: if ((flag_sanitize & (SANITIZE_NULL | SANITIZE_ALIGNMENT)) == 0) - remove = true; + replace = true; break; case IFN_UBSAN_BOUNDS: if ((flag_sanitize & SANITIZE_BOUNDS) == 0) - remove = true; + replace = true; break; case IFN_UBSAN_VPTR: if ((flag_sanitize & SANITIZE_VPTR) == 0) - remove = true; + replace = true; break; case IFN_UBSAN_OBJECT_SIZE: if ((flag_sanitize & SANITIZE_OBJECT_SIZE) == 0) - remove = true; + replace = true; break; case IFN_UBSAN_PTR: if ((flag_sanitize & SANITIZE_POINTER_OVERFLOW) == 0) - remove = true; + replace = true; break; case IFN_ASAN_MARK: if ((flag_sanitize & SANITIZE_ADDRESS) == 0) - remove = true; + replace = true; break; case IFN_TSAN_FUNC_EXIT: if ((flag_sanitize & SANITIZE_THREAD) == 0) - remove = true; + replace = true; break; default: break; } - gcc_assert (!remove || gimple_call_lhs (stmt) == NULL_TREE); + if (replace) + { + gimple_call_set_internal_fn (as_a (stmt), + IFN_NOP); + update_stmt (stmt); + } } } if (remove) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8f2075b0ead..1477cabcacb 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-15 Richard Biener + + PR lto/83388 + * gcc.dg/lto/pr83388_0.c: New testcase. + 2017-12-15 Ed Schonberg * gnat.dg/expr_func2.ads, gnat.dg/expr_func2.adb: New testcase. diff --git a/gcc/testsuite/gcc.dg/lto/pr83388_0.c b/gcc/testsuite/gcc.dg/lto/pr83388_0.c new file mode 100644 index 00000000000..4febbac06da --- /dev/null +++ b/gcc/testsuite/gcc.dg/lto/pr83388_0.c @@ -0,0 +1,18 @@ +/* { dg-lto-do link } */ +/* { dg-lto-options { { -O2 -flto -fsanitize=null } { -O0 -flto -fsanitize=null } } } */ +/* { dg-extra-ld-options { -fno-sanitize=null -r -nostdlib } } */ + +enum { a } e(void); +struct C { + int d; +} c; +long f; +void g(long); +static void i(_Bool h) { + struct C *a = ({ ({ &c; }); }); + if (e()) { + int b = a->d; + g(f); + } +} +void j(void) { i(a); }