CTSRD-CHERI / clang

DO NOT USE. Use llvm-project instead
Other
9 stars 8 forks source link

Integer comparison in C++ between intcap_t values does a signed extend rather than zero extend #199

Closed khilangudka closed 6 years ago

khilangudka commented 6 years ago

The following example C++ code:

void foo() {
  intptr_t x = 0x2;
  intptr_t y = 0x3;
  intptr_t z = x == y;
}

Leads to the following LLVM IR in the purecap ABI (i.e. when intptr_t is __intcap_t) for the equality comparison:

  %cmp = icmp eq i8 addrspace(200)* %2, %3
  %conv = sext i1 %cmp to i64

However, when not compiling for the purecap ABI, or when using vanilla clang++, the following IR is generated:

  %cmp = icmp eq i32 %0, %1
  %conv = zext i1 %cmp to i32

The implications of what we are currently generating for the purecap ABI is that the resulting value is 0xFFFFFFFFFFFFFFFF (i.e. -1) instead of 0x1, which breaks some tests in WebKit's javascript interpreter that depend on 0x1 for true. We are doing the right thing for purecap C code.

I think we should be zero extending here to be consistent with C and the non-purecap C++ case.