[cfe-dev] Crash with C++exception. Bug in codegen, or in the developer ?

Jean-Daniel Dupas devlists at shadowlab.org
Fri Jul 13 14:16:06 PDT 2012


Le 13 juil. 2012 à 22:32, John McCall <rjmccall at apple.com> a écrit :

> 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.

Thanks, I filled it as Bug 13359 

-- Jean-Daniel




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120713/939b4479/attachment.html>


More information about the cfe-dev mailing list