On Tue, Jan 18, 2022 at 11:17:41AM +0100, Jakub Jelinek via Gcc-patches wrote:
> Anyway, the following has been successfully bootstrapped/regtested on
> x86_64-linux and i686-linux, ok for trunk?

Actually, I missed one regression (thought it is caused by PR104025 patch
but it is this one):
+FAIL: experimental/source_location/1.cc execution test

The test does (in multiple spots):
  VERIFY( loc.file_name() == __FILE__ );
where file_name() is constexpr and returns const char *.
address_compare sees EQ_EXPR where the string literals have exactly the
same bytes, but are different tree nodes.  The test clearly relies on
the string literal merging GCC does...

To restore the previous behavior (note, this was !folding_initializer case),
I need following incremental patch, i.e. make sure I don't change behavior
for the !folding_initializer case.

But, perhaps if we think that different STRING_CSTs with identical
content should compare equal (which is likely true as expand_expr_constant
-> output_constant_def should ensure that), then maybe we should
earlier in address_compare for two different STRING_CSTs that have
the same TREE_STRING_LENGTH memcmp the content and set equal to 0
earlier.  Again, question whether to do that always, or just for
!folding_initializer, or just for folding_initializer.

--- gcc/fold-const.cc.jj        2022-01-18 13:10:56.864364624 +0100
+++ gcc/fold-const.cc   2022-01-18 13:25:08.057491249 +0100
@@ -16627,8 +16627,10 @@ address_compare (tree_code code, tree ty
   else if ((TREE_CODE (base0) == FUNCTION_DECL && ioff0)
           || (TREE_CODE (base1) == FUNCTION_DECL && ioff1))
     return 2;
-  else if ((!DECL_P (base0) && TREE_CODE (base0) != STRING_CST)
-          || (!DECL_P (base1) && TREE_CODE (base1) != STRING_CST))
+  else if ((!DECL_P (base0)
+           && (!folding_initializer || TREE_CODE (base0) != STRING_CST))
+          || (!DECL_P (base1)
+              && (!folding_initializer || TREE_CODE (base1) != STRING_CST)))
     return 2;
   /* If this is a pointer comparison, ignore for now even
      valid equalities where one pointer is the offset zero
@@ -16651,8 +16653,7 @@ address_compare (tree_code code, tree ty
       poly_int64 size0, size1;
       if (TREE_CODE (base0) == STRING_CST)
        {
-         if (!folding_initializer
-             || ioff0 < 0
+         if (ioff0 < 0
              || ioff0 > TREE_STRING_LENGTH (base0))
            return 2;
          size0 = TREE_STRING_LENGTH (base0);
@@ -16673,8 +16674,7 @@ address_compare (tree_code code, tree ty
 
       if (TREE_CODE (base1) == STRING_CST)
        {
-         if (!folding_initializer
-             || ioff1 < 0
+         if (ioff1 < 0
              || ioff1 > TREE_STRING_LENGTH (base1))
            return 2;
          size1 = TREE_STRING_LENGTH (base1);


        Jakub

Reply via email to