xref: /OK3568_Linux_fs/buildroot/package/odb/0010-Add-initial-support-for-GCC-9.patch (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1From cd9a15f42ef35449a8ad480352f9f5495eb37c30 Mon Sep 17 00:00:00 2001
2From: Boris Kolpackov <boris@codesynthesis.com>
3Date: Fri, 15 Mar 2019 17:37:28 +0200
4Subject: [PATCH] Add initial support for GCC 9
5
6[Upstream: 841140bbf13ae2bfaa5978a181718cda0a8edae7]
7Signed-off-by: Kamel Bouhara <kamel.bouhara@bootlin.com>
8---
9 odb/cxx-lexer.cxx | 33 +++++++++++++++++++++++++++------
10 odb/gcc.hxx       | 32 ++++++++++++++++++++++++++++++++
11 odb/include.cxx   |  3 +++
12 odb/plugin.cxx    | 45 ++++++++++++++++++++++++++++++---------------
13 4 files changed, 92 insertions(+), 21 deletions(-)
14
15diff --git a/odb/cxx-lexer.cxx b/odb/cxx-lexer.cxx
16index cfebbb5..acd13be 100644
17--- a/odb/cxx-lexer.cxx
18+++ b/odb/cxx-lexer.cxx
19@@ -143,12 +143,20 @@ translate ()
20 // Diagnostics callback.
21 //
22 extern "C" bool
23-cpp_error_callback (
24+cpp_diagnostic_callback (
25   cpp_reader* reader,
26+#if BUILDING_GCC_MAJOR >= 9
27+  cpp_diagnostic_level level,
28+#else
29   int level,
30+#endif
31 #if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 5
32+#if BUILDING_GCC_MAJOR >= 9
33+  cpp_warning_reason,
34+#else
35   int /*reason*/, // Added in GCC 4.6.0.
36 #endif
37+#endif
38 #if BUILDING_GCC_MAJOR <= 5
39   location_t,
40   unsigned int,
41@@ -185,10 +193,14 @@ cpp_error_callback (
42     vfprintf (stderr, msg, *ap);
43     fprintf (stderr, "\n");
44
45-    // By resetting the error callback we indicate to cxx_string_lexer
46-    // that there was an error.
47+    // By resetting the callback we indicate to cxx_string_lexer that there
48+    // was an error.
49     //
50+#if BUILDING_GCC_MAJOR >= 9
51+    cpp_get_callbacks (reader)->diagnostic = 0;
52+#else
53     cpp_get_callbacks (reader)->error = 0;
54+#endif
55     return true;
56   }
57
58@@ -247,7 +259,12 @@ start (string const& data)
59   // The previous lexing session should have popped the buffer.
60   //
61   assert (cpp_get_buffer (reader_) == 0);
62-  callbacks_->error = &cpp_error_callback;
63+
64+#if BUILDING_GCC_MAJOR >= 9
65+  callbacks_->diagnostic = &cpp_diagnostic_callback;
66+#else
67+  callbacks_->error = &cpp_diagnostic_callback;
68+#endif
69
70   data_ = data;
71   buf_ = data;
72@@ -267,10 +284,14 @@ next (string& token, tree* node)
73   token.clear ();
74   cpp_token const* t (cpp_get_token (reader_));
75
76-  // If there was an error, the error callback will be reset to 0.
77-  // Diagnostics has already been issued.
78+  // If there was an error, the callback will be reset to 0. Diagnostics has
79+  // already been issued.
80   //
81+#if BUILDING_GCC_MAJOR >= 9
82+  if (callbacks_->diagnostic == 0)
83+#else
84   if (callbacks_->error == 0)
85+#endif
86     throw invalid_input ();
87
88   cpp_ttype tt (t->type);
89diff --git a/odb/gcc.hxx b/odb/gcc.hxx
90index a22357d..0304192 100644
91--- a/odb/gcc.hxx
92+++ b/odb/gcc.hxx
93@@ -158,4 +158,36 @@ gcc_tree_code_name (gcc_tree_code_type tc) {return tree_code_name[tc];}
94 #  define anon_aggrname_p(X) ANON_AGGRNAME_P(X)
95 #endif
96
97+// In GCC 9:
98+//
99+// INCLUDED_FROM     Became linemap_included_from_linemap().
100+// LAST_SOURCE_LINE  Was removed apparently as no longer used. Studying
101+//                   the line-map.h diff from 8.3 suggests that the old
102+//                   implementation should still work.
103+//
104+#if BUILDING_GCC_MAJOR >= 9
105+
106+inline const line_map_ordinary*
107+INCLUDED_FROM (line_maps* set, const line_map_ordinary* map)
108+{
109+  return linemap_included_from_linemap (set, map);
110+}
111+
112+inline source_location
113+LAST_SOURCE_LINE_LOCATION (const line_map_ordinary* map)
114+{
115+  return (((map[1].start_location - 1
116+	    - map->start_location)
117+	   & ~((1 << map->m_column_and_range_bits) - 1))
118+	  + map->start_location);
119+}
120+
121+inline linenum_type
122+LAST_SOURCE_LINE (const line_map_ordinary* map)
123+{
124+  return SOURCE_LINE (map, LAST_SOURCE_LINE_LOCATION (map));
125+}
126+
127+#endif
128+
129 #endif // ODB_GCC_HXX
130diff --git a/odb/include.cxx b/odb/include.cxx
131index 08c93ce..0082f5e 100644
132--- a/odb/include.cxx
133+++ b/odb/include.cxx
134@@ -584,6 +584,9 @@ namespace
135
136     for (include_map::iterator i (imap.begin ()), e (imap.end ()); i != e; ++i)
137     {
138+      // Note that the LAST_SOURCE_LINE value of a map that includes another
139+      // map is the line of that include.
140+
141       /*
142       cerr << endl
143            << i->first << " included from" << endl;
144diff --git a/odb/plugin.cxx b/odb/plugin.cxx
145index 0fac632..892f27c 100644
146--- a/odb/plugin.cxx
147+++ b/odb/plugin.cxx
148@@ -44,10 +44,15 @@ paths profile_paths_;
149 path file_;    // File being compiled.
150 paths inputs_; // List of input files in at-once mode or just file_.
151
152-bool (*cpp_error_prev) (
153+bool (*cpp_diagnostic_prev) (
154   cpp_reader*,
155+#if BUILDING_GCC_MAJOR >= 9
156+  cpp_diagnostic_level,
157+  cpp_warning_reason,
158+#else
159   int,
160   int,
161+#endif
162 #if BUILDING_GCC_MAJOR >= 6
163   rich_location*,
164 #else
165@@ -58,17 +63,22 @@ bool (*cpp_error_prev) (
166   va_list*);
167
168 static bool
169-cpp_error_filter (cpp_reader* r,
170-                  int level,
171-                  int reason,
172+cpp_diagnostic_filter (cpp_reader* r,
173+#if BUILDING_GCC_MAJOR >= 9
174+                       cpp_diagnostic_level level,
175+                       cpp_warning_reason reason,
176+#else
177+                       int level,
178+                       int reason,
179+#endif
180 #if BUILDING_GCC_MAJOR >= 6
181-                  rich_location* l,
182+                       rich_location* l,
183 #else
184-                  location_t l,
185-                  unsigned int column_override,
186+                       location_t l,
187+                       unsigned int column_override,
188 #endif
189-                  const char* msg,
190-                  va_list* ap)
191+                       const char* msg,
192+                       va_list* ap)
193 {
194   // #pragma once in the main file. Note that the message that we get is
195   // potentially translated so we search for the substring (there is
196@@ -80,7 +90,7 @@ cpp_error_filter (cpp_reader* r,
197   if (strstr (msg, "#pragma once") != 0)
198     return true;
199
200-  return cpp_error_prev (
201+  return cpp_diagnostic_prev (
202     r,
203     level,
204     reason,
205@@ -119,15 +129,20 @@ start_unit_callback (void*, void*)
206   //
207   cpp_callbacks* cb (cpp_get_callbacks (parse_in));
208
209-  if (cb->error == 0)
210+#if BUILDING_GCC_MAJOR >= 9
211+  cpp_diagnostic_prev = cb->diagnostic;
212+  cb->diagnostic = &cpp_diagnostic_filter;
213+#else
214+  cpp_diagnostic_prev = cb->error;
215+  cb->error = &cpp_diagnostic_filter;
216+#endif
217+
218+  if (cpp_diagnostic_prev == 0)
219   {
220-    cerr << "ice: expected cpp error callback to be set" << endl;
221+    cerr << "ice: expected cpp diagnostic callback to be set" << endl;
222     exit (1);
223   }
224
225-  cpp_error_prev = cb->error;
226-  cb->error = &cpp_error_filter;
227-
228   // Set the directory of the main file (stdin) to that of the orginal
229   // file so that relative inclusion works. Also adjust the path and
230   // re-stat the file so that #pragma once works.
231--
2322.25.0
233
234