immunant / c2rust

Migrate C code to Rust
https://c2rust.com/
Other
3.93k stars 230 forks source link

c2rust-analyze: handle uses of statics #877

Open spernsteiner opened 1 year ago

spernsteiner commented 1 year ago

On lighttpd, our second-largest source of panics is the Operand::Constant case of type_of, which currently doesn't allow any pointers or references to appear in the type of the constant. Constants of reference type are used for accessing statics - here is an example:

static MY_STATIC: i32 = 12345;
let x = MY_STATIC;
// Produces the following MIR:
_2 = const {alloc1: &i32};
_1 = (*_2);

Here, alloc1 is the static allocation used to store the value of MY_STATIC. The value assigned to _2 is an Operand::Constant of type &i32, which currently causes a panic in our static analysis.

There are several different cases observed in lighttpd that we'd eventually like to handle:

Lookup tables are probably the easiest, but the handling of that case is entirely separate from the main analysis. Aside from that, strings and bytestrings also seem relatively simple, and adding support for these to the dataflow analysis could provide some ideas on how to handle the more complex cases.

aneksteind commented 1 year ago

@fw-immunant @kkysen just wanted to check to see if anything else should be crossed off this list given your work in this area

kkysen commented 1 year ago

@fw-immunant @kkysen just wanted to check to see if anything else should be crossed off this list given your work in this area

Just the string literals, which I've checked the box for now.