diff options
author | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-11 12:01:10 +0200 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2022-08-11 14:52:40 +0200 |
commit | 8899dc9bf70b193dc59dbc8e81400de22c203e8f (patch) | |
tree | d9972cf5dfca4299cfebf9f9eb4958372b3c923e /gcc/rust/rust-lang.cc | |
parent | eca2ac2c23e0c8b438fd696d4f85e35c9210d8dd (diff) | |
download | gcc-8899dc9bf70b193dc59dbc8e81400de22c203e8f.zip gcc-8899dc9bf70b193dc59dbc8e81400de22c203e8f.tar.gz gcc-8899dc9bf70b193dc59dbc8e81400de22c203e8f.tar.bz2 |
intrinsics: Add wrapping_{add, sub, mul}
Since wrapping arithmetics are guaranteed in Rust, we turn on the -fwrapv and simply desugar wrapping_{add, sub, mul} to their non-checked inner operations. This is the only difference between a wrapping add and a regular addition: The regular addition will gain some checks for overflows, which are simply not used for the wrapping version.
Diffstat (limited to 'gcc/rust/rust-lang.cc')
-rw-r--r-- | gcc/rust/rust-lang.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc index 95c92f8..ed822cc 100644 --- a/gcc/rust/rust-lang.cc +++ b/gcc/rust/rust-lang.cc @@ -152,8 +152,14 @@ grs_langhook_option_lang_mask (void) /* Initialize the options structure. */ static void -grs_langhook_init_options_struct (struct gcc_options * /* opts */) +grs_langhook_init_options_struct (struct gcc_options *opts) { + /* Operations are always wrapping in Rust, even on signed integer. This is + * useful for the low level wrapping_{add, sub, mul} intrinsics, not for + * regular arithmetic operations which are checked for overflow anyway using + * builtins */ + opts->x_flag_wrapv = 1; + // nothing yet - used by frontends to change specific options for the language Rust::Session::get_instance ().init_options (); } |