Fix not caught use-after-scope with -O1 (PR sanitize/78106)
authorMartin Liska <mliska@suse.cz>
Tue, 25 Oct 2016 14:16:10 +0000 (16:16 +0200)
committerMartin Liska <marxin@gcc.gnu.org>
Tue, 25 Oct 2016 14:16:10 +0000 (14:16 +0000)
PR sanitizer/78106
* sanopt.c (imm_dom_path_with_freeing_call): Handle gasm
statements as they can also contain possibly a freeing call.
PR sanitizer/78106
* gcc.dg/asan/pr78106.c: New test.

From-SVN: r241511

gcc/ChangeLog
gcc/sanopt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/asan/pr78106.c [new file with mode: 0644]

index e0601576db7ca09f1c6e37b54ef1d23048f3b186..65483863f7151b12cbe7fac1dae041b4076107ff 100644 (file)
@@ -1,3 +1,9 @@
+2016-10-25  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/78106
+       * sanopt.c (imm_dom_path_with_freeing_call): Handle gasm
+       statements as they can also contain possibly a freeing call.
+
 2016-10-25  H.J. Lu  <hongjiu.lu@intel.com>
            Martin Liska  <mliska@suse.cz>
 
index 27c43da539f92ac59a7abc1d011f00bab3109356..8a6fbe9da9513d0a83a6defb0656c173086431d8 100644 (file)
@@ -211,8 +211,12 @@ imm_dom_path_with_freeing_call (basic_block bb, basic_block dom)
       for (gsi = gsi_start_bb (e->src); !gsi_end_p (gsi); gsi_next (&gsi))
        {
          gimple *stmt = gsi_stmt (gsi);
+         gasm *asm_stmt;
 
-         if (is_gimple_call (stmt) && !nonfreeing_call_p (stmt))
+         if ((is_gimple_call (stmt) && !nonfreeing_call_p (stmt))
+             || ((asm_stmt = dyn_cast <gasm *> (stmt))
+                 && (gimple_asm_clobbers_memory_p (asm_stmt)
+                     || gimple_asm_volatile_p (asm_stmt))))
            {
              pred_info->has_freeing_call_p = true;
              break;
index c7c233f6c920f32fc607df4947616d211fb945f0..edc026eb44fc75b75ea82a81be3d7ba84b5f1c7b 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-25  Martin Liska  <mliska@suse.cz>
+
+       PR sanitizer/78106
+       * gcc.dg/asan/pr78106.c: New test.
+
 2016-10-25  Martin Liska  <mliska@suse.cz>
 
        * gcc.dg/ipa/ipa-icf-32.c: Removed one scanned pattern.
diff --git a/gcc/testsuite/gcc.dg/asan/pr78106.c b/gcc/testsuite/gcc.dg/asan/pr78106.c
new file mode 100644 (file)
index 0000000..d333f9b
--- /dev/null
@@ -0,0 +1,31 @@
+/* PR sanitizer/78106 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=address -fdump-tree-sanopt-details" } */
+
+int *variable;
+
+void __attribute__((used)) release()
+{
+  __builtin_free (variable);
+}
+
+int main2(int argc)
+{
+  *variable = 2;
+
+  if (argc <= 5)
+    asm volatile ("call release");
+
+  *variable = 2;
+  __builtin_abort ();
+
+  return 0;
+}
+
+int main(int argc, char **argv)
+{
+  variable = __builtin_malloc (sizeof(int));
+  return main2(argc);
+}
+
+/* { dg-final { scan-tree-dump-not "Optimizing out(\n|\r\n|\r)  ASAN_CHECK \\(7, variable.*" "sanopt" } } */