-
Notifications
You must be signed in to change notification settings - Fork 11
Memory Model: pointer casts are not handled atm #147
Description
At the moment, pointer casts are not handled in the current memory model.
We encountered the issue because our mlir-toolchain packed some constants into a dense byte array (probably to reduce assembly size) and then later indexed into this array using a pointer of the original data type.
Since each constant is currently put into a single cell, the loads do not correctly recombine the (e.g., 4) bytes needed to correctly load an uint32_t from the uint8_t array.
here is a small example demonstrating the issue:
#include <stdlib.h>
#include <stdint.h>
#ifndef __ZKLLVM__
#include <iostream>
#endif
uint8_t global[4] = {1,1,1,1};
[[circuit]] int memory_demo() {
uint32_t* ptr = (uint32_t*)&global[0];
uint32_t val = *ptr;
#ifndef __ZKLLVM__
std::cout << val << std::endl;
#endif
return val;
}
#ifndef __ZKLLVM__
int main (int argc, char *argv[]){
memory_demo();
return 0;
}
#endifThe compiled version returns 0x01010101, while the assigner version returns 0x01;
We could work around this at the moment by forcing our mlir-toolchain to output constants as arrays of their original type, so this is not that big of a priority for us, but we were told to open an issue either way.