Skip to content

FFI doesn't sign-extend 32-bit integer results from C #36122

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

Closed
sjindel-google opened this issue Mar 6, 2019 · 1 comment
Closed

FFI doesn't sign-extend 32-bit integer results from C #36122

sjindel-google opened this issue Mar 6, 2019 · 1 comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@sjindel-google
Copy link
Contributor

typedef NativeNullaryOpSigned = ffi.Int32 Function();

void testExtension() {
  ffi.Pointer fn = ffiTestFunctions.lookup("TestExtension");
  int Function() signedOp = fn
      .cast<ffi.Pointer<ffi.NativeFunction<NativeNullaryOpSigned>>>()
      .asFunction();
  Expect.equals(signedOp(), 0xffffffff80000000);
}
DART_EXPORT int32_t TestExtension() {
  return 1UL << 31;
}

@dcharkes @mraleph

@sjindel-google sjindel-google added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Mar 6, 2019
@sjindel-google sjindel-google self-assigned this Mar 6, 2019
@a-siva a-siva added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Mar 7, 2019
@dcharkes
Copy link
Contributor

We already have a test for this:

DART_EXPORT int32_t ReturnMinInt32() {
  return 0x80000000;
}
void testExtension() {
  Expect.equals(returnMaxUint8(), 0xff);
  Expect.equals(returnMaxUint16(), 0xffff);
  Expect.equals(returnMaxUint32(), 0xffffffff);
  Expect.equals(returnMinInt8(), -0x80);
  Expect.equals(returnMinInt16(), -0x8000);
  Expect.equals(returnMinInt32(), -0x80000000); // here is our test.

  Expect.equals(takeMaxUint8(0xff), 1);
  Expect.equals(takeMaxUint16(0xffff), 1);
  Expect.equals(takeMaxUint32(0xffffffff), 1);
  Expect.equals(takeMinInt8(0x80), 1);
  Expect.equals(takeMinInt16(0x8000), 1);
  Expect.equals(takeMinInt32(0x80000000), 1);
}

And

Expect.equals(-0x80000000, 0xffffffff80000000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants