This commit is contained in:
nora 2023-05-30 16:40:05 +02:00
parent 3e1215e870
commit 096d0e78ac
6 changed files with 44 additions and 10 deletions

3
.gitignore vendored
View file

@ -1,5 +1,8 @@
/good
/bad
*.ll
*.s
a.out
# Added by cargo

View file

@ -5,7 +5,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[[bin]]
[lib]
name = "code"
path = "./code.rs"

View file

@ -1,7 +1,7 @@
#/usr/bin/env bash
rustc code.rs --crate-name bad -Zmir-enable-passes=-ConstProp -Copt-level=3
rustc code.rs --crate-name good -Zmir-enable-passes=+ConstProp -Copt-level=3
rustc code.rs --crate-name bad -Zmir-enable-passes=-ConstProp -Copt-level=3 --cfg pure_rust
rustc code.rs --crate-name good -Zmir-enable-passes=+ConstProp -Copt-level=3 --cfg pure_rust
bad=$(./bad)
good=$(./good)

7
checkllvm.sh Executable file
View file

@ -0,0 +1,7 @@
#!/usr/bin/env bash
rustc code.rs --crate-name ll -Zmir-enable-passes=-ConstProp --emit llvm-ir -Cno-prepopulate-passes --crate-type=lib
clang ll.ll helper.c
./a.out

26
code.rs
View file

@ -1,9 +1,18 @@
use std::ptr;
#[inline(never)]
pub fn print_var(v: u8) {
println!("{v}");
extern "C" {
pub fn print_var(v: u8);
}
pub unsafe fn fn12_rs() {
#[cfg(pure_rust)]
mod impl_ {
#[no_mangle]
pub extern "C" fn print_var(v: u8) {
println!("{v}");
}
}
#[no_mangle]
pub unsafe extern "C" fn fn12_rs() {
let mut bool_storage: bool = false;
let mut v9: usize = 0;
@ -12,7 +21,8 @@ pub unsafe fn fn12_rs() {
let v20_ptr = ptr::addr_of_mut!(v20);
let mut v12: *mut u8 = core::ptr::addr_of_mut!((*v20_ptr)[v9]);
v9 = 2_usize; // unused but necessary write
loop { // only runs once, but necessary
loop {
// only runs once, but necessary
match *v12 {
197 => {
let mut match_condition: u64 = 0;
@ -60,8 +70,10 @@ pub unsafe fn fn12_rs() {
}
}
}
pub fn main() {
#[cfg(pure_rust)]
fn main() {
unsafe {
fn12_rs();
}
}
}

12
helper.c Normal file
View file

@ -0,0 +1,12 @@
#include <stdio.h>
#include <stdint.h>
void print_var(uint8_t x) {
printf("%d", x);
}
void fn12_rs();
int main() {
fn12_rs();
}