[LLVMbugs] [Bug 20940] New: Runtime crash because of leaking exception in a destructor when compiled with "-std=c++11 -g -O0" clang.

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sun Sep 14 21:23:57 PDT 2014


http://llvm.org/bugs/show_bug.cgi?id=20940

            Bug ID: 20940
           Summary: Runtime crash because of leaking exception in a
                    destructor when compiled with "-std=c++11 -g -O0"
                    clang.
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: asg.msft at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Clang: version 3.4.

DESCRIPTION: Exception (throw 1;) is leaking in destructor although it's
guarded by catch(...). This causes the runtime to crash. This happens if the
code is compiled with "-std=c++11 -g -O0" clang option but doesn't happen with
"-std=c++11 -g -O2" option. Seems like optimization for -std=c++11 is
generating the incorrect code. Enabling the flag for exceptions with
"-fexceptions" didn't seem to matter. I've attached the respective .ii and .s
files. 

I'm not sure whether the main trunk of clang has this issue. The clang++.exe
I'm using is from Android NDK. I filed a bug for Android as well.

I minimized the code to the following in my app.
-------------------
Contents of foo.cpp
-------------------
void func()
{
    class CFoo
    {
    public:
        CFoo() {}

        ~CFoo() 
        { 
       // throw 1 leaks and terminate is called if compiled
           // with "-std=c++11 -g -O0".
           // There is no crash if compiled with "-std=c++11 -g -O2".
           try { throw 1; }
           catch (...) {}
        }
    };

    { CFoo a; }
}

----------------------
Compilation commands
----------------------

1)RUNTIME crash: App crashes while executing the "throw 1" stmt above when
compiled with:

clang++.exe -g -std=c++11 -O0 -c foo.cpp -o foo.o

.ARM.exidx dump:

0x0 <_Z4funcv>: 0x809b8480
  Compact model index: 0
  0x9b      vsp = r11
  0x84 0x80 pop {r11, r14}
0x30 <_ZZ4funcvEN4CFooC2Ev>: 0x1 [cantunwind]
0x44 <_ZZ4funcvEN4CFooD2Ev>: 0x1 [cantunwind]
Unwind table index '.ARM.exidx.text.__clang_call_terminate' at offset 0x45c
contains 1 entries:
0x0 <__clang_call_terminate>: 0x1 [cantunwind]

2)NO RUNTIME crash: App doesn't crash when compiled with:

clang++.exe -g -std=c++11 -O2 -c foo.cpp -o foo.o

.ARM.exidx dump:
Unwind table index '.ARM.exidx' at offset 0x3b8 contains 1 entries:
0x0 <_Z4funcv>: 0x1 [cantunwind]
Unwind table index '.ARM.exidx.text.__clang_call_terminate' at offset 0x3d4
contains 1 entries:
0x0 <__clang_call_terminate>: 0x1 [cantunwind]

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20140915/f4f8b9e0/attachment.html>


More information about the llvm-bugs mailing list