0003-Initial-work-to-make-ODB-compatible-with-GCC-6.patch 9.0 KB

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