0010-Add-initial-support-for-GCC-9.patch 6.6 KB

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