re PR tree-optimization/65709 (Bad code for LZ4 decompression with -O3 on x86_64)
authorJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Apr 2015 19:51:08 +0000 (21:51 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 9 Apr 2015 19:51:08 +0000 (21:51 +0200)
PR tree-optimization/65709
* ubsan.c (instrument_mem_ref): Use TREE_TYPE (base) instead of
TREE_TYPE (TREE_TYPE (t)).

* c-c++-common/ubsan/align-9.c: New test.

From-SVN: r221958

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/ubsan/align-9.c [new file with mode: 0644]
gcc/ubsan.c

index 17fe5a153e29406fc0d092e2758d17b2151d71d1..cedbd18db9d493541ed597b2b660fc22b7557cd0 100644 (file)
@@ -1,3 +1,9 @@
+2015-04-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/65709
+       * ubsan.c (instrument_mem_ref): Use TREE_TYPE (base) instead of
+       TREE_TYPE (TREE_TYPE (t)).
+
 2015-04-09  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR target/65710
index da590b1a389c353257ee668a4258158ffbd65873..4be085d3bbe018d6d4545da83abaec42a9c66f26 100644 (file)
@@ -1,7 +1,12 @@
+2015-04-09  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/65709
+       * c-c++-common/ubsan/align-9.c: New test.
+
 2013-04-09  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/56852
-       * gfortran.dg/pr56852.f90 : New test
+       * gfortran.dg/pr56852.f90: New test.
 
 2015-04-09  Marek Polacek  <polacek@redhat.com>
            Jakub Jelinek  <jakub@redhat.com>
diff --git a/gcc/testsuite/c-c++-common/ubsan/align-9.c b/gcc/testsuite/c-c++-common/ubsan/align-9.c
new file mode 100644 (file)
index 0000000..24cba94
--- /dev/null
@@ -0,0 +1,21 @@
+/* Limit this to known non-strict alignment targets.  */
+/* { dg-do run { target { i?86-*-linux* x86_64-*-linux* } } } */
+/* { dg-options "-O2 -fsanitize=alignment -fsanitize-recover=alignment" } */
+
+__attribute__((noinline, noclone)) void
+foo (void *p, const void *q)
+{
+  *(long int *) p = *(const long int *) q;
+}
+
+int
+main ()
+{
+  struct S { long c; char f[64]; char d; char e[2 * sizeof (long)]; char g[64]; } s;
+  __builtin_memset (&s, '\0', sizeof s);
+  foo (&s.e[0], &s.e[sizeof (long)]);
+  return 0;
+}
+
+/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*load of misaligned address 0x\[0-9a-fA-F]* for type 'const long int', which requires \[48] byte alignment.*" } */
+/* { dg-output "\.c:8:\[0-9]*: \[^\n\r]*store to misaligned address 0x\[0-9a-fA-F]* for type 'long int', which requires \[48] byte alignment" } */
index b9d9f30e66028f735fcf949072f5b691039c3581..701e9f292289ba48d3ab03af8e5e7e5abb51438d 100644 (file)
@@ -1232,9 +1232,9 @@ instrument_mem_ref (tree mem, tree base, gimple_stmt_iterator *iter,
   tree t = TREE_OPERAND (base, 0);
   if (!POINTER_TYPE_P (TREE_TYPE (t)))
     return;
-  if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (TREE_TYPE (t))) && mem != base)
+  if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (base)) && mem != base)
     ikind = UBSAN_MEMBER_ACCESS;
-  tree kind = build_int_cst (TREE_TYPE (t), ikind);
+  tree kind = build_int_cst (build_pointer_type (TREE_TYPE (base)), ikind);
   tree alignt = build_int_cst (pointer_sized_int_node, align);
   gcall *g = gimple_build_call_internal (IFN_UBSAN_NULL, 3, t, kind, alignt);
   gimple_set_location (g, gimple_location (gsi_stmt (*iter)));