Redefinition of `struct lang_type` in rust-tree.h and rust-lang.cc
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108087
- @CohenArthur could you assign me this issue :)
Done @DrMahad! Thank you :)
First Solution:
- When I try to move
struct GTY (()) lang_typefromrust-tree.htorust-lang.cc, I get the following error.
-S ../../gccrs/gcc -I gtyp-input.list -w tmp-gtype.state
../../gccrs/gcc/rust/rust-lang.cc:164: duplicate definition of 'struct lang_type'
../../gccrs/gcc/rust/rust-lang.cc:159: previous definition here
make[2]: *** [Makefile:2853: s-gtype] Error 1
make[2]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build/gcc'
make[1]: *** [Makefile:4571: all-gcc] Error 2
make[1]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build'
make: *** [Makefile:1006: all] Error 2
Second Solution:
- When I try to delete the
struct GTY (()) lang_typefrom rust-tree.h, I get the following error:
In file included from ../../gccrs/gcc/rust/backend/rust-constexpr.cc:20:
../../gccrs/gcc/rust/backend/rust-constexpr.cc: In function ‘bool Rust::Compile::build_data_member_initialization(tree, vec<constructor_elt, va_gc>**)’:
../../gccrs/gcc/rust/backend/rust-tree.h:1324:55: error: invalid use of incomplete type ‘struct lang_type’
1324 | (CLASS_TYPE_P (NODE) && LANG_TYPE_CLASS_CHECK (NODE)->anon_aggr)
| ^~
../../gccrs/gcc/rust/backend/rust-constexpr.cc:3833:16: note: in expansion of macro ‘ANON_AGGR_TYPE_P’
3833 | else if (ANON_AGGR_TYPE_P (TREE_TYPE (aggr)))
| ^~~~~~~~~~~~~~~~
In file included from ../../gccrs/gcc/tree.h:23,
from ../../gccrs/gcc/rust/backend/rust-constexpr.h:21,
from ../../gccrs/gcc/rust/backend/rust-constexpr.cc:17:
../../gccrs/gcc/tree-core.h:1740:10: note: forward declaration of ‘struct lang_type’
1740 | struct lang_type *lang_specific;
| ^~~~~~~~~
make[2]: *** [../../gccrs/gcc/rust/Make-lang.in:360: rust/rust-constexpr.o] Error 1
make[2]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build/gcc'
make[1]: *** [Makefile:4571: all-gcc] Error 2
make[1]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build'
make: *** [Makefile:1006: all] Error 2
Third Solution:
- When I try to delete the
struct GTY (()) lang_typefromrust-lang.cc, I get the following error:
/usr/bin/ld: rust/rust-lang.o: in function `gt_ggc_mx_lang_tree_node(void*)':
/home/mahad/Desktop/DrMahad/gccrs-build/gcc/./gt-rust-rust-lang.h:369: undefined reference to `gt_ggc_mx_lang_type(void*)'
/usr/bin/ld: /home/mahad/Desktop/DrMahad/gccrs-build/gcc/./gt-rust-rust-lang.h:344: undefined reference to `gt_ggc_mx_lang_type(void*)'
/usr/bin/ld: rust/rust-lang.o: in function `gt_pch_nx_lang_tree_node(void*)':
/home/mahad/Desktop/DrMahad/gccrs-build/gcc/./gt-rust-rust-lang.h:830: undefined reference to `gt_pch_nx_lang_type(void*)'
/usr/bin/ld: /home/mahad/Desktop/DrMahad/gccrs-build/gcc/./gt-rust-rust-lang.h:855: undefined reference to `gt_pch_nx_lang_type(void*)'
collect2: error: ld returned 1 exit status
make[2]: *** [../../gccrs/gcc/rust/Make-lang.in:175: rust1] Error 1
make[2]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build/gcc'
make[1]: *** [Makefile:4571: all-gcc] Error 2
make[1]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build'
make: *** [Makefile:1006: all] Error 2
Fourth Solution:
- I renamed lang_type in
gccrs/gcc/rust/backend/rust-tree.hto lang_type2. So, I get the following error:
/gcc/rust/util -I ../../gccrs/gcc/rust/metadata ../../gccrs/gcc/rust/backend/rust-constexpr.cc
In file included from ../../gccrs/gcc/rust/backend/rust-constexpr.cc:20:
../../gccrs/gcc/rust/backend/rust-constexpr.cc: In function ‘bool Rust::Compile::build_data_member_initialization(tree, vec<constructor_elt, va_gc>**)’:
../../gccrs/gcc/rust/backend/rust-tree.h:1324:55: error: invalid use of incomplete type ‘struct lang_type’
1324 | (CLASS_TYPE_P (NODE) && LANG_TYPE_CLASS_CHECK (NODE)->anon_aggr)
| ^~
../../gccrs/gcc/rust/backend/rust-constexpr.cc:3833:16: note: in expansion of macro ‘ANON_AGGR_TYPE_P’
3833 | else if (ANON_AGGR_TYPE_P (TREE_TYPE (aggr)))
| ^~~~~~~~~~~~~~~~
In file included from ../../gccrs/gcc/tree.h:23,
from ../../gccrs/gcc/rust/backend/rust-constexpr.h:21,
from ../../gccrs/gcc/rust/backend/rust-constexpr.cc:17:
../../gccrs/gcc/tree-core.h:1740:10: note: forward declaration of ‘struct lang_type’
1740 | struct lang_type *lang_specific;
| ^~~~~~~~~
make[2]: *** [../../gccrs/gcc/rust/Make-lang.in:360: rust/rust-constexpr.o] Error 1
make[2]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build/gcc'
make[1]: *** [Makefile:4571: all-gcc] Error 2
make[1]: Leaving directory '/home/mahad/Desktop/DrMahad/gccrs-build'
make: *** [Makefile:1006: all] Error 2
As a non-gccrs person, just the person who filed the bug:
- Are they really the same type? If so, put it into a common place (if it's not already), and include it in both, and don't define it again. I don't think they are here, though.
- If they're not the same type, either rename one, or put it into an anonymous namespace.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108087#c4 makes it sound like it's not the same, just similar.
Thank you @thesamesam for helping me in this issue.
- Sam, I don't think so they are of same type.
- Secondly, I'll work on your provided solution and see if it works :)
- Currently, I was able to port these in a seperate header rust-gcc.h https://github.com/Rust-GCC/gccrs/commit/d7af62a5de2110c3c5a505a7405285c57aca5db7.
- My whole progress can be found here https://github.com/Rust-GCC/gccrs/compare/master...MahadMuhammad:gccrs:Fix%231702.
The issue is that we have ported over constexpr support from C++ as Rust compiles time constant evaluation. But this meant porting over some of the C++ custom GCC bits. Its an awkward issue, probably one for me to sort out in a few weeks unless someone can extract it out into a shared header like @thesamesam has suggested and we talked about on zulip.
Quoting myself on BZ:
I think this was fixed by https://github.com/Rust-GCC/gccrs/pull/2586 -> r14-7947-g9048f08f4e9459.