diff mbox series

[COMMITTED] c++: Use constexpr to avoid wrong -Wsign-compare

Message ID 5acf75ee-83a2-b321-e564-9fea4ed89612@redhat.com
State New
Headers show
Series [COMMITTED] c++: Use constexpr to avoid wrong -Wsign-compare | expand

Commit Message

Jason Merrill Feb. 8, 2020, 4:14 p.m. UTC
We would like to do constexpr evaluation to avoid false positives on 
warnings, but constexpr evaluation can involve function body copying 
that changes DECL_UID, which breaks -fcompare-debug.  In the PR Jakub 
suggested that one possibility would be to avoid operations that might 
affect DECL_UID; this patch implements that suggestion.

The other three patches are to avoid regressions from this change.
We recently started unsharing values we find in cv_cache, but we 
shouldn't do that if it's the same as the argument.  No longer unsharing 
regresses the diagnostic locations in decomp48.C.  And the digest_init 
patch avoids a regression on desig14.C.

All tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox series

Patch

From 77840fd9056d8cc9dd5913ac5b9b366da3cf1008 Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Fri, 7 Feb 2020 16:10:18 -0500
Subject: [PATCH 1/4] c++: Fix TREE_SIDE_EFFECTS after digest_init.
To: gcc-patches@gcc.gnu.org

	* typeck2.c (process_init_constructor): Also clear TREE_SIDE_EFFECTS
	if appropriate.
---
 gcc/cp/typeck2.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 371b203c29b..48920894b3b 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1929,11 +1929,15 @@  process_init_constructor (tree type, tree init, int nested, int flags,
       TREE_SIDE_EFFECTS (init) = true;
     }
   else if (picflags & PICFLAG_NOT_ALL_CONSTANT)
-    /* Make sure TREE_CONSTANT isn't set from build_constructor.  */
-    TREE_CONSTANT (init) = false;
+    {
+      /* Make sure TREE_CONSTANT isn't set from build_constructor.  */
+      TREE_CONSTANT (init) = false;
+      TREE_SIDE_EFFECTS (init) = false;
+    }
   else
     {
       TREE_CONSTANT (init) = 1;
+      TREE_SIDE_EFFECTS (init) = false;
       if (!(picflags & PICFLAG_NOT_ALL_SIMPLE))
 	TREE_STATIC (init) = 1;
     }
-- 
2.18.1