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

Fix handling of undef integer values. #158

Merged
merged 5 commits into from
Jul 16, 2021
Merged

Fix handling of undef integer values. #158

merged 5 commits into from
Jul 16, 2021

Conversation

artemdinaburg
Copy link
Contributor

Fix handling of undef integer values
This was the source of a segfault due to a failed cast.

result = ast.CreateAdjustedIntLit(val);
}
} else if (llvm::isa<llvm::UndefValue>(constant)) {
//NOTE(artem):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably going to be a more general issue, of having to deal with undef vals. I'm going to wait for @surovic to implement a fix in a way that he sees fit, as he might want to factor out handling of undefs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really have a plan for undef values yet. So for now, I guess this is a good enough fix. Added as issue #159

@artemdinaburg do you have an input that I could put to the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I had to read the undefined value description a bit more.

An undef (if not frozen, which we have not run into yet) can take any value. This is not undefined behavior, but an undefined value.

My opinion is that:

  1. This is probably due to some anvill issue, and anvill should definitely have a pass to see if undef leaks out to final bitcode.
  2. We may have undef as a legitimate source into rellic, if, say, the ISA specs for some instruction specify a register is in an undefined state, and then the register is used.
  3. The current behavior (assume that an undef pointer is NULL) is perfectly valid, since it can indeed be NULL.
  4. For this specific PR, we should return a constant integer of 0 of the right bit width (not cast to a pointer, as this is an int value). I will see if I can make the change.
  5. From a correctness and "what does the user expect?" standpoint, I think we should pick a value (say, zero) and emit function call like:
int32_t rellic_undefined_value_int32() {
#pragma error "The input bitcode uses an undefined value. This may not be an error, but it probably is. Uncomment this pragma to achieve recompilable code.
return 0; // any value works here
}

...
int var0 = rellic_undefined_value_int32();
...

The user of the decompiled code can then figure out what they want to do about the undef, and static analysis tools should be trivially able to see that rellic_undefined_value_*() returns 0 (or 42 or whatever we pick).

unittests/AST/ASTBuilder.cpp Outdated Show resolved Hide resolved
@surovic surovic merged commit 7dbd01d into master Jul 16, 2021
@surovic surovic deleted the fix-undef-integer branch July 16, 2021 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants