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]

[PATCH][PR sanitizer/80414] Fix segfault with -fsanitize=undefined on 32 bit host


Hello everyone.

I have patch to fix segfault with -fsanitize=undefined on 32 bit host.

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

Can someone please review it.

Thanks.






commit 3bb53510ae11a9fa1f79ae83469c2650abe81ab4
Author: Denis Khalikov <d.khalikov@partner.samsung.com>
Date:   Thu Apr 13 12:03:19 2017 +0300

        PR sanitizer/80414
        * ubsan.c (ubsan_expand_bounds_ifn): Fix wrong tree val generation
        for 32 bit host.
        * c-c++-common/ubsan/bounds-15.c: New test.

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3154103..283dbd6 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2017-04-13  Denis Khalikov <d.khalikov@partner.samsung.com>
+
+	PR sanitizer/80414
+	* ubsan.c (ubsan_expand_bounds_ifn): Fix wrong tree val generation
+	for 32 bit host.
+
 2017-04-12  Jan Hubicka  <hubicka@ucw.cz>
 
 	PR lto/69953 
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b1594f2..fe55233 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2017-04-13  Denis Khalikov  <d.khalikov@partner.samsung.com>
+
+	PR sanitizer/80414
+	* c-c++-common/ubsan/bounds-15.c: New test.
+
 2017-04-12  Jakub Jelinek  <jakub@redhat.com>
 
 	PR tree-optimization/79390
diff --git a/gcc/testsuite/c-c++-common/ubsan/bounds-15.c b/gcc/testsuite/c-c++-common/ubsan/bounds-15.c
new file mode 100644
index 0000000..2af709a
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/ubsan/bounds-15.c
@@ -0,0 +1,11 @@
+/* { dg-do run } */
+/* { dg-options "-fsanitize=bounds" } */
+/* { dg-skip-if "" { *-*-* } { "*" } { "-O0" } } */
+
+int main()
+{
+  long long offset = 10;
+  char array[10];
+  char c = array[offset];
+  return 0;
+}
diff --git a/gcc/ubsan.c b/gcc/ubsan.c
index c01d633..9333336 100644
--- a/gcc/ubsan.c
+++ b/gcc/ubsan.c
@@ -672,7 +672,8 @@ ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi)
 
   /* Pick up the arguments of the UBSAN_BOUNDS call.  */
   tree type = TREE_TYPE (TREE_TYPE (gimple_call_arg (stmt, 0)));
-  tree index = gimple_call_arg (stmt, 1);
+  tree index, orig_index;
+  index = orig_index = gimple_call_arg (stmt, 1);
   tree orig_index_type = TREE_TYPE (index);
   tree bound = gimple_call_arg (stmt, 2);
 
@@ -708,9 +709,9 @@ ubsan_expand_bounds_ifn (gimple_stmt_iterator *gsi)
 	  ? BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS
 	  : BUILT_IN_UBSAN_HANDLE_OUT_OF_BOUNDS_ABORT;
       tree fn = builtin_decl_explicit (bcode);
-      tree val = force_gimple_operand_gsi (gsi, ubsan_encode_value (index),
-					   true, NULL_TREE, true,
-					   GSI_SAME_STMT);
+      tree val
+	= force_gimple_operand_gsi (gsi, ubsan_encode_value (orig_index), true,
+				    NULL_TREE, true, GSI_SAME_STMT);
       g = gimple_build_call (fn, 2, data, val);
     }
   gimple_set_location (g, loc);

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