]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Support for 64-bit location_t: Activate 64-bit location_t
authorLewis Hyatt <lhyatt@gmail.com>
Sat, 16 Nov 2024 18:45:22 +0000 (13:45 -0500)
committerLewis Hyatt <lhyatt@gcc.gnu.org>
Sun, 8 Dec 2024 15:32:27 +0000 (10:32 -0500)
Change location_t to be a 64-bit integer instead of a 32-bit integer in
libcpp.

Also included in this change are the two other patches in the original
series which depended on this one; I am committing them all at once in case
it needs to be reverted later:

-Support for 64-bit location_t: gimple parts

The size of struct gimple increased by 8 bytes with the change in size of
location_t from 32- to 64-bit; adjust the WORD markings in the comments
accordingly. It seems that most of the WORD markings were off by one already,
probably not having been updated after a previous reduction in the size of a
gimple, so they have become retroactively correct again, and only a couple
needed adjustment actually.

Also add a comment that there is now 32 bits of unused padding available in
struct gimple for 64-bit hosts.

-Support for 64-bit location_t: Remove -flarge-source-files

The option -flarge-source-files became unnecessary with 64-bit location_t
and harms performance compared to the new default setting, so silently
ignore it.

libcpp/ChangeLog:

* include/cpplib.h (struct cpp_token): Adjust comment about the
struct size.
* include/line-map.h (location_t): Change typedef from 32-bit to 64-bit
integer.
(LINE_MAP_MAX_COLUMN_NUMBER): Increase size to be appropriate for
64-bit location_t.
(LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES): Likewise.
(LINE_MAP_MAX_LOCATION_WITH_COLS): Likewise.
(LINE_MAP_MAX_LOCATION): Likewise.
(MAX_LOCATION_T): Likewise.
(line_map_suggested_range_bits): Likewise.
(struct line_map): Adjust comment about the struct size.
(struct line_map_macro): Likewise.
(struct line_map_ordinary): Likewise. Rearrange fields to optimize
padding.

gcc/testsuite/ChangeLog:

* g++.dg/diagnostic/pr77949.C: Adapt the test for 64-bit location_t,
when the previously expected failure doesn't actually happen.
* g++.dg/modules/loc-prune-4.C: Adjust the expected output for the
64-bit location_t case.
* gcc.dg/plugin/expensive_selftests_plugin.cc: Don't try to test
the maximum supported column number in 64-bit location_t mode.
* gcc.dg/plugin/location_overflow_plugin.cc: Adjust the base_location
so it can effectively test 64-bit location_t.

gcc/ChangeLog:

* gimple.h (struct gphi): Update word marking comments to reflect
the new size of location_t.
(struct gimple): Likewise. Add a comment about padding.
* common.opt: Mark -flarge-source-files as Ignored.
* common.opt.urls: Regenerate.
* doc/invoke.texi: Remove -flarge-source-files.
* toplev.cc (process_options): Remove support for
-flarge-source-files.

gcc/common.opt
gcc/common.opt.urls
gcc/doc/invoke.texi
gcc/gimple.h
gcc/testsuite/g++.dg/diagnostic/pr77949.C
gcc/testsuite/g++.dg/modules/loc-prune-4.C
gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc
gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc
gcc/toplev.cc
libcpp/include/cpplib.h
libcpp/include/line-map.h

index a42537c5f1edece906093c50d050db19a004319c..dc39f164facc3e7887f0d3909be14b50dd3314fa 100644 (file)
@@ -1808,9 +1808,8 @@ Common Undocumented Var(flag_keep_gc_roots_live) Optimization
 ; Always keep a pointer to a live memory block
 
 flarge-source-files
-Common Var(flag_large_source_files) Init(0)
-Improve GCC's ability to track column numbers in large source files,
-at the expense of slower compilation.
+Common Ignore
+Does nothing.  Preserved for backward compatibility.
 
 flate-combine-instructions
 Common Var(flag_late_combine_instructions) Optimization Init(0)
index 01033a90795b04dbb4424556c861b9a410a22149..773c021dd9427449cd84d870b8a4e7f6a3f9b1a5 100644 (file)
@@ -721,9 +721,6 @@ UrlSuffix(gcc/Optimize-Options.html#index-fgraphite-identity)
 fhoist-adjacent-loads
 UrlSuffix(gcc/Optimize-Options.html#index-fhoist-adjacent-loads)
 
-flarge-source-files
-UrlSuffix(gcc/Preprocessor-Options.html#index-flarge-source-files)
-
 flate-combine-instructions
 UrlSuffix(gcc/Optimize-Options.html#index-flate-combine-instructions)
 
index 57b6ca126400ac9c9cb21433f9a4ccc81d9662e7..daab28908684fd354d483318178fa86a437dd7e0 100644 (file)
@@ -693,7 +693,7 @@ Objective-C and Objective-C++ Dialects}.
 -dD  -dI  -dM  -dN  -dU
 -fdebug-cpp  -fdirectives-only  -fdollars-in-identifiers
 -fexec-charset=@var{charset}  -fextended-identifiers
--finput-charset=@var{charset}  -flarge-source-files
+-finput-charset=@var{charset}
 -fmacro-prefix-map=@var{old}=@var{new} -fmax-include-depth=@var{depth}
 -fno-canonical-system-headers  -fpch-deps  -fpch-preprocess
 -fpreprocessed  -ftabstop=@var{width}  -ftrack-macro-expansion
@@ -18777,21 +18777,6 @@ This option may be useful in conjunction with the @option{-B} or
 perform additional processing of the program source between
 normal preprocessing and compilation.
 
-@opindex flarge-source-files
-@item -flarge-source-files
-Adjust GCC to expect large source files, at the expense of slower
-compilation and higher memory usage.
-
-Specifically, GCC normally tracks both column numbers and line numbers
-within source files and it normally prints both of these numbers in
-diagnostics.  However, once it has processed a certain number of source
-lines, it stops tracking column numbers and only tracks line numbers.
-This means that diagnostics for later lines do not include column numbers.
-It also means that options like @option{-Wmisleading-indentation} cease to work
-at that point, although the compiler prints a note if this happens.
-Passing @option{-flarge-source-files} significantly increases the number
-of source lines that GCC can process before it stops tracking columns.
-
 @end table
 
 @node Assembler Options
index 039ed66eab5d93c48c0cc5ee38c673029580330d..fbd3c1b1e4704d12f2d7421e0b1e81c665873bb7 100644 (file)
@@ -259,23 +259,26 @@ struct GTY((desc ("gimple_statement_structure (&%h)"), tag ("GSS_BASE"),
      in there.  */
   unsigned int subcode         : 16;
 
-  /* UID of this statement.  This is used by passes that want to
-     assign IDs to statements.  It must be assigned and used by each
-     pass.  By default it should be assumed to contain garbage.  */
+  /* UID of this statement.  This is used by passes that want to assign IDs
+     to statements.  It must be assigned and used by each pass.  By default
+     it should be assumed to contain garbage.  */
   unsigned uid;
 
   /* [ WORD 2 ]
-     Locus information for debug info.  */
-  location_t location;
-
-  /* Number of operands in this tuple.  */
+     Number of operands in this tuple.  */
   unsigned num_ops;
 
+  /* Unused 32 bits padding on 64-bit hosts.  */
+
   /* [ WORD 3 ]
+     Locus information for debug info.  */
+  location_t location;
+
+  /* [ WORD 4 ]
      Basic block holding this statement.  */
   basic_block bb;
 
-  /* [ WORD 4-5 ]
+  /* [ WORD 5-6 ]
      Linked lists of gimple statements.  The next pointers form
      a NULL terminated list, the prev pointers are a cyclic list.
      A gimple statement is hence also a double-ended list of
@@ -479,7 +482,7 @@ struct GTY((tag("GSS_PHI")))
   /* [ WORD 8 ]  */
   tree result;
 
-  /* [ WORD 9 ]  */
+  /* [ WORD 9-14 ]  */
   struct phi_arg_d GTY ((length ("%h.nargs"))) args[1];
 };
 
index b81d6e2bb46d989cebefc53a0e7fc9620e730c1d..e1a201e52c04228de990b30f8daeacd1b857c023 100644 (file)
@@ -1,7 +1,10 @@
-// Ensure that no fix-it hints are emitted
+// Ensure that fix-it hints are emitted even at a large column number.
 // { dg-options "-fdiagnostics-parseable-fixits" }
 
 /* Very long line, where a missing semicolon would be suggested for
    insertion at column 4097.  */
 class test {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   }   
 // { dg-error "-: expected .;. after class definition" "" { target *-*-* } .-1 }
+/* { dg-begin-multiline-output "" }
+fix-it:
+{ dg-end-multiline-output "" }  */
index aa8f248b52bd135c4975c1f36dce873f34697cdb..19e85d8d8a6ff36c18f71e2fcf197cdbe524b51c 100644 (file)
@@ -16,7 +16,7 @@ int bar (int); // merge lines
 int baz (int);
 
 
-// { dg-final { scan-lang-dump {Ordinary maps:2 locs:12288 range_bits:5} module } }
+// { dg-final { scan-lang-dump {Ordinary maps:2 locs:49152 range_bits:7} module } }
 // { dg-final { scan-lang-dump { 1 source file names\n Source file...=[^\n]*loc-prune-4.C\n} module } }
-// { dg-final { scan-lang-dump { Span:0 ordinary \[[0-9]+\+12288,\+4096\)->\[0,\+4096\)} module } }
-// { dg-final { scan-lang-dump { Span:1 ordinary \[[0-9]+\+40960,\+8192\)->\[4096,\+8192\)} module } }
+// { dg-final { scan-lang-dump { Span:0 ordinary \[[0-9]+\+49152,\+16384\)->\[0,\+16384\)} module } }
+// { dg-final { scan-lang-dump { Span:1 ordinary \[[0-9]+\+163840,\+32768\)->\[16384,\+32768\)} module } }
index e96efe0bed50c7cc28a0c506f5f013ab2cd10ebc..217e8f8c9cb8e543f1681c0908c6dae3950dc1c2 100644 (file)
@@ -63,17 +63,13 @@ test_richloc (rich_location *richloc)
 static void
 test_fixit_on_very_long_line (const line_table_case &case_)
 {
-  /* Various interesting column/line-width values, to try to tickle
-     out bugs.  */
+  /* Various interesting column/line-width values, to try to tickle out bugs. In
+     64-bit location mode, we can't test the max because the maximum supported
+     column is unreasonably large.  */
   const int VERY_LONG_LINE = 8192;
   const int columns[] = {0,
                         1,
                         80,
-                        LINE_MAP_MAX_COLUMN_NUMBER - 2,
-                        LINE_MAP_MAX_COLUMN_NUMBER - 1,
-                        LINE_MAP_MAX_COLUMN_NUMBER,
-                        LINE_MAP_MAX_COLUMN_NUMBER + 1,
-                        LINE_MAP_MAX_COLUMN_NUMBER + 2,
                         VERY_LONG_LINE,
                         VERY_LONG_LINE + 5};
   for (unsigned int width_idx = 0; width_idx < ARRAY_SIZE (columns);
index 45a01b5f9178638ce74520eb6ddf9eb0ce266e01..f731b1421b0fd1e379f3dfda78ea557488cbf689 100644 (file)
@@ -84,6 +84,11 @@ plugin_init (struct plugin_name_args *plugin_info,
   if (!base_location)
     error_at (UNKNOWN_LOCATION, "missing plugin argument");
 
+  /* With 64-bit locations, the thresholds are larger, so shift the base
+     location argument accordingly.  */
+  gcc_assert (sizeof (location_t) == sizeof (uint64_t));
+  base_location = 1 + ((base_location - 1) << 31);
+
   register_callback (plugin_info->base_name,
                     PLUGIN_PRAGMAS,
                     on_pragma_registration,
index d4a4add29f92ba260de924795d8ea48286203667..370d7f39f2185b7a28cd7296f90ddd52b147f1b9 100644 (file)
@@ -1765,9 +1765,6 @@ process_options ()
     hash_table_sanitize_eq_limit
       = param_hash_table_verification_limit;
 
-  if (flag_large_source_files)
-    line_table->default_range_bits = 0;
-
   diagnose_options (&global_options, &global_options_set, UNKNOWN_LOCATION);
 
   /* Please don't change global_options after this point, those changes won't
index 298b434698ad50bd25afc1753685c199abdffb2d..10f07250135042dbb4240f3447bbca72c53b1cd5 100644 (file)
@@ -255,8 +255,10 @@ struct GTY(()) cpp_identifier {
        spelling;
 };
 
-/* A preprocessing token.  This has been carefully packed and should
-   occupy 16 bytes on 32-bit hosts and 24 bytes on 64-bit hosts.  */
+/* A preprocessing token.  This occupies 32 bytes on a 64-bit host.  On a
+   32-bit host it occupies 20 or 24 bytes, depending whether a uint64_t
+   requires 4- or 8-byte alignment.  */
+
 struct GTY(()) cpp_token {
 
   /* Location of first char of token, together with range of full token.  */
index 96fdf60644f234383aab6b40206f43f66fa21a89..95cc09d900ba5eac83fb57c18f635e99d5f723d2 100644 (file)
@@ -291,7 +291,10 @@ enum lc_reason
 
    To further see how location_t works in practice, see the
    worked example in libcpp/location-example.txt.  */
-typedef unsigned int location_t;
+
+/* A 64-bit type to represent a location.  We only use 63 of the 64 bits, so
+   that two location_t can be safely subtracted and stored in an int64_t.  */
+typedef uint64_t location_t;
 typedef int64_t location_diff_t;
 
 /* Sometimes we need a type that has the same size as location_t but that does
@@ -302,24 +305,31 @@ typedef location_t line_map_uint_t;
 /* Do not track column numbers higher than this one.  As a result, the
    range of column_bits is [12, 18] (or 0 if column numbers are
    disabled).  */
-const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 12);
+const unsigned int LINE_MAP_MAX_COLUMN_NUMBER = (1U << 31) - 1;
 
 /* Do not pack ranges if locations get higher than this.
    If you change this, update:
      gcc.dg/plugin/location-overflow-test-*.c.  */
-const location_t LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES = 0x50000000;
+const location_t LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES
+  = location_t (0x50000000) << 31;
 
 /* Do not track column numbers if locations get higher than this.
    If you change this, update:
      gcc.dg/plugin/location-overflow-test-*.c.  */
-const location_t LINE_MAP_MAX_LOCATION_WITH_COLS = 0x60000000;
+const location_t LINE_MAP_MAX_LOCATION_WITH_COLS
+  = location_t (0x60000000) << 31;
+
+/* Highest possible source location encoded within an ordinary map.  Higher
+   values up to MAX_LOCATION_T represent macro virtual locations.  */
+const location_t LINE_MAP_MAX_LOCATION = location_t (0x70000000) << 31;
 
-/* Highest possible source location encoded within an ordinary map.  */
-const location_t LINE_MAP_MAX_LOCATION = 0x70000000;
+/* This is the highest possible source location encoded within an
+   ordinary or macro map.  */
+const location_t MAX_LOCATION_T = location_t (-1) >> 2;
 
 /* This is the number of range bits suggested to enable, if range tracking is
    desired.  */
-const int line_map_suggested_range_bits = 5;
+const int line_map_suggested_range_bits = 7;
 
 /* A range of source locations.
 
@@ -397,7 +407,7 @@ typedef size_t (*line_map_round_alloc_size_func) (size_t);
 struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map {
   location_t start_location;
 
-  /* Size and alignment is (usually) 4 bytes.  */
+  /* Size is 8 bytes; alignment 4 or 8 depending on the arch.  */
 };
 
 /* An ordinary line map encodes physical source locations. Those
@@ -413,7 +423,7 @@ struct GTY((tag ("0"), desc ("MAP_ORDINARY_P (&%h) ? 1 : 2"))) line_map {
 
    The highest possible source location is MAX_LOCATION_T.  */
 struct GTY((tag ("1"))) line_map_ordinary : public line_map {
-  /* Base class is 4 bytes.  */
+  /* Base class is 8 bytes.  */
 
   /* 4 bytes of integers, each 1 byte for easy extraction/insertion.  */
 
@@ -445,9 +455,7 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map {
      +-------------------------+-----------------------+-------------------+ */
   unsigned int m_range_bits : 8;
 
-  /* Pointer alignment boundary on both 32 and 64-bit systems.  */
-
-  const char *to_file;
+  /* 32-bit int even in 64-bit mode.  */
   linenum_type to_line;
 
   /* Location from whence this line map was included.  For regular
@@ -456,12 +464,11 @@ struct GTY((tag ("1"))) line_map_ordinary : public line_map {
      within a map.  */
   location_t included_from;
 
-  /* Size is 20 or 24 bytes, no padding  */
-};
+  /* Pointer alignment boundary, whether 32-bit or 64-bit mode.  */
+  const char *to_file;
 
-/* This is the highest possible source location encoded within an
-   ordinary or macro map.  */
-const location_t MAX_LOCATION_T = 0x7FFFFFFF;
+  /* Size is 28 (32) bytes for 32-bit (64-bit) arch.  */
+};
 
 struct cpp_hashnode;
 
@@ -480,7 +487,7 @@ struct GTY((tag ("2"))) line_map_macro : public line_map {
     return m_expansion;
   }
 
-  /* Base is 4 bytes.  */
+  /* Base is 8 bytes.  */
 
   /* The number of tokens inside the replacement-list of MACRO.  */
   unsigned int n_tokens;
@@ -556,7 +563,10 @@ struct GTY((tag ("2"))) line_map_macro : public line_map {
      if we are in a nested expansion context not.  */
   location_t m_expansion;
 
-  /* Size is 20 or 32 (4 bytes padding on 64-bit).  */
+  /* Size is one of the following:
+     32-bit system: 28 or 32 bytes, depending whether a uint64_t requires
+                   4- or 8-byte alignment.
+     64-bit arch: 40 bytes.  */
 };
 
 #if CHECKING_P && (GCC_VERSION >= 2007)
@@ -783,7 +793,7 @@ struct htab;
 
    The new adhoc_loc uses the highest bit as the enabling bit, i.e. if the
    highest bit is 1, then the number is adhoc_loc. Otherwise, it serves as
-   the original location. Once identified as the adhoc_loc, the lower 31
+   the original location.  Once identified as the adhoc_loc, the lower 62
    bits of the integer is used to index the location_adhoc_data array,
    in which the locus and associated data is stored.  */