[cfe-dev] UBSan & Function Pointer: Is this illegal?

Kazunari Kudo who.is.kazunari at gmail.com
Sat Jan 17 23:32:41 PST 2015


Dear All,

I wrote a program and it compiled by Clang 3.4 with its undefined behavior sanitizer. However, the sanitizer warned it as follows that a type-mismatched function call was made in the code even though the type looked to be the same as my original intention. I would appreciate if someone could give me an explanation about the reason behind the warning (the warning actually is a runtime error though).

==11410==WARNING: Trying to symbolize code, but external symbolizer is not initialized!
path/to/HelloWorld.cpp:25:13: runtime error: call to function (unknown) through pointer to incorrect function type 'foo::CBar &(*)()'
(./libFoo.so+0x20af0): note: (unknown) defined here

I have confirmed some facts of the target function, which triggers the issue, are summarized as follows:

* The target function is called through a function pointer, which is exported from another library / shared object.
* The target function returns a user-defined type (class or struct) or has a user-defined type as its argument.
* If the return value or the arguments are C++ standard library class such as std::string or std::vector, the issue doesn’t happen.

To review the source code in detail, please have a look at the following stackoverflow page. I will provide you the source files if it’s not good to introduce a URL reference on the mailing list.

Clang's UBSan & Function Pointer: Is this illegal?
http://stackoverflow.com/questions/27976687/clangs-ubsan-function-pointer-is-this-illegal <http://stackoverflow.com/questions/27976687/clangs-ubsan-function-pointer-is-this-illegal>

Best regards,
Kazunari

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150118/3baed5af/attachment.html>


More information about the cfe-dev mailing list