re PR c++/86738 (gcc 8.2: Internal compiler error memcpy)
authorJakub Jelinek <jakub@redhat.com>
Wed, 8 Aug 2018 08:31:40 +0000 (10:31 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Wed, 8 Aug 2018 08:31:40 +0000 (10:31 +0200)
PR c++/86738
* constexpr.c (cxx_eval_binary_expression): For arithmetics involving
NULL pointer set *non_constant_p to true.
(cxx_eval_component_reference): For dereferencing of a NULL pointer,
set *non_constant_p to true and return t.

* g++.dg/opt/pr86738.C: New test.

From-SVN: r263390

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr86738.C [new file with mode: 0644]

index 0d4377c2d6aeb1f4d8054ea33ae16bcaadac26ce..ed3ad71a94ac827461bfedc60338a33e954f5faf 100644 (file)
@@ -1,3 +1,11 @@
+2018-08-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/86738
+       * constexpr.c (cxx_eval_binary_expression): For arithmetics involving
+       NULL pointer set *non_constant_p to true.
+       (cxx_eval_component_reference): For dereferencing of a NULL pointer,
+       set *non_constant_p to true and return t.
+
 2018-08-07  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/59480, DR 136
index 79039ff2b791aea3f05eaa664a90b1820d8fb314..d796e8b1626a4dbb0e3e90aee8b5f4417f89dffb 100644 (file)
@@ -2082,6 +2082,7 @@ cxx_eval_binary_expression (const constexpr_ctx *ctx, tree t,
     {
       if (!ctx->quiet)
        error ("arithmetic involving a null pointer in %qE", lhs);
+      *non_constant_p = true;
       return t;
     }
   else if (code == POINTER_PLUS_EXPR)
@@ -2522,9 +2523,13 @@ cxx_eval_component_reference (const constexpr_ctx *ctx, tree t,
                                             lval,
                                             non_constant_p, overflow_p);
   if (INDIRECT_REF_P (whole)
-      && integer_zerop (TREE_OPERAND (whole, 0))
-      && !ctx->quiet)
-    error ("dereferencing a null pointer in %qE", orig_whole);
+      && integer_zerop (TREE_OPERAND (whole, 0)))
+    {
+      if (!ctx->quiet)
+       error ("dereferencing a null pointer in %qE", orig_whole);
+      *non_constant_p = true;
+      return t;
+    }
 
   if (TREE_CODE (whole) == PTRMEM_CST)
     whole = cplus_expand_constant (whole);
index c4aaa448fa1394b88a98b5c6e8682fb5a3953b4b..6eb02bb3decef86e8b949bbff640beb24480ff7f 100644 (file)
@@ -1,3 +1,8 @@
+2018-08-08  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/86738
+       * g++.dg/opt/pr86738.C: New test.
+
 2018-08-07  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR target/86838
diff --git a/gcc/testsuite/g++.dg/opt/pr86738.C b/gcc/testsuite/g++.dg/opt/pr86738.C
new file mode 100644 (file)
index 0000000..f5079ff
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/86738
+// { dg-do compile }
+
+struct S { int s; };
+unsigned char a[20];
+unsigned char *p = &a[(__UINTPTR_TYPE__) &((S *) 0)->s];
+
+void
+foo ()
+{
+  __builtin_memcpy (&a[15], &a[(__UINTPTR_TYPE__) &((S *) 0)->s], 2);
+}