-
Notifications
You must be signed in to change notification settings - Fork 146
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
Add support for the freeze
instruction
#175
Comments
Is it actually possible to express this in C at all? I think undefined behaviours in C are global. |
I'm not sure. One option is to avoid undef and poison values altogether, for example we could always initialize variables, thus If I'm reading cppref correctly, there we may be able to safely access it via a From https://en.cppreference.com/w/c/language/initialization
From https://en.cppreference.com/w/c/language/object
I do have a test for this now, unfortunately it doesn't seem like casting to // Compile with clang -S test.c -emit-llvm -O3
#include <string.h>
#include <stdio.h>
int main(int argc, char** argv) {
int i;
int j /* = freeze i */;
// Insert "freeze" operation here...
char* tmp = (char*)&i;
memcpy(&j, tmp, sizeof(int));
// If j is correctly frozen, then k and j must have the same value.
int k = j;
// If j isn't frozen, then printf is called with `i32 undef, i32 undef`
printf("%d, %d", j, k);
return 0;
} |
Looking at LLVM IR for some Rust code, I noticed the
freeze
instruction that LLVM-CBE doesn't currently support: https://llvm.org/docs/LangRef.html#freeze-instructionI've been thinking about how we should handle this, but have run into a few issues:
memcpy
or a "black box" function that duplicates the value?The text was updated successfully, but these errors were encountered: