]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold: DECL_VALUE_EXPR isn't simple [PR120400]
authorJason Merrill <jason@redhat.com>
Fri, 23 May 2025 13:41:25 +0000 (09:41 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 27 May 2025 20:40:40 +0000 (16:40 -0400)
This PR noted that fold_truth_andor was wrongly changing && to & where the
RHS is a VAR_DECL with DECL_VALUE_EXPR; we can't assume that such can be
evaluated unconditionally.

To be more precise we could recurse into DECL_VALUE_EXPR, but that doesn't
seem worth bothering with since typical uses involve a COMPONENT_REF, which
is not simple.

PR c++/120400

gcc/ChangeLog:

* fold-const.cc (simple_operand_p): False for vars with
DECL_VALUE_EXPR.

gcc/fold-const.cc

index 5f48ced50636e760514988ba0c362f27bebd3eee..014f42187932b731f4422bc90f5cb217d39381bd 100644 (file)
@@ -5085,6 +5085,11 @@ simple_operand_p (const_tree exp)
                 #pragma weak, etc).  */
              && ! TREE_PUBLIC (exp)
              && ! DECL_EXTERNAL (exp)
+             /* DECL_VALUE_EXPR will expand to something non-simple.  */
+             && ! ((VAR_P (exp)
+                    || TREE_CODE (exp) == PARM_DECL
+                    || TREE_CODE (exp) == RESULT_DECL)
+                   && DECL_HAS_VALUE_EXPR_P (exp))
              /* Weakrefs are not safe to be read, since they can be NULL.
                 They are !TREE_PUBLIC && !DECL_EXTERNAL but still
                 have DECL_WEAK flag set.  */