Skip to content

Commit db06d1a

Browse files
authored
Merge pull request #116 from davidmalcolm/fixing-gcc-8
Fixing gcc 8
2 parents 078aec8 + a492b73 commit db06d1a

File tree

11 files changed

+278
-14
lines changed

11 files changed

+278
-14
lines changed

.travis.yml

Lines changed: 62 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,66 @@
1+
matrix:
2+
include:
3+
- os: linux
4+
addons:
5+
apt:
6+
sources:
7+
- ubuntu-toolchain-r-test
8+
packages:
9+
- g++-4.8 gcc-4.8-plugin-dev
10+
env:
11+
- MATRIX_EVAL="CC=gcc-4.8 && CXX=g++-4.8"
12+
13+
# works on Precise and Trusty
14+
- os: linux
15+
addons:
16+
apt:
17+
sources:
18+
- ubuntu-toolchain-r-test
19+
packages:
20+
- g++-4.9 gcc-4.9-plugin-dev
21+
env:
22+
- MATRIX_EVAL="CC=gcc-4.9 && CXX=g++-4.9"
23+
24+
# works on Precise and Trusty
25+
- os: linux
26+
addons:
27+
apt:
28+
sources:
29+
- ubuntu-toolchain-r-test
30+
packages:
31+
- g++-5 gcc-5-plugin-dev
32+
env:
33+
- MATRIX_EVAL="CC=gcc-5 && CXX=g++-5"
34+
35+
# works on Precise and Trusty
36+
- os: linux
37+
addons:
38+
apt:
39+
sources:
40+
- ubuntu-toolchain-r-test
41+
packages:
42+
- g++-6 gcc-6-plugin-dev
43+
env:
44+
- MATRIX_EVAL="CC=gcc-6 && CXX=g++-6"
45+
46+
# works on Precise and Trusty
47+
- os: linux
48+
addons:
49+
apt:
50+
sources:
51+
- ubuntu-toolchain-r-test
52+
packages:
53+
- g++-7 gcc-7-plugin-dev
54+
env:
55+
- MATRIX_EVAL="CC=gcc-7 && CXX=g++-7"
56+
157
language: c
258
compiler:
359
- gcc
4-
script: make
60+
561
before_install:
6-
- sudo apt-get update -qq
7-
- sudo apt-get install -qq gcc-4.6-plugin-dev python-six python-pygments graphviz python-lxml
62+
- eval "${MATRIX_EVAL}"
63+
- sudo apt-get update -qq
64+
- sudo apt-get install -qq python-six python-pygments graphviz python-lxml
65+
66+
script: make

gcc-c-api/gcc-callgraph.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
#include "tree-ssa-alias.h"
2525
#include "basic-block.h"
2626
#if (GCC_VERSION >= 4009)
27-
#include "gimple-expr.h"
27+
#include "tree-ssa-alias.h" /* needed by gimple.h in 4.9 */
28+
#include "internal-fn.h" /* needed by gimple.h in 4.9 */
29+
#include "is-a.h" /* needed by gimple.h in 4.9 */
30+
#include "predict.h" /* needed by gimple.h in 4.9 */
31+
#include "gimple-expr.h" /* needed by gimple.h in 4.9 */
2832
#endif
2933
#include "gimple.h"
3034

gcc-python-compat.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ dump_gimple_stmt (pretty_printer *buffer, gimple gs, int spc, int flags);
4343

4444

4545
/*
46-
This is declared in gcc/tree-pretty-print.c (around line 580); it doesn't
47-
seem to be declared in any of the plugin headers:
46+
This is declared in gcc/tree-pretty-print.c (around line 580); it was only
47+
exposed to plugin headers (in tree-pretty-print.h) in GCC commit r203113
48+
(aka 0d9585ca35b919263b973afb371f0eda04857159, 2013-10-02), as part of
49+
GCC 4.9
50+
51+
The signature was changed by GCC 8 commit r248140 (aka
52+
3f6e5ced7eb1cf5b3212b2391c5b70ec3dcaf136, 2017-05-17), which introduced
53+
dump_flags_t.
4854
*/
55+
#if GCC_VERSION < 4009
4956
extern int
5057
dump_generic_node (pretty_printer *buffer, tree node, int spc, int flags,
5158
bool is_stmt);
59+
#endif
5260

5361
/* Within gcc/gcc-internal.h, not exposed by plugin API */
5462
extern bool ggc_force_collect;

gcc-python-diagnostics.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,11 @@ PyGcc_inform(PyObject *self, PyObject *args, PyObject *kwargs)
164164
Py_RETURN_NONE;
165165
} else if (Py_TYPE (obj) == (PyTypeObject *)&PyGccRichLocation_TypeObj) {
166166
PyGccRichLocation *richloc_obj = (PyGccRichLocation *)obj;
167-
inform_at_rich_loc (&richloc_obj->richloc, msg);
167+
#if (GCC_VERSION >= 8000)
168+
inform (&richloc_obj->richloc, "%s", msg);
169+
#else
170+
inform_at_rich_loc (&richloc_obj->richloc, "%s", msg);
171+
#endif
168172
Py_RETURN_NONE;
169173
} else {
170174
return PyErr_Format(PyExc_TypeError,

gcc-python-tree.c

Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,16 @@ __typeof__ (lang_check_failed) lang_check_failed __attribute__ ((weak));
6060

6161
__typeof__ (decl_as_string) decl_as_string __attribute__ ((weak));
6262

63-
/* Similar for namespace_binding: */
63+
/* Similar for namespace_binding, though gcc 8's r247654 (aka
64+
f906dcc33dd818b71e16c88cef38f33c161070db) replaced it with
65+
get_namespace_value and reversed the order of the params
66+
and r247745 (aka 9d79db401edbb9665cde47ddea2702671c89e548)
67+
renamed it from get_namespace_value to get_namespace_binding. */
68+
#if (GCC_VERSION >= 8000)
69+
__typeof__ (get_namespace_binding) get_namespace_binding __attribute__ ((weak));
70+
#else
6471
__typeof__ (namespace_binding) namespace_binding __attribute__ ((weak));
72+
#endif
6573

6674
/* And for cp_namespace_decls: */
6775
__typeof__ (cp_namespace_decls) cp_namespace_decls __attribute__ ((weak));
@@ -678,13 +686,32 @@ PyGccConstructor_get_elements(PyObject *self, void *closure)
678686
return NULL;
679687
}
680688

689+
#if (GCC_VERSION >= 5000)
690+
691+
static void
692+
print_integer_cst_to_buf(tree int_cst, char *buf, tree type)
693+
{
694+
/*
695+
GCC 8 commit r253595 (aka e3d0f65c14ffd7a63455dc1aa9d0405d25b327e4,
696+
2017-10-10) introduces and requires the use of wi::to_wide on
697+
INTEGER_CST.
698+
*/
699+
#if (GCC_VERSION >= 8000)
700+
print_dec(wi::to_wide(int_cst), buf, TYPE_SIGN (type));
701+
#else
702+
print_dec(int_cst, buf, TYPE_SIGN (type));
703+
#endif
704+
}
705+
706+
#endif /* #if (GCC_VERSION >= 5000) */
707+
681708
PyObject *
682709
PyGcc_int_from_int_cst(tree int_cst)
683710
{
684711
tree type = TREE_TYPE(int_cst);
685712
#if (GCC_VERSION >= 5000)
686713
char buf[WIDE_INT_PRINT_BUFFER_SIZE];
687-
print_dec(int_cst, buf, TYPE_SIGN (type));
714+
print_integer_cst_to_buf (int_cst, buf, type);
688715
return PyGcc_int_from_decimal_string_buffer(buf);
689716
#else
690717
return PyGcc_int_from_double_int(TREE_INT_CST(int_cst),
@@ -704,7 +731,7 @@ PyGccIntegerConstant_repr(struct PyGccTree * self)
704731
tree type = TREE_TYPE(self->t.inner);
705732
#if (GCC_VERSION >= 5000)
706733
char buf[WIDE_INT_PRINT_BUFFER_SIZE];
707-
print_dec(self->t.inner, buf, TYPE_SIGN (type));
734+
print_integer_cst_to_buf (self->t.inner, buf, type);
708735
#else
709736
char buf[512];
710737
PyGcc_DoubleIntAsText(TREE_INT_CST(self->t.inner),
@@ -931,13 +958,22 @@ PyGccNamespaceDecl_lookup(struct PyGccTree * self, PyObject *args, PyObject *kwa
931958
return NULL;
932959
}
933960

961+
#if (GCC_VERSION >= 8000)
962+
if (NULL == get_namespace_binding) {
963+
#else
934964
if (NULL == namespace_binding) {
965+
#endif
935966
return raise_cplusplus_only("gcc.NamespaceDecl.lookup");
936967
}
937968

938969
t_name = get_identifier(name);
939970

971+
#if (GCC_VERSION >= 8000)
972+
t_result = get_namespace_binding(self->t.inner, t_name);
973+
#else
940974
t_result = namespace_binding(t_name, self->t.inner);
975+
#endif
976+
941977
return PyGccTree_New(gcc_private_make_tree(t_result));
942978
}
943979

@@ -980,6 +1016,16 @@ PyGccNamespaceDecl_declarations(tree t)
9801016
return PyGcc_TreeListFromChain(cp_namespace_decls(t));
9811017
}
9821018

1019+
#if (GCC_VERSION >= 8000)
1020+
1021+
static int is_namespace (tree decl, void *)
1022+
{
1023+
return (TREE_CODE (decl) == NAMESPACE_DECL
1024+
&& !DECL_NAMESPACE_ALIAS (decl));
1025+
}
1026+
1027+
#endif /* #if (GCC_VERSION >= 8000) */
1028+
9831029
PyObject *
9841030
PyGccNamespaceDecl_namespaces(tree t)
9851031
{
@@ -993,7 +1039,57 @@ PyGccNamespaceDecl_namespaces(tree t)
9931039
if (DECL_NAMESPACE_ALIAS(t))
9941040
return raise_namespace_alias("gcc.NamespaceDecl.namespaces");
9951041

1042+
/* GCC 8's r248821 (aka f7564df45462679c3b0b82f2942f5fb50b640113)
1043+
eliminated the "namespaces" field from cp_binding_level. */
1044+
1045+
#if (GCC_VERSION >= 8000)
1046+
return PyGcc_TreeListFromChainWithFilter(NAMESPACE_LEVEL(t)->names,
1047+
is_namespace, NULL);
1048+
#else
9961049
return PyGcc_TreeListFromChain(NAMESPACE_LEVEL(t)->namespaces);
1050+
#endif
1051+
}
1052+
1053+
/* Accessing the fields and methods of compound types.
1054+
GCC 8's r250413 (aka ab87ee8f509c0b600102195704105d4d98ec59d9)
1055+
eliminated TYPE_METHODS, instead putting both fields and methods
1056+
on the TYPE_FIELDS chain, using DECL_DECLARES_FUNCTION_P to
1057+
distinguish them. */
1058+
1059+
#if (GCC_VERSION >= 8000)
1060+
1061+
static int is_field (tree t, void *)
1062+
{
1063+
return !DECL_DECLARES_FUNCTION_P (t);
1064+
}
1065+
1066+
static int is_method (tree t, void *)
1067+
{
1068+
return DECL_DECLARES_FUNCTION_P (t);
1069+
}
1070+
1071+
#endif /* #if (GCC_VERSION >= 8000) */
1072+
1073+
PyObject *
1074+
PyGcc_GetFields(struct PyGccTree *self)
1075+
{
1076+
#if (GCC_VERSION >= 8000)
1077+
return PyGcc_TreeListFromChainWithFilter(TYPE_FIELDS(self->t.inner),
1078+
is_field, NULL);
1079+
#else
1080+
return PyGcc_TreeListFromChain(TYPE_FIELDS(self->t.inner));
1081+
#endif
1082+
}
1083+
1084+
PyObject *
1085+
PyGcc_GetMethods(struct PyGccTree *self)
1086+
{
1087+
#if (GCC_VERSION >= 8000)
1088+
return PyGcc_TreeListFromChainWithFilter(TYPE_FIELDS(self->t.inner),
1089+
is_method, NULL);
1090+
#else
1091+
return PyGcc_TreeListFromChain(TYPE_METHODS(self->t.inner));
1092+
#endif
9971093
}
9981094

9991095
/*
@@ -1104,6 +1200,44 @@ PyGcc_TreeListFromChain(tree t)
11041200
return NULL;
11051201
}
11061202

1203+
/* As above, but only add nodes for which "filter" returns true. */
1204+
PyObject *
1205+
PyGcc_TreeListFromChainWithFilter(tree t,
1206+
int (*filter) (tree, void *),
1207+
void *user_data)
1208+
{
1209+
PyObject *result = NULL;
1210+
1211+
result = PyList_New(0);
1212+
if (!result) {
1213+
goto error;
1214+
}
1215+
1216+
while (t) {
1217+
if (filter (t, user_data)) {
1218+
PyObject *item;
1219+
1220+
item = PyGccTree_New(gcc_private_make_tree(t));
1221+
if (!item) {
1222+
goto error;
1223+
}
1224+
if (-1 == PyList_Append(result, item)) {
1225+
Py_DECREF(item);
1226+
goto error;
1227+
}
1228+
Py_DECREF(item);
1229+
}
1230+
1231+
t = TREE_CHAIN(t);
1232+
}
1233+
1234+
return result;
1235+
1236+
error:
1237+
Py_XDECREF(result);
1238+
return NULL;
1239+
}
1240+
11071241
/*
11081242
As above, but expect nodes of the form:
11091243
tree_list ---> value

gcc-python-wrappers.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ PyGccNamespaceDecl_declarations(tree t);
346346
PyObject *
347347
PyGccNamespaceDecl_namespaces(tree t);
348348

349+
PyObject *
350+
PyGcc_GetFields(struct PyGccTree *self);
351+
352+
PyObject *
353+
PyGcc_GetMethods(struct PyGccTree *self);
349354

350355
/* gcc-python-gimple.c: */
351356
extern gcc_gimple_asm
@@ -499,6 +504,11 @@ PyGccRtl_str(struct PyGccRtl * self);
499504
PyObject *
500505
PyGcc_TreeListFromChain(tree t);
501506

507+
PyObject *
508+
PyGcc_TreeListFromChainWithFilter(tree t,
509+
int (*filter) (tree, void *),
510+
void *user_data);
511+
502512
PyObject *
503513
PyGcc_TreeMakeListFromTreeList(tree t);
504514

gcc-python.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,22 @@ PyGcc_get_translation_units(PyObject *self, PyObject *args)
301301
add_translation_unit_decl_to_list)
302302
}
303303

304-
/* Weakly import global_namespace; it will be non-NULL for the C++ frontend: */
304+
305+
/* Weakly import global_namespace; it will be non-NULL for the C++ frontend.
306+
307+
GCC 8's r247599 (aka c99e91fe8d1191b348cbc1659fbfbac2fc07e154)
308+
converted it from:
309+
extern GTY(()) tree global_namespace;
310+
to:
311+
#define global_namespace cp_global_trees[CPTI_GLOBAL]
312+
so we have to access cp_global_trees instead. */
313+
314+
#if (GCC_VERSION >= 8000)
315+
__typeof__ (cp_global_trees) cp_global_trees __attribute__ ((weak));
316+
#else
305317
__typeof__ (global_namespace) global_namespace __attribute__ ((weak));
318+
#endif /* #if (GCC_VERSION >= 8000) */
319+
306320

307321
static PyObject *
308322
PyGcc_get_global_namespace(PyObject *self, PyObject *args)

generate-tree-c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,10 @@ def add_complex_getter(name, doc):
479479

480480
if tree_type.SYM in ('RECORD_TYPE', 'UNION_TYPE', 'QUAL_UNION_TYPE'):
481481
add_simple_getter('fields',
482-
'PyGcc_TreeListFromChain(TYPE_FIELDS(self->t.inner))',
482+
'PyGcc_GetFields(self)',
483483
"The fields of this type")
484484
add_simple_getter('methods',
485-
'PyGcc_TreeListFromChain(TYPE_METHODS(self->t.inner))',
485+
'PyGcc_GetMethods(self)',
486486
"The methods of this type")
487487

488488
if tree_type.SYM == 'ENUMERAL_TYPE':

0 commit comments

Comments
 (0)