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

[E0133] Use of unsafe code outside of unsafe function or block #2424

Merged
merged 1 commit into from
Jul 13, 2023

Conversation

MahadMuhammad
Copy link
Contributor

E0133 Use of unsafe code outside of unsafe function or block

Code tested from E0133

// https://doc.rust-lang.org/error_codes/E0133.html
unsafe fn f() { return; } // This is the unsafe code

fn main() {
    f(); // error: call to unsafe function requires unsafe function or block
}

Output:

➜  gccrs-build gcc/crab1 ../mahad-testsuite/E0133.rs                                          
../mahad-testsuite/E0133.rs:4:5: error: call to unsafe function requires unsafe function or block [E0133]
    4 |     f(); // error: call to unsafe function requires unsafe function or block
      |     ^

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.gccrs-build 

Running TestCases:

➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/unsafe6.rs
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/unsafe6.rs:7:5: error: call to unsafe function requires unsafe function or block [E0133]
    7 |     foo(); // { dg-error "call to unsafe function" }
      |     ^~~
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/unsafe6.rs:8:5: error: call to unsafe function requires unsafe function or block [E0133]
    8 |     bar(); // { dg-error "call to unsafe function" }
      |     ^~~

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.
➜  gccrs-build gcc/crab1 /home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/unsafe8.rs                            
/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/unsafe8.rs:9:5: error: call to unsafe method requires unsafe function or block [E0133]
    9 |     s.foo(); // { dg-error "call to unsafe method" }
      |     ^

Analyzing compilation unit

Time variable                                   usr           sys          wall           GGC
 TOTAL                              :   0.00          0.00          0.00          146k
Extra diagnostic checks enabled; compiler may run slowly.
Configure with --enable-checking=release to disable checks.

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc (check_unsafe_call): called error function.

gcc/rust/ChangeLog:

	* checks/errors/rust-unsafe-checker.cc (check_unsafe_call):
	called error function.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

LGTM

@philberty philberty added the diagnostic diagnostic static analysis label Jul 13, 2023
@philberty philberty added this to the GCC 14 Stage 3 milestone Jul 13, 2023
@philberty philberty added this pull request to the merge queue Jul 13, 2023
Merged via the queue into Rust-GCC:master with commit 601c289 Jul 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants