Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respin the builtin PR #2693

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Respin the builtin PR #2693

merged 1 commit into from
Dec 18, 2023

Conversation

dkm
Copy link
Member

@dkm dkm commented Oct 16, 2023

Add 1 extra on top of previous PR from Arthur that
adds attribute support.

Must be squashed with the original to get a working change.

@dkm dkm marked this pull request as draft October 16, 2023 21:20
@dkm dkm self-assigned this Oct 16, 2023
@dkm dkm force-pushed the dkm/builtin_respin branch from 9d0ec98 to a7eaf19 Compare October 16, 2023 21:25
@CohenArthur
Copy link
Member

ah, while doing a quick review I noticed that this commit also includes some of the new intrinsics I was adding at the time @dkm. I have no idea if these are correct or not, and you can probably drop them if you'd like to avoid some headache

@dkm
Copy link
Member Author

dkm commented Oct 20, 2023

ah, while doing a quick review I noticed that this commit also includes some of the new intrinsics I was adding at the time @dkm. I have no idea if these are correct or not, and you can probably drop them if you'd like to avoid some headache

I'll try to add some test for said intrinsics (I didn't notice them while adjusting the patch, but I guess I'll find them easily?). Would be better to have them in now, while I'm at it :)

@dkm dkm force-pushed the dkm/builtin_respin branch from 3166894 to 712d6df Compare October 20, 2023 18:10
@dkm
Copy link
Member Author

dkm commented Oct 22, 2023

ah, while doing a quick review I noticed that this commit also includes some of the new intrinsics I was adding at the time @dkm. I have no idea if these are correct or not, and you can probably drop them if you'd like to avoid some headache

I'll try to add some test for said intrinsics (I didn't notice them while adjusting the patch, but I guess I'll find them easily?). Would be better to have them in now, while I'm at it :)

@CohenArthur can you elaborate a bit on which intrinsics you were trying to add?

@dkm dkm force-pushed the dkm/builtin_respin branch from e7d2cd2 to e487afd Compare October 22, 2023 17:10
@dkm dkm force-pushed the dkm/builtin_respin branch 3 times, most recently from ce3a3cb to 336ca8f Compare November 11, 2023 14:59
@dkm dkm marked this pull request as ready for review November 11, 2023 15:00
@dkm dkm requested a review from CohenArthur November 11, 2023 15:00
@dkm dkm force-pushed the dkm/builtin_respin branch from 336ca8f to 4907f4d Compare November 11, 2023 15:01
@dkm
Copy link
Member Author

dkm commented Nov 11, 2023

@CohenArthur should be in a good enough state. Haven't touched too much at your code, but fixed some shortcoming (mainly the attributes that were dropped when including the .def file).
If/when it's approved, I'll squashed both and mark mysel as Co-authored-by so that the bootstrap is happy (hopefully).

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great @dkm! Thank you for taking the time :) I'll run a bootstrap build on it if you want before we merge it

@dkm
Copy link
Member Author

dkm commented Nov 21, 2023

Looks great @dkm! Thank you for taking the time :) I'll run a bootstrap build on it if you want before we merge it

I've already tested the bootstrap build on x86_64-linux, but feel free to test again, we don't want to introduce any bootstrap issues :)

@dkm
Copy link
Member Author

dkm commented Nov 21, 2023

Let me first squash everything!

@dkm dkm force-pushed the dkm/builtin_respin branch 2 times, most recently from eec212d to f05b149 Compare November 23, 2023 07:58
@dkm
Copy link
Member Author

dkm commented Nov 23, 2023

Hmmm, there are issues on gcc 4.8 and MacOS.

@dkm
Copy link
Member Author

dkm commented Nov 29, 2023

Strangely, the compiler doesn't ICE locally, will try with a gcc 4.8.

 215   │ crab1: internal compiler error: Segmentation fault
 216   │ 0x12e528f crash_signal
 217   │     ../../gcc/toplev.cc:314
 218   │ 0x7f730443650f ???
 219   │     ./signal/../sysdeps/unix/sysv/linux/x86_64/libc_sigaction.c:0
 220   │ 0xccd827 Rust::Compile::BuiltinsContext::define_function_type(Rust::Compile::BuiltinsContext::Type, Rust::Compile::BuiltinsContext::Type, bool, unsigned long, ...)
 221   │     ../../gcc/rust/backend/rust-builtins.cc:65
 222   │ 0xcd28bb Rust::Compile::BuiltinsContext::define_builtin_types()
 223   │     ../../gcc/builtin-types.def:967
 224   │ 0xcd3c78 Rust::Compile::BuiltinsContext::setup()
 225   │     ../../gcc/rust/backend/rust-builtins.cc:358
 226   │ 0xcd3d3b Rust::Compile::BuiltinsContext::get()
 227   │     ../../gcc/rust/backend/rust-builtins.cc:30

@dkm
Copy link
Member Author

dkm commented Nov 29, 2023

That's fun, valgrind output loads of error with a gccrs built using gcc-4.8 as the base compiler, but it's clean with a gccrs built using a more recent base compiler.

@CohenArthur
Copy link
Member

That's fun, valgrind output loads of error with a gccrs built using gcc-4.8 as the base compiler, but it's clean with a gccrs built using a more recent base compiler.

yuuuuuuumm :) C++almost11 strikes again!!

@dkm
Copy link
Member Author

dkm commented Dec 6, 2023

That's fun, valgrind output loads of error with a gccrs built using gcc-4.8 as the base compiler, but it's clean with a gccrs built using a more recent base compiler.

yuuuuuuumm :) C++almost11 strikes again!!

But it seems it's not related to C++11.
The code crashed on:

      auto arg_idx = va_arg (list, size_t);
      auto arg_type = builtin_types[arg_idx];

with arg_idx being ridiculously large. The original D code has the same sequence but it pulls int not size_t from ..., and indeed, using int works® and matches the symptoms (size_t being 8 and int being 4 bytes, on lp64).

But the "real" argument being passed is an enum Type, and using this in the va_arg call gives a nice warning (thank you compiler):

../../gcc/rust/backend/rust-builtins.cc: In member function ‘void Rust::Compile::BuiltinsContext::define_function_type(Rust::Compile::BuiltinsContext::Type, Rust::Compile::Bu
iltinsContext::Type, bool, size_t, ...)’:                                                                                                                                     
../../gcc/rust/backend/rust-builtins.cc:64:36: warning: ‘Rust::Compile::BuiltinsContext::Type’ is promoted to ‘int’ when passed through ‘...’ [enabled by default]            
       auto arg_idx = va_arg (list, Type);                                                                                                                                    
                                    ^                                                                                                                                         
../../gcc/rust/backend/rust-builtins.cc:64:36: note: (so you should pass ‘int’ not ‘Rust::Compile::BuiltinsContext::Type’ to ‘va_arg’)                                        
../../gcc/rust/backend/rust-builtins.cc:64:36: note: if this code is reached, the program will abort           

See SO post about that: https://stackoverflow.com/questions/24580503/error-when-pass-enum-in-a-function-with-variable-arguments

@dkm dkm force-pushed the dkm/builtin_respin branch from f05b149 to 3369b90 Compare December 6, 2023 21:46
@dkm
Copy link
Member Author

dkm commented Dec 7, 2023

MacOS 😭

@dkm
Copy link
Member Author

dkm commented Dec 7, 2023

MacOS 😭

ok, easy fix...

This commit performs builtin initialization in a more "GCC-y" way,
similarly to what the D frontend is doing. This way, we no longer have
to worry about invalid attributes or types when initializing them by
hand.

Also add attributes support through LANG_HOOKS_COMMON_ATTRIBUTE_TABLE
lang hook.

Most of these changes are based on D frontend.

gcc/rust/ChangeLog:

	* Make-lang.in (GRS_OBJS): Add rust-attribs.o.
	* backend/rust-builtins.cc (builtin_const, builtin_noreturn)
	(builtin_novops): Remove.
	(BuiltinsContext::lookup_simple_builtin): Adjust.
	(BuiltinsContext::setup_overflow_fns): Remove.
	(BuiltinsContext::define_function_type): Set builtin type to
	errormark so the builtin is considered unavailable.
	(BuiltinsContext::setup_math_fns): Remove.
	(BuiltinsContext::setup_atomic_fns): Remove.
	(build_c_type_nodes): Refactor based on D frontend.
	(BuiltinsContext::define_builtin_types): Likewise.
	(DEF_PRIMITIVE_TYPE): New.
	(DEF_FUNCTION_TYPE_0): New.
	(DEF_FUNCTION_TYPE_1): New.
	(DEF_FUNCTION_TYPE_2): New.
	(DEF_FUNCTION_TYPE_3): New.
	(DEF_FUNCTION_TYPE_4): New.
	(DEF_FUNCTION_TYPE_5): New.
	(DEF_FUNCTION_TYPE_6): New.
	(DEF_FUNCTION_TYPE_7): New.
	(DEF_FUNCTION_TYPE_8): New.
	(DEF_FUNCTION_TYPE_9): New.
	(DEF_FUNCTION_TYPE_10): New.
	(DEF_FUNCTION_TYPE_11): New.
	(DEF_FUNCTION_TYPE_VAR_0): New.
	(DEF_FUNCTION_TYPE_VAR_1): New.
	(DEF_FUNCTION_TYPE_VAR_2): New.
	(DEF_FUNCTION_TYPE_VAR_3): New.
	(DEF_FUNCTION_TYPE_VAR_4): New.
	(DEF_FUNCTION_TYPE_VAR_5): New.
	(DEF_FUNCTION_TYPE_VAR_6): New.
	(DEF_FUNCTION_TYPE_VAR_7): New.
	(DEF_FUNCTION_TYPE_VAR_11): New.
	(DEF_POINTER_TYPE): New.
	(BuiltinsContext::setup): Adjust.
	(BuiltinsContext::define_builtin_attributes): New.
	(DEF_ATTR_NULL_TREE): New.
	(DEF_ATTR_INT): New.
	(DEF_ATTR_STRING): New.
	(DEF_ATTR_IDENT): New.
	(DEF_ATTR_TREE_LIST): New.
	(handle_flags): Remove.
	(BuiltinsContext::define_builtins): New.
	(DEF_BUILTIN): New.
	(BuiltinsContext::define_builtin): Remove.
	(BuiltinsContext::register_rust_mappings): New. Add all missing
	builtins.
	(BuiltinsContext::lookup_gcc_builtin): Adjust.
	* backend/rust-builtins.h (DEF_PRIMITIVE_TYPE): New.
	(DEF_FUNCTION_TYPE_0): New.
	(DEF_FUNCTION_TYPE_1): New.
	(DEF_FUNCTION_TYPE_2): New.
	(DEF_FUNCTION_TYPE_3): New.
	(DEF_FUNCTION_TYPE_4): New.
	(DEF_FUNCTION_TYPE_5): New.
	(DEF_FUNCTION_TYPE_6): New.
	(DEF_FUNCTION_TYPE_7): New.
	(DEF_FUNCTION_TYPE_8): New.
	(DEF_FUNCTION_TYPE_9): New.
	(DEF_FUNCTION_TYPE_10): New.
	(DEF_FUNCTION_TYPE_11): New.
	(DEF_FUNCTION_TYPE_VAR_0): New.
	(DEF_FUNCTION_TYPE_VAR_1): New.
	(DEF_FUNCTION_TYPE_VAR_2): New.
	(DEF_FUNCTION_TYPE_VAR_3): New.
	(DEF_FUNCTION_TYPE_VAR_4): New.
	(DEF_FUNCTION_TYPE_VAR_5): New.
	(DEF_FUNCTION_TYPE_VAR_6): New.
	(DEF_FUNCTION_TYPE_VAR_7): New.
	(DEF_FUNCTION_TYPE_VAR_11): New.
	(DEF_POINTER_TYPE): New.
	(DEF_ATTR_NULL_TREE): New.
	(DEF_ATTR_INT): New.
	(DEF_ATTR_STRING): New.
	(DEF_ATTR_IDENT): New.
	(DEF_ATTR_TREE_LIST): New.
	* backend/rust-compile-intrinsic.cc (Intrinsics::compile): Add
	comment.
	(op_with_overflow_inner): Adjust.
	(copy_handler_inner): Adjust.
	(prefetch_data_handler): Adjust.
	(build_atomic_builtin_name): Adjust.
	(atomic_load_handler_inner): Adjust.
	(uninit_handler): Adjust.
	(move_val_init_handler): Adjust.
	(expect_handler_inner): Adjust.
	* rust-gcc.cc (fetch_overflow_builtins): Adjust.
	* rust-lang.cc (rust_localize_identifier): Adjust.
	(LANG_HOOKS_COMMON_ATTRIBUTE_TABLE): New.
	* rust-attribs.cc: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/intrinsics-4.rs: Adjust.
	* rust/compile/torture/intrinsics-math.rs: Adjust.
	* rust/execute/torture/atomic_load.rs: Adjust.
	* rust/execute/torture/atomic_store.rs: Adjust.
	* rust/compile/torture/intrinsics-1.rs: Removed.
	* rust/compile/torture/builtin_abort.rs: New test.
	* rust/execute/torture/builtin_abort.rs: New test.

Signed-off-by: Marc Poulhiès <[email protected]>
Co-authored-by: Arthur Cohen <[email protected]>
@dkm dkm force-pushed the dkm/builtin_respin branch from ac2557f to 4554090 Compare December 9, 2023 20:56
@CohenArthur CohenArthur added this pull request to the merge queue Dec 18, 2023
Merged via the queue into master with commit f7127fc Dec 18, 2023
9 checks passed
@dkm dkm deleted the dkm/builtin_respin branch February 16, 2024 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants