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

In the while loop body using a volatile variable, the generated code will lack a semicolon. #1064

Open
ahaoboy opened this issue Mar 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ahaoboy
Copy link

ahaoboy commented Mar 5, 2024

ubuntu2310 + llvm-config-15 + C2Rust 0.18.0

input:

#include <stdio.h>

static void Encode(char *str_)
{
  const char *volatile str = str_;
  static const char *HEX = "0123456789ABCDEF";
  while (*str)
  {
    int c = (unsigned char)*str++;
  }
}

int main()
{
  Encode(NULL);
  return 0;
}

output:

#![allow(dead_code, mutable_transmutes, non_camel_case_types, non_snake_case, non_upper_case_globals, unused_assignments, unused_mut)]
unsafe extern "C" fn Encode(mut str_: *mut libc::c_char) {
    let mut str: *const libc::c_char = str_;
    static mut HEX: *const libc::c_char = b"0123456789ABCDEF\0" as *const u8
        as *const libc::c_char;
    while *str != 0 {
        let fresh0 = ::core::ptr::read_volatile::<
            *const libc::c_char,
        >(&str as *const *const libc::c_char);
        ::core::ptr::write_volatile(
            &mut str as *mut *const libc::c_char,
            (::core::ptr::read_volatile::<
                *const libc::c_char,
            >(&str as *const *const libc::c_char))
                .offset(1),
        )
        let mut c: libc::c_int = *fresh0 as libc::c_uchar as libc::c_int;
    }
}
unsafe fn main_0() -> libc::c_int {
    Encode(0 as *mut libc::c_char);
    return 0 as libc::c_int;
}
pub fn main() {
    unsafe { ::std::process::exit(main_0() as i32) }
}
@kkysen kkysen added the bug Something isn't working label Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants