From 9f8e4e351be1f6310c8bcd868f5ef71f8d210875 Mon Sep 17 00:00:00 2001
From: qing zhao <qing.zhao@oracle.com>
Date: Mon, 27 Apr 2020 16:20:19 +0200
Subject: [PATCH] Fix PR94230

---
 gcc/c-family/c-indentation.c                          |  5 +++++
 gcc/common.opt                                        |  5 +++++
 gcc/doc/invoke.texi                                   | 19 +++++++++++++++++--
 .../gcc.dg/plugin/location-overflow-test-1.c          |  2 +-
 gcc/toplev.c                                          |  3 +++
 5 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/gcc/c-family/c-indentation.c b/gcc/c-family/c-indentation.c
index f737555db0e..9fba3bcc67c 100644
--- a/gcc/c-family/c-indentation.c
+++ b/gcc/c-family/c-indentation.c
@@ -67,6 +67,11 @@ get_visual_column (expanded_location exploc, location_t loc,
 		  "%<-Wmisleading-indentation%> is disabled from this point"
 		  " onwards, since column-tracking was disabled due to"
 		  " the size of the code/headers");
+	  if (!flag_large_source_files)
+	    inform (loc,
+		    "adding %<-flarge-source-files%> will allow for more" 
+		    " column-tracking support, at the expense of compilation"
+		    " time and memory");
 	}
       return false;
     }
diff --git a/gcc/common.opt b/gcc/common.opt
index d33383b523c..30d05734d16 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1609,6 +1609,11 @@ fkeep-gc-roots-live
 Common Undocumented Report Var(flag_keep_gc_roots_live) Optimization
 ; Always keep a pointer to a live memory block
 
+flarge-source-files
+Common Report 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.
+
 floop-parallelize-all
 Common Report Var(flag_loop_parallelize_all) Optimization
 Mark all loops as parallel.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index a37a2ee9c19..bdde7c1d881 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -574,8 +574,8 @@ Objective-C and Objective-C++ Dialects}.
 -dD  -dI  -dM  -dN  -dU @gol
 -fdebug-cpp  -fdirectives-only  -fdollars-in-identifiers  @gol
 -fexec-charset=@var{charset}  -fextended-identifiers  @gol
--finput-charset=@var{charset}  -fmacro-prefix-map=@var{old}=@var{new}  @gol
--fmax-include-depth=@var{depth} @gol
+-finput-charset=@var{charset}  -flarge-source-files  @gol
+-fmacro-prefix-map=@var{old}=@var{new} -fmax-include-depth=@var{depth} @gol
 -fno-canonical-system-headers  -fpch-deps  -fpch-preprocess  @gol
 -fpreprocessed  -ftabstop=@var{width}  -ftrack-macro-expansion  @gol
 -fwide-exec-charset=@var{charset}  -fworking-directory @gol
@@ -14183,6 +14183,21 @@ This option may be useful in conjunction with the @option{-B} or
 perform additional processing of the program source between
 normal preprocessing and compilation.
 
+@item -flarge-source-files
+@opindex 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
diff --git a/gcc/testsuite/gcc.dg/plugin/location-overflow-test-1.c b/gcc/testsuite/gcc.dg/plugin/location-overflow-test-1.c
index 1a80a668a0f..a3ac12d3b46 100644
--- a/gcc/testsuite/gcc.dg/plugin/location-overflow-test-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/location-overflow-test-1.c
@@ -13,7 +13,7 @@ int
 fn_1 (int flag)
 {
   int x = 4, y = 5;
-  if (flag) x = 3; y = 2; /* { dg-message "-:disabled from this point" } */
+  if (flag) x = 3; y = 2; /* { dg-message "-:disabled from this point" "adding '-flarge-source-files'" } */
   return x * y;
 }
 
diff --git a/gcc/toplev.c b/gcc/toplev.c
index 4c8be502c71..b3230b71b9d 100644
--- a/gcc/toplev.c
+++ b/gcc/toplev.c
@@ -1854,6 +1854,9 @@ process_options (void)
     hash_table_sanitize_eq_limit
       = param_hash_table_verification_limit;
 
+  if (flag_large_source_files)
+    line_table->default_range_bits = 0;
+
   /* Please don't change global_options after this point, those changes won't
      be reflected in optimization_{default,current}_node.  */
 }
-- 
2.11.0
