re PR sanitizer/63690 (ICE: tree check: expected class 'expression', have 'constant...
authorMarek Polacek <polacek@redhat.com>
Wed, 19 Nov 2014 14:32:02 +0000 (14:32 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Wed, 19 Nov 2014 14:32:02 +0000 (14:32 +0000)
PR sanitizer/63690
* ubsan.c (instrument_object_size): Check for MEM_REF.

* gcc.dg/ubsan/pr63690.c: New test.

From-SVN: r217778

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/ubsan/pr63690.c [new file with mode: 0644]
gcc/ubsan.c

index 6e1f93069c19f82eff3e231578c4ca709fbfc7d2..2c13f13e4a26200dc5bcdf0a0a2dc01f43fbe7f7 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-19  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/63690
+       * ubsan.c (instrument_object_size): Check for MEM_REF.
+
 2014-11-19  Ilya Verbin  <ilya.verbin@intel.com>
 
        PR regression/63868
index 93d00115079b37e6e6cfec2ebc1d3fcefb1a7fdc..1f25b0ba5a3ca1091c651fa35181f4b34bf289e7 100644 (file)
@@ -1,3 +1,8 @@
+2014-11-19  Marek Polacek  <polacek@redhat.com>
+
+       PR sanitizer/63690
+       * gcc.dg/ubsan/pr63690.c: New test.
+
 2014-11-19  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR sanitizer/62132
diff --git a/gcc/testsuite/gcc.dg/ubsan/pr63690.c b/gcc/testsuite/gcc.dg/ubsan/pr63690.c
new file mode 100644 (file)
index 0000000..be8600f
--- /dev/null
@@ -0,0 +1,18 @@
+/* PR sanitizer/63690 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+void
+foo (void)
+{
+  (*"c")++;
+}
+/* PR sanitizer/63690 */
+/* { dg-do compile } */
+/* { dg-options "-fsanitize=undefined" } */
+
+void
+foo (void)
+{
+  (*"c")++;
+}
index 7d1e341812ceeb118b6e5725de1aa9d9b210e3b0..ad5665ff0477f730f8b724b6cd48f65b80ebaef2 100644 (file)
@@ -1539,7 +1539,13 @@ instrument_object_size (gimple_stmt_iterator *gsi, bool is_lhs)
     return;
 
   bool decl_p = DECL_P (inner);
-  tree base = decl_p ? inner : TREE_OPERAND (inner, 0);
+  tree base;
+  if (decl_p)
+    base = inner;
+  else if (TREE_CODE (inner) == MEM_REF)
+    base = TREE_OPERAND (inner, 0);
+  else
+    return;
   tree ptr = build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (t)), t);
 
   while (TREE_CODE (base) == SSA_NAME)