On 1/11/24 15:34, Dmitry Drozodv wrote:
You are absolutely right, we can't throw all side-effects away.

+      /* C++ [conv.lval]p3:
+        If T is cv std::nullptr_t, the result is a null pointer constant. */
+      return ((TREE_SIDE_EFFECTS (expr) && !CONVERT_EXPR_P (expr))
+              ? build2 (COMPOUND_EXPR, type, expr, val)
+              : val);

This seems to assume that a CONVERT_EXPR can't have any other side-effects nested in it.

It seems to me a better approach is the one in keep_unused_object_arg and cp_gimplify_expr, basically

if (TREE_THIS_VOLATILE (e))
  e = cp_build_addr_expr (e);

since the address of a volatile lvalue is safe to put on the lhs of a COMPOUND_EXPR.

-      if (!TREE_SIDE_EFFECTS (e))
+      /* C++ [conv.lval]p3:
+        Convert expr from nullptr to nullptr doesn't have side effect. */
+      if (!TREE_SIDE_EFFECTS (e) || CONVERT_EXPR_P (expr))

I don't see why ocp_convert needs to change at all; if TREE_SIDE_EFFECTS is set we'll eventually get to cp_convert_to_pointer and can do the right thing there.

@@ -770,6 +770,15 @@ split_nonconstant_init (tree dest, tree init)
            && array_of_runtime_bound_p (TREE_TYPE (dest)))
      code = build_vec_init (dest, NULL_TREE, init, /*value-init*/false,
                            /*from array*/1, tf_warning_or_error);
+  else if (TREE_CODE (TREE_TYPE(init)) == NULLPTR_TYPE)
+    {
+      /* C++ [conv.lval]p3:
+        If T is cv std::nullptr_t, the result is a null pointer constant. */
+      tree val = build_int_cst(TREE_TYPE(dest), 0);
+      tree ie = cp_build_init_expr(dest, val);

Why not just

DECL_INITIAL (dest) = nullptr_node;

?

Also, your mail client is mangling your patch so it doesn't apply properly. Please see https://gcc.gnu.org/contribute.html for more information.

Jason

Reply via email to