1From bf389fd5185143847b1d91aed423e79c322dba51 Mon Sep 17 00:00:00 2001
2From: Boris Kolpackov <boris@codesynthesis.com>
3Date: Fri, 5 Feb 2016 16:01:42 +0200
4Subject: [PATCH] Initial work to make ODB compatible with GCC 6
5
6[Upstream: 511dcf67322ad87fb32f97d1cf7725c129e83898]
7Signed-off-by: Kamel Bouhara <kamel.bouhara@bootlin.com>
8---
9 odb/cxx-lexer.cxx          |  4 ++++
10 odb/gcc-fwd.hxx            | 23 ++++++++++++++++++++++-
11 odb/gcc.hxx                | 10 ++++++++++
12 odb/include.cxx            | 31 +++++++++++++++++++++----------
13 odb/parser.cxx             |  8 ++++----
14 odb/plugin.cxx             | 29 +++++++++++++++++++++++++++--
15 odb/semantics/elements.cxx |  4 ++--
16 7 files changed, 90 insertions(+), 19 deletions(-)
17
18diff --git a/odb/cxx-lexer.cxx b/odb/cxx-lexer.cxx
19index 7029c7e..64df296 100644
20--- a/odb/cxx-lexer.cxx
21+++ b/odb/cxx-lexer.cxx
22@@ -135,8 +135,12 @@ cpp_error_callback (
23 #if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 5
24   int /*reason*/, // Added in GCC 4.6.0.
25 #endif
26+#if BUILDING_GCC_MAJOR <= 5
27   location_t,
28   unsigned int,
29+#else
30+  rich_location*,
31+#endif
32   char const* msg,
33   va_list *ap)
34 {
35diff --git a/odb/gcc-fwd.hxx b/odb/gcc-fwd.hxx
36index a120f05..618b106 100644
37--- a/odb/gcc-fwd.hxx
38+++ b/odb/gcc-fwd.hxx
39@@ -7,6 +7,24 @@
40
41 #include <bversion.h>
42
43+#if BUILDING_GCC_MAJOR >= 6
44+
45+// If we include <system.h> here, it pulls in all kinds of GCC trouble that
46+// "poisons" standard C/C++ declarations; see safe-ctype.h. So instead we
47+// are going to "exclude" safe-ctype.h. To compensate, however, we will
48+// include it first thing in gcc.hxx.
49+//
50+#  include <config.h>
51+#  define SAFE_CTYPE_H
52+#  include <system.h>
53+#  undef SAFE_CTYPE_H
54+#  include <coretypes.h>
55+
56+typedef unsigned int source_location; // <line-map.h>
57+typedef source_location location_t;   // <input.h>
58+
59+#else // GCC < 6
60+
61 #if BUILDING_GCC_MAJOR > 4 || BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR > 8
62 #  include <limits.h> // CHAR_BIT
63 #  include <config.h>
64@@ -33,6 +51,9 @@ extern "C"
65
66 typedef unsigned int source_location; // <line-map.h>
67 typedef source_location location_t;   // <input.h>
68-}
69+
70+} // extern "C"
71+
72+#endif
73
74 #endif // ODB_GCC_FWD_HXX
75diff --git a/odb/gcc.hxx b/odb/gcc.hxx
76index c953047..858d685 100644
77--- a/odb/gcc.hxx
78+++ b/odb/gcc.hxx
79@@ -7,6 +7,10 @@
80
81 #include <odb/gcc-fwd.hxx>
82
83+#if BUILDING_GCC_MAJOR >= 6
84+#  include <safe-ctype.h> // See gcc-fwd.hxx.
85+#endif
86+
87 // GCC header includes to get the plugin and parse tree declarations.
88 // The order is important and doesn't follow any kind of logic.
89 //
90@@ -145,4 +149,10 @@ gcc_tree_code_name (gcc_tree_code_type tc) {return tree_code_name[tc];}
91 #define DECL_CHAIN(x) TREE_CHAIN(x)
92 #endif
93
94+// In GCC 6, ANON_AGGRNAME_P became anon_aggrname_p().
95+//
96+#if BUILDING_GCC_MAJOR < 6
97+#  define anon_aggrname_p(X) ANON_AGGRNAME_P(X)
98+#endif
99+
100 #endif // ODB_GCC_HXX
101diff --git a/odb/include.cxx b/odb/include.cxx
102index c397993..08c93ce 100644
103--- a/odb/include.cxx
104+++ b/odb/include.cxx
105@@ -30,9 +30,18 @@ namespace
106     path path_;
107   };
108
109+#if BUILDING_GCC_MAJOR >= 6
110+  typedef line_map_ordinary line_map_type;
111+#else
112+  typedef line_map line_map_type;
113+# ifndef linemap_check_ordinary
114+#   define linemap_check_ordinary(X) (X)
115+# endif
116+#endif
117+
118   struct includes
119   {
120-    typedef std::map<line_map const*, include_directive> map_type;
121+    typedef std::map<line_map_type const*, include_directive> map_type;
122     bool trailing; // Included at the beginning or at the end of the main file.
123     map_type map;
124   };
125@@ -144,7 +153,9 @@ namespace
126       //
127       if (l > BUILTINS_LOCATION)
128       {
129-        line_map const* lm (linemap_lookup (line_table, l));
130+        line_map_type const* lm (
131+          linemap_check_ordinary (
132+            linemap_lookup (line_table, l)));
133
134         if (lm != 0 && !MAIN_FILE_P (lm))
135         {
136@@ -537,20 +548,20 @@ namespace
137     //
138 #if BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR <= 6
139     size_t used (line_table->used);
140-    line_map const* maps (line_table->maps);
141+    line_map_type const* maps (line_table->maps);
142 #else
143     size_t used (line_table->info_ordinary.used);
144-    line_map const* maps (line_table->info_ordinary.maps);
145+    line_map_type const* maps (line_table->info_ordinary.maps);
146 #endif
147
148     for (size_t i (0); i < used; ++i)
149     {
150-      line_map const* m (maps + i);
151+      line_map_type const* m (maps + i);
152
153       if (MAIN_FILE_P (m) || m->reason != LC_ENTER)
154         continue;
155
156-      line_map const* ifm (INCLUDED_FROM (line_table, m));
157+      line_map_type const* ifm (INCLUDED_FROM (line_table, m));
158
159 #if BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR <= 6
160       path f (m->to_file);
161@@ -580,7 +591,7 @@ namespace
162       for (includes::iterator j (i->second.begin ());
163            j != i->second.end (); ++j)
164       {
165-        line_map const* lm (j->first);
166+        line_map_type const* lm (j->first);
167         cerr << '\t' << lm->to_file << ":" << LAST_SOURCE_LINE (lm) << endl;
168       }
169       */
170@@ -589,13 +600,13 @@ namespace
171       // it is preferred over all others. Use the first one if there are
172       // several.
173       //
174-      line_map const* main_lm (0);
175+      line_map_type const* main_lm (0);
176       include_directive* main_inc (0);
177
178       for (includes::map_type::iterator j (i->second.map.begin ());
179            j != i->second.map.end (); ++j)
180       {
181-        line_map const* lm (j->first);
182+        line_map_type const* lm (j->first);
183
184         if (MAIN_FILE_P (lm))
185         {
186@@ -636,7 +647,7 @@ namespace
187       for (includes::map_type::iterator j (i->second.map.begin ());
188            j != i->second.map.end (); ++j)
189       {
190-        line_map const* lm (j->first);
191+        line_map_type const* lm (j->first);
192
193 #if BUILDING_GCC_MAJOR == 4 && BUILDING_GCC_MINOR <= 6
194         string f (lm->to_file);
195diff --git a/odb/parser.cxx b/odb/parser.cxx
196index a8e6a6a..feda9d4 100644
197--- a/odb/parser.cxx
198+++ b/odb/parser.cxx
199@@ -1044,14 +1044,14 @@ emit_type_decl (tree decl)
200     // says that in typedef struct {} S; S becomes struct's
201     // name.
202     //
203-    if (ANON_AGGRNAME_P (decl_name))
204+    if (anon_aggrname_p (decl_name))
205     {
206       tree d (TYPE_NAME (t));
207
208       if (d != NULL_TREE &&
209           !DECL_ARTIFICIAL (d) &&
210           DECL_NAME (d) != NULL_TREE &&
211-          !ANON_AGGRNAME_P (DECL_NAME (d)))
212+          !anon_aggrname_p (DECL_NAME (d)))
213       {
214         decl = d;
215         decl_name = DECL_NAME (decl);
216@@ -1668,7 +1668,7 @@ create_type (tree t,
217             ts << "start anon/stub " << gcc_tree_code_name(tc) << " at "
218                << file << ":" << line << endl;
219
220-          if (d == NULL_TREE || ANON_AGGRNAME_P (DECL_NAME (d)))
221+          if (d == NULL_TREE || anon_aggrname_p (DECL_NAME (d)))
222           {
223             if (tc == RECORD_TYPE)
224               r = &emit_class<class_> (t, file, line, clmn);
225@@ -1765,7 +1765,7 @@ create_type (tree t,
226         ts << "start anon/stub " << gcc_tree_code_name(tc) << " at "
227            << file << ":" << line << endl;
228
229-      if (d == NULL_TREE || ANON_AGGRNAME_P (DECL_NAME (d)))
230+      if (d == NULL_TREE || anon_aggrname_p (DECL_NAME (d)))
231       {
232         r = &emit_enum (t, access, file, line, clmn);
233       }
234diff --git a/odb/plugin.cxx b/odb/plugin.cxx
235index 51f0cb1..779faed 100644
236--- a/odb/plugin.cxx
237+++ b/odb/plugin.cxx
238@@ -45,14 +45,28 @@ path file_;    // File being compiled.
239 paths inputs_; // List of input files in at-once mode or just file_.
240
241 bool (*cpp_error_prev) (
242-  cpp_reader*, int, int, location_t, unsigned int, const char*, va_list*);
243+  cpp_reader*,
244+  int,
245+  int,
246+#if BUILDING_GCC_MAJOR >= 6
247+  rich_location*,
248+#else
249+  location_t,
250+  unsigned int,
251+#endif
252+  const char*,
253+  va_list*);
254
255 static bool
256 cpp_error_filter (cpp_reader* r,
257                   int level,
258                   int reason,
259+#if BUILDING_GCC_MAJOR >= 6
260+                  rich_location* l,
261+#else
262                   location_t l,
263                   unsigned int column_override,
264+#endif
265                   const char* msg,
266                   va_list* ap)
267 {
268@@ -66,7 +80,18 @@ cpp_error_filter (cpp_reader* r,
269   if (strstr (msg, "#pragma once") != 0)
270     return true;
271
272-  return cpp_error_prev (r, level, reason, l, column_override, msg, ap);
273+  return cpp_error_prev (
274+    r,
275+    level,
276+    reason,
277+#if BUILDING_GCC_MAJOR >= 6
278+    l,
279+#else
280+    l,
281+    column_override,
282+#endif
283+    msg,
284+    ap);
285 }
286
287 // A prefix of the _cpp_file struct. This struct is not part of the
288diff --git a/odb/semantics/elements.cxx b/odb/semantics/elements.cxx
289index 21e3260..399d5e9 100644
290--- a/odb/semantics/elements.cxx
291+++ b/odb/semantics/elements.cxx
292@@ -59,7 +59,7 @@ namespace semantics
293       if (tree decl = TYPE_NAME (n))
294         name = DECL_NAME (decl);
295
296-      return name != 0 && ANON_AGGRNAME_P (name);
297+      return name != 0 && anon_aggrname_p (name);
298     }
299
300     return true;
301@@ -108,7 +108,7 @@ namespace semantics
302       if (tree decl = TYPE_NAME (type))
303       {
304         name = DECL_NAME (decl);
305-        if (name != 0 && ANON_AGGRNAME_P (name))
306+        if (name != 0 && anon_aggrname_p (name))
307           return true;
308
309         tree s (CP_DECL_CONTEXT (decl));
310--
3112.25.0
312
313