re PR sanitizer/83388 (reference statement index not found error with -fsanitize...
authorRichard Biener <rguenther@suse.de>
Fri, 15 Dec 2017 13:43:30 +0000 (13:43 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 15 Dec 2017 13:43:30 +0000 (13:43 +0000)
2017-12-15  Richard Biener  <rguenther@suse.de>

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

gcc/ChangeLog
gcc/internal-fn.c
gcc/internal-fn.def
gcc/lto-streamer-in.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/lto/pr83388_0.c [new file with mode: 0644]

index e83d5beaa1a03671056e909440a8e2728ff0bbce..3282f489370807c3a96c7f2181dcd23beb95e497 100644 (file)
@@ -1,3 +1,11 @@
+2017-12-15  Richard Biener  <rguenther@suse.de>
+
+       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  <richard.sandiford@linaro.org>
            Alan Hayward  <alan.hayward@arm.com>
            David Sherwood  <david.sherwood@arm.com>
index 7ddc5246e3ccda0bb8d9dd5ba555ed22c24e0ca6..21e7b104eec3b38e4ee683e6bae60c7366190492 100644 (file)
@@ -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.  */
 
index d6ab03112b00dd9f928a98342536dd0273950fc1..07f9208b0acdf04a540c6fcf92bb0e49bc785156 100644 (file)
@@ -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
index 9b785ff365d75c27839dfbabf96a239de7ee81d6..a313b25907d71a1f5a35a9e85f686833d9c9a5fd 100644 (file)
@@ -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 <gcall *> (stmt),
+                                                  IFN_NOP);
+                     update_stmt (stmt);
+                   }
                }
            }
          if (remove)
index 8f2075b0eadeef4fbb402d5bb91c8658eeacff3f..1477cabcacbf039b748ed6cd09e9300fbad00da1 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-15  Richard Biener  <rguenther@suse.de>
+
+       PR lto/83388
+       * gcc.dg/lto/pr83388_0.c: New testcase.
+
 2017-12-15  Ed Schonberg  <schonberg@adacore.com>
 
        * 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 (file)
index 0000000..4febbac
--- /dev/null
@@ -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); }