]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/38705 (ICE: canonical types differ for identical types const int and const...
authorJakub Jelinek <jakub@redhat.com>
Sat, 3 Jan 2009 00:54:40 +0000 (01:54 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 3 Jan 2009 00:54:40 +0000 (01:54 +0100)
PR c++/38705
* builtins.c (fold_builtin_memory_op): Give up if either operand
is volatile.  Set srctype or desttype to non-qualified version
of the other type.

* g++.dg/torture/pr38705.C: New test.

From-SVN: r143029

gcc/ChangeLog
gcc/builtins.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/torture/pr38705.C [new file with mode: 0644]

index 59808900dab3f12cd855c6c74b74d15782d17185..5f6b8d1d11c9971477916bc417343add393a03ad 100644 (file)
@@ -1,5 +1,10 @@
 2009-01-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/38705
+       * builtins.c (fold_builtin_memory_op): Give up if either operand
+       is volatile.  Set srctype or desttype to non-qualified version
+       of the other type.
+
        PR c/38700
        * builtins.c (fold_builtin_expect): Only check DECL_WEAK for VAR_DECLs
        and FUNCTION_DECLs.
index cda94c3cbc06461fa6471ec695a4c5c542e55a4e..57cce08abe53a5b02d28349ad594a361b380b8d1 100644 (file)
@@ -8907,7 +8907,9 @@ fold_builtin_memory_op (tree dest, tree src, tree len, tree type, bool ignore, i
          || !TYPE_SIZE_UNIT (srctype)
          || !TYPE_SIZE_UNIT (desttype)
          || TREE_CODE (TYPE_SIZE_UNIT (srctype)) != INTEGER_CST
-         || TREE_CODE (TYPE_SIZE_UNIT (desttype)) != INTEGER_CST)
+         || TREE_CODE (TYPE_SIZE_UNIT (desttype)) != INTEGER_CST
+         || TYPE_VOLATILE (srctype)
+         || TYPE_VOLATILE (desttype))
        return NULL_TREE;
 
       src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT);
@@ -8924,7 +8926,7 @@ fold_builtin_memory_op (tree dest, tree src, tree len, tree type, bool ignore, i
        {
          srcvar = build_fold_indirect_ref (src);
          if (TREE_THIS_VOLATILE (srcvar))
-           srcvar = NULL_TREE;
+           return NULL_TREE;
          else if (!tree_int_cst_equal (lang_hooks.expr_size (srcvar), len))
            srcvar = NULL_TREE;
          /* With memcpy, it is possible to bypass aliasing rules, so without
@@ -8942,7 +8944,7 @@ fold_builtin_memory_op (tree dest, tree src, tree len, tree type, bool ignore, i
        {
          destvar = build_fold_indirect_ref (dest);
          if (TREE_THIS_VOLATILE (destvar))
-           destvar = NULL_TREE;
+           return NULL_TREE;
          else if (!tree_int_cst_equal (lang_hooks.expr_size (destvar), len))
            destvar = NULL_TREE;
          else if (!var_decl_component_p (destvar))
@@ -8958,7 +8960,7 @@ fold_builtin_memory_op (tree dest, tree src, tree len, tree type, bool ignore, i
          if (TREE_ADDRESSABLE (TREE_TYPE (destvar)))
            return NULL_TREE;
 
-         srctype = desttype;
+         srctype = build_qualified_type (desttype, 0);
          if (src_align < (int) TYPE_ALIGN (srctype))
            {
              if (AGGREGATE_TYPE_P (srctype)
@@ -8980,7 +8982,7 @@ fold_builtin_memory_op (tree dest, tree src, tree len, tree type, bool ignore, i
          if (TREE_ADDRESSABLE (TREE_TYPE (srcvar)))
            return NULL_TREE;
 
-         desttype = srctype;
+         desttype = build_qualified_type (srctype, 0);
          if (dest_align < (int) TYPE_ALIGN (desttype))
            {
              if (AGGREGATE_TYPE_P (desttype)
index 4a0c0c64cfa847f7b5eb0df6f1d289083b6781a0..5f1c4228f26b83b187c101098c3e8093da92cd26 100644 (file)
@@ -1,5 +1,8 @@
 2009-01-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/38705
+       * g++.dg/torture/pr38705.C: New test.
+
        PR c/38700
        * gcc.dg/pr38700.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/torture/pr38705.C b/gcc/testsuite/g++.dg/torture/pr38705.C
new file mode 100644 (file)
index 0000000..8058d3a
--- /dev/null
@@ -0,0 +1,27 @@
+// PR c++/38705
+// { dg-do compile }
+
+typedef int T;
+typedef __SIZE_TYPE__ size_t;
+extern "C" void *memcpy (void *, const void *, size_t);
+
+void
+foo (char *p, const int q)
+{
+  memcpy (p, &q, sizeof (int));
+}
+
+struct S
+{
+  T t;
+  int u;
+  int bar () const;
+  template <class T> void foo (const T &x) const {}
+};
+
+int
+S::bar () const
+{
+  foo (u);
+  foo (t);
+}