<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - clang leaks 80 bytes (one BasicBlock) in code like void f () try {} catch (...) {}"
href="http://llvm.org/bugs/show_bug.cgi?id=18318">18318</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang leaks 80 bytes (one BasicBlock) in code like void f () try {} catch (...) {}
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kcc@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>earthdok@google.com, llvmbugs@cs.uiuc.edu, samsonov@google.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>fresh clang r197977, tested on x86_64 linux
Reproduce:
1. build clang with asan (cmake option -DLLVM_USE_SANITIZER=Address) or run
regular clang under valgrind
% cat z.cc
void f () try {} catch (...) {}
% ASAN_OPTIONS=detect_leaks=1 clang -c z.cc
Indirect leak of 80 byte(s) in 1 object(s) allocated from:
#0 0x75f046 in operator new(unsigned long)
/home/kcc/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:54
#1 0x487800e in getLLVMContext
/home/kcc/llvm/include/llvm/IR/BasicBlock.h:111
#2 0x487800e in Twine
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenFunction.h:1278
#3 0x487800e in
clang::CodeGen::CodeGenFunction::EnterCXXTryStmt(clang::CXXTryStmt const&,
bool) /home/kcc/llvm/tools/clang/lib/CodeGen/CGException.cpp:593
#4 0x4877cf3 in
clang::CodeGen::CodeGenFunction::EmitCXXTryStmt(clang::CXXTryStmt const&)
/home/kcc/llvm/tools/clang/lib/CodeGen/CGException.cpp:581
#5 0x466db8e in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt
const*) /home/kcc/llvm/tools/clang/lib/CodeGen/CGStmt.cpp:167
#6 0x46a4f39 in EmitFunctionBody
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:648
#7 0x46a4f39 in
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenFunction.
#8 0x46c98a5 in
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2174
#9 0x46c2119 in
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:1359
#10 0x46c6f13 in
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:1216
#11 0x46ce46a in
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2915
#12 0x45ebadd in (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
/home/kcc/llvm/tools/clang/lib/CodeGen/ModuleBuilder.cpp:81
#13 0x45e9760 in
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:96
#14 0x4b97353 in clang::ParseAST(clang::Sema&, bool, bool)
/home/kcc/llvm/tools/clang/lib/Parse/ParseAST.cpp:142
#15 0x45e6adf in clang::CodeGenAction::ExecuteAction()
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenAction.cpp:431
#16 0x36e8913 in clang::FrontendAction::Execute()
/home/kcc/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:378
#17 0x3673c30 in
clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
/home/kcc/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:707
#18 0x3881cd6 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
/home/kcc/llvm/tools/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:237
#19 0x780a95 in cc1_main(char const**, char const**, char const*, void*)
/home/kcc/llvm/tools/clang/tools/driver/cc1_main.cpp:100
#20 0x77b8c6 in main /home/kcc/llvm/tools/clang/tools/driver/driver.cpp:314
#21 0x7fb1d9c1776c in __libc_start_main
/build/buildd/eglibc-2.15/csu/libc-start.c:226
Indirect leak of 22 byte(s) in 1 object(s) allocated from:
#0 0x75e876 in __interceptor_malloc
/home/kcc/llvm/projects/compiler-rt/lib/asan/asan_malloc_linux.cc:74
#1 0x321e859 in Allocate /home/kcc/llvm/include/llvm/Support/Allocator.h:36
#2 0x321e859 in Create<llvm::MallocAllocator, llvm::Value *>
/home/kcc/llvm/include/llvm/ADT/StringMap.h:161
#3 0x321e859 in Create<llvm::Value *>
/home/kcc/llvm/include/llvm/ADT/StringMap.h:187
#4 0x321e859 in Create /home/kcc/llvm/include/llvm/ADT/StringMap.h:191
#5 0x321e859 in llvm::Value::setName(llvm::Twine const&)
/home/kcc/llvm/lib/IR/Value.cpp:217
#6 0x4878027 in getLLVMContext
/home/kcc/llvm/include/llvm/IR/BasicBlock.h:111
#7 0x4878027 in Twine
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenFunction.h:1278
#8 0x4878027 in
clang::CodeGen::CodeGenFunction::EnterCXXTryStmt(clang::CXXTryStmt const&,
bool) /home/kcc/llvm/tools/clang/lib/CodeGen/CGException.cpp:593
#9 0x4877cf3 in
clang::CodeGen::CodeGenFunction::EmitCXXTryStmt(clang::CXXTryStmt const&)
/home/kcc/llvm/tools/clang/lib/CodeGen/CGException.cpp:581
#10 0x466db8e in clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt
const*) /home/kcc/llvm/tools/clang/lib/CodeGen/CGStmt.cpp:167
#11 0x46a4f39 in EmitFunctionBody
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenFunction.cpp:648
#12 0x46a4f39 in
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenFunction
#13 0x46c98a5 in
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
/home/kcc/llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:2174
...
# or
% valgrind --leak-check=full clang -cc1 -emit-obj -fcxx-exceptions -x
c++ z.cc
==20232== 102 (80 direct, 22 indirect) bytes in 1 blocks are definitely lost in
loss record 9 of 9
==20232== at 0x402F2A9: operator new(unsigned long)
(valgrind/coregrind/m_replacemalloc/vg_replace_malloc.c:298)
==20232== by 0x18ED87F:
clang::CodeGen::CodeGenFunction::EnterCXXTryStmt(clang::CXXTryStmt const&,
bool)
==20232== by 0x18ED770:
clang::CodeGen::CodeGenFunction::EmitCXXTryStmt(clang::CXXTryStmt const&)
==20232== by 0x185455B:
clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*)
==20232== by 0x1865B31:
clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl,
llvm::Function*, clang::CodeGen::CGFunctionInfo const&)
==20232== by 0x1870DE3:
clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
==20232== by 0x186E4BB:
clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl,
llvm::GlobalValue*)
==20232== by 0x186FFE4:
clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl)
==20232== by 0x187299A:
clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*)
==20232== by 0x182809E: (anonymous
namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef)
==20232== by 0x1827636:
clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef)
==20232== by 0x19CBEE2: clang::ParseAST(clang::Sema&, bool, bool)
The leak is easy to see w/o any leak detection tools as every function with
such code leaks 102 bytes (80 bytes for NDEBUG build)
gen.sh:
#!/bin/bash
echo "#define X(a) void f ## a () try {} catch (...) {}"
for((i=0;i<$1;i++)); do echo "X($i)"; done
% for((i=1;i<1000000;i*=2)); do ./gen.sh $i > a.cc; /usr/bin/time
--format="i=$i; max mem: %M" clang a.cc -c ; done
i=1; max mem: 42592
i=2; max mem: 42608
i=4; max mem: 42672
i=8; max mem: 42688
i=16; max mem: 42704
i=32; max mem: 43088
i=64; max mem: 43808
i=128; max mem: 45392
i=256; max mem: 48528
i=512; max mem: 54816
i=1024; max mem: 67248
i=2048; max mem: 92160
i=4096; max mem: 141792
i=8192; max mem: 241968
i=16384; max mem: 441904
i=32768; max mem: 843296
i=65536; max mem: 1645216
i=131072; max mem: 3249392
i=262144; max mem: 6458560
i=524288; max mem: 12874608</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>