]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Don't record string concatenation data for 'RESERVED_LOCATION_P'
authorThomas Schwinge <thomas@codesourcery.com>
Fri, 3 Sep 2021 16:25:10 +0000 (18:25 +0200)
committerThomas Schwinge <thomas@codesourcery.com>
Mon, 20 Sep 2021 08:12:47 +0000 (10:12 +0200)
'RESERVED_LOCATION_P' means 'UNKNOWN_LOCATION' or 'BUILTINS_LOCATION'.
We're using 'UNKNOWN_LOCATION' as a spare value for 'Empty', so should
ascertain that we don't use it as a key additionally.  Similarly for
'BUILTINS_LOCATION' that we'd later like to use as a spare value for
'Deleted'.

As discussed in the source code comment added, for these we didn't have
stable behavior anyway.

Follow-up to r239175 (commit 88fa5555a309e5d6c6171b957daaf2f800920869)
"On-demand locations within string-literals".

gcc/
* input.c (string_concat_db::record_string_concatenation)
(string_concat_db::get_string_concatenation): Skip for
'RESERVED_LOCATION_P'.
gcc/testsuite/
* gcc.dg/plugin/diagnostic-test-string-literals-1.c: Adjust
expected error diagnostics.

gcc/input.c
gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c

index 4b809862e02dc78f63572bf78a5fc413a2b99f6e..dd753decfa0d3fa132998700f813f68a9a5f36c8 100644 (file)
@@ -1437,6 +1437,11 @@ string_concat_db::record_string_concatenation (int num, location_t *locs)
   gcc_assert (locs);
 
   location_t key_loc = get_key_loc (locs[0]);
+  /* We don't record data for 'RESERVED_LOCATION_P (key_loc)' key values:
+     any data now recorded under key 'key_loc' would be overwritten by a
+     subsequent call with the same key 'key_loc'.  */
+  if (RESERVED_LOCATION_P (key_loc))
+    return;
 
   string_concat *concat
     = new (ggc_alloc <string_concat> ()) string_concat (num, locs);
@@ -1460,6 +1465,10 @@ string_concat_db::get_string_concatenation (location_t loc,
   gcc_assert (out_locs);
 
   location_t key_loc = get_key_loc (loc);
+  /* We don't record data for 'RESERVED_LOCATION_P (key_loc)' key values; see
+     discussion in 'string_concat_db::record_string_concatenation'.  */
+  if (RESERVED_LOCATION_P (key_loc))
+    return false;
 
   string_concat **concat = m_table->get (key_loc);
   if (!concat)
index 4cba87be2aece08a801e2d7828a9b9e5cc324b7f..8818192eb45435990b96b6ceba50444cd86194d2 100644 (file)
@@ -332,8 +332,8 @@ pr87652 (const char *stem, int counter)
                                OFFSET + end_idx);              \
   } while (0)
 
-/* { dg-error "unable to read substring location: unable to read source line" "" { target c } 329 } */
-/* { dg-error "unable to read substring location: failed to get ordinary maps" "" { target c++ } 329 } */
+/* { dg-error "unable to read substring location: failed to get ordinary maps" "" { target c } 329 } */
+/* { dg-error "unable to read substring location: macro expansion" "" { target c++ } 329 } */
 /* { dg-begin-multiline-output "" }
      __emit_string_literal_range(__FILE__":%5d: " format,        \
                                  ^~~~~~~~