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

Signed bitcode values emitted as unsigned C #132

Open
artemdinaburg opened this issue Apr 15, 2021 · 2 comments
Open

Signed bitcode values emitted as unsigned C #132

artemdinaburg opened this issue Apr 15, 2021 · 2 comments

Comments

@artemdinaburg
Copy link
Contributor

artemdinaburg commented Apr 15, 2021

Rellic will sometimes forget signedess and emit unsigned casts for signed integers. Simple example below:

signed.c:

#include <stdbool.h>

bool signed_less_than_1(signed short v) {
  return v < 1;
}

Compile:

clang-11 -O1 -std=c99 -emit-llvm -c -o signed.bc signed.c

Rellic:

rellic-decomp-11.0 --input signed.bc --output signed_decomp.c

Output:

unsigned char signed_less_than_1(unsigned short arg0);
unsigned char signed_less_than_1(unsigned short arg0) {
    return (arg0 < (unsigned short)1U);
}

The bitcode in question performs a signed compare, and rellic should emit a signed compare as well:

define dso_local zeroext i1 @signed_less_than_1(i16 signext %0) local_unnamed_addr #0 {
  %2 = icmp slt i16 %0, 1
  ret i1 %2
}
@surovic
Copy link
Contributor

surovic commented Jun 8, 2021

Resolved by #121

Unfortunately I haven't found a good way of regression testing this one using our executable roundtrip tests, because we don't have type inference.

@greenbagels
Copy link
Contributor

I might just be out of the loop, but it seems that the issue still exists; after building 356ecb1 and reproducing the test case, the LLVM IR is identical to before:

define dso_local zeroext i1 @signed_less_than_1(i16 signext %0) local_unnamed_addr #0 {
  %2 = icmp slt i16 %0, 1
  ret i1 %2
}

while the produced roundtrip code is slightly different, but still with the wrong type signature:

unsigned char signed_less_than_1(unsigned short arg0);
unsigned char signed_less_than_1(unsigned short arg0) {
    return (short)arg0 < 1;
}

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

No branches or pull requests

3 participants