gccrs: Add unsafe checks for Rust
commitb1b35204d8a186a6fadc8534e99e9161892192ac
authorArthur Cohen <arthur.cohen@embecosm.com>
Tue, 23 Aug 2022 15:31:17 +0000 (23 16:31 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 13 Dec 2022 13:00:06 +0000 (13 14:00 +0100)
treecf4c292fb42affbd0293c30229fb6cb510a5a059
parent06688fe40a249a406634d3307f662e2fe2e0c517
gccrs: Add unsafe checks for Rust

The UnsafeChecker visitor verifies that unsafe actions are only performed
in unsafe contexts. Otherwise, an error should be reported to the user and
the compilation pipeline should be halted. These contexts, which include
unsafe blocks or unsafe functions, are allowed to perform more actions
than regular safe Rust code. These actions currently include:

- Dereferencing raw pointers
- Calls to unsafe functions
- Use of inline assembly
- Use of mutable static
- Use of extern static
- Access to a union's field
- Call to functions with #[target(feature)] attribute
- Initializing type with rustc_layout_scalar_valid_range attribute
- Mutation of layout constrained field
- Borrow of layout constrained field

gcc/rust/
* checks/errors/rust-unsafe-checker.cc: New.
* checks/errors/rust-unsafe-checker.h: New.
gcc/rust/checks/errors/rust-unsafe-checker.cc [new file with mode: 0644]
gcc/rust/checks/errors/rust-unsafe-checker.h [new file with mode: 0644]