[cfe-dev] Crash with C++exception. Bug in codegen, or in the developer ?
John McCall
rjmccall at apple.com
Fri Jul 13 13:32:42 PDT 2012
On Jul 13, 2012, at 12:17 PM, Jean-Daniel Dupas wrote:
> While running the following code, it crashes due to an invalid free operation:
>
> exc(8657) malloc: *** error for object 0x7f97c14039e0: pointer being freed was not allocated
> *** set a breakpoint in malloc_error_break to debug
> fish: Job 1, './exc' terminated by signal SIGABRT (Abort)
>
> --- --- --- --- ---
> #include <string>
>
> class Error {
> public:
> explicit inline Error(const std::string &str) noexcept {}
> };
>
> std::string _cxx_strfmt() noexcept { return std::string(); }
>
> int main(int argc, char **argv) {
> try {
> throw Error(_cxx_strfmt());
> } catch (...) {}
> }
> ------
>
> compiled using
> clang++ -std=c++11 exc.cpp
>
> I can't see what is wrong with this code, but if I remove the noexcept declaration (either one), it stop crashing and run as expected.
>
> Is this something I'm doing wrong, or this is a subtle clang bug ?
>
> I attach the llvm ir generate with noexcept (exc-crash.s) and the one without (exc.s)
>
> If this is a bug in clang, tell me, I will fill a report.
It's a clang bug; somehow we're unconditionally freeing the exception
in this case.
John.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120713/750aea3d/attachment.html>
More information about the cfe-dev
mailing list