rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

The bindgen generated incorrect function signature for the C++ member function.

Open soloist-v opened this issue 2 years ago • 0 comments

bindgen would generate the incorrect binding for the C++ member function Dims getBindingDimensions(int32_t bindingIndex) const;. It would generate:

extern "C" {
    #[link_name = "\u{1}?getBindingDimensions@ICudaEngine@nvinfer1@@QEBA?AVDims32@2@H@Z"]
    pub fn ICudaEngine_getBindingDimensions(
        this: *const root::nvinfer1::ICudaEngine,
        bindingIndex: i32,
    ) -> root::nvinfer1::Dims;
}
// mov     rdx, [rbp+0A10h+var_7D8.raw]   ; the raw is this pointer
// lea     rcx, [rbp+0A10h+var_6C8]       ; return value Dims
// mov     r8d, 457h                      ; bindingIndex
// call    ?getBindingDimensions@ICudaEngine@nvinfer1@@QEBA?AVDims32@2@H@Z ;

Clearly, this result is incorrect as the this pointer will be passed through rdx (The this pointer should be passed through rcx). This will result in a segmentation fault.

In C++ complie correct result: Dims getBindingDimensions(int32_t bindingIndex) const;

...
mov     [rsp+arg_10], r8d   ; bindingIndex
mov     [rsp+arg_8], rdx    ; return value
mov     [rsp+arg_0], rcx    ; this pointer
...

soloist-v avatar Jul 10 '23 15:07 soloist-v