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

llvm: Stored value type does not match pointer operand type! #30494

Closed
yorkie opened this issue Dec 20, 2015 · 6 comments
Closed

llvm: Stored value type does not match pointer operand type! #30494

yorkie opened this issue Dec 20, 2015 · 6 comments
Labels
A-codegen Area: Code generation

Comments

@yorkie
Copy link
Contributor

yorkie commented Dec 20, 2015

Hey Rust Team,

I got this error at compiling time:

Stored value type does not match pointer operand type!
  store { i64 } %0, i64* %2, align 8
 i64LLVM ERROR: Broken function found, compilation aborted!
Could not compile `rustjs`.

Caused by:
  Process didn't exit successfully: `rustc src/lib.rs --crate-name rustjs --crate-type lib -g --out-dir /Users/yorkieliu/workspace/rust.js/target/debug --emit=dep-info,link -L dependency=/Users/yorkieliu/workspace/rust.js/target/debug -L dependency=/Users/yorkieliu/workspace/rust.js/target/debug/deps --extern clap=/Users/yorkieliu/workspace/rust.js/target/debug/deps/libclap-b681d5dfd49166f9.rlib --extern rustc_serialize=/Users/yorkieliu/workspace/rust.js/target/debug/deps/librustc_serialize-3c33cb2a40992011.rlib --extern libc=/Users/yorkieliu/workspace/rust.js/target/debug/deps/liblibc-dd3420cb049117bb.rlib --extern env_logger=/Users/yorkieliu/workspace/rust.js/target/debug/deps/libenv_logger-2fedde90a22290a6.rlib -l rustjs_deps` (exit code: 1)
make: *** [rustjs] Error 101

With my personal rust module: https://github.com/yorkie/rust.js, I found the same issue at #19571.

I used the latest 1.5.0, however it worked at 1.0.0.

@eddyb
Copy link
Member

eddyb commented Dec 21, 2015

This seems unrelated to #19571.
Can you try other versions? If your code compiles on them, that is.
If you have multirust, it should be trivial to switch between versions.

I could try to reduce rust.js myself, it looks like a moderately sized project.

@eddyb
Copy link
Member

eddyb commented Dec 21, 2015

Minimal reproduction:

struct Foo;
impl Foo {
    extern fn foo(_: [u8; 1]) {}
}

It appears that extern methods (not free functions) have their arguments incorrectly translated.
cc @dotdash @Aatch

@eddyb eddyb added the A-codegen Area: Code generation label Dec 21, 2015
@yorkie
Copy link
Contributor Author

yorkie commented Dec 21, 2015

Thanks @eddyb for that so detailed reply, do you think it's related to this commit yorkie/rust.js@9525af0?

@eddyb
Copy link
Member

eddyb commented Dec 21, 2015

No, not really.
The problem stems from the fact that you're passing structures by value in arguments, e.g.:

#[repr(C)]
pub struct FunctionCallbackInfo(*mut *mut FunctionCallbackInfo);

...

impl StringBytes {
  extern fn New(arguments: v8::FunctionCallbackInfo) {
    arguments.GetReturnValue().SetWithBool(true);
  }
}

One way you might be able to work around this bug would be to remove one level of indirection, e.g.

extern {
  fn v8_function_callback_info_get_return_value(this: &mut FunctionCallbackInfo) -> &mut ReturnValue;
}

// Doesn't really matter what's inside, can still pretend there's a pointer there.
#[repr(C)]
pub struct FunctionCallbackInfo(*mut u8);
#[repr(C)]
pub struct ReturnValue(*mut u8);

impl FunctionCallbackInfo {
  pub fn GetReturnValue(&mut self) -> &mut ReturnValue {
    unsafe { v8_function_callback_info_get_return_value(self) }
  }
}

impl StringBytes {
  extern fn New(arguments: &mut v8::FunctionCallbackInfo) {
    arguments.GetReturnValue().SetWithBool(true);
  }
}

And on the C++ side:

ReturnValue<Value> v8_function_callback_info_get_return_value(FunctionCallbackInfo<Value> *callbackInfo) {
  return callbackInfo->GetReturnValue();
}

It would be a pretty big change, but it should make your code compile.

@eddyb
Copy link
Member

eddyb commented Dec 21, 2015

@yorkie Sorry, I was overthinking this, you should be able to get away with just moving extern fn methods out of impl blocks (and make them free functions).

This issue is also related to #30235.

@arielb1
Copy link
Contributor

arielb1 commented Apr 27, 2016

duplicate of #30235.

@arielb1 arielb1 closed this as completed Apr 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

No branches or pull requests

3 participants