[cfe-dev] valgrind memcheck shows leaks in svn clang compile of simplest c++ program

John McCall rjmccall at apple.com
Thu Jan 3 12:05:05 PST 2013


On Dec 30, 2012, at 1:40 PM, Larry Evans <cppljevans at suddenlink.net> wrote:

> On 12/30/12 12:52, Sebastian Redl wrote:
>> 
>> On 30.12.2012, at 14:33, Larry Evans wrote:
>> 
>>> Is using valgrind memcheck a good way to detect memory leaks in clang?
>> 
>> No. Look at this part of the command line:
>> 
>>>> ==5556== Command: /home/evansl/download/llvm/svn/top/out/debug/install/bin/clang -cc1 -disable-free
>> 
>> This option (passed by default from the driver to the main compiler) instructs Clang not to free any of the AST nodes it allocates, to save time on process shutdown. So obviously they all leak.
>> 
>> Sebastian
> I managed to change to args to the main compiler so that -disable-free
> no longer appears in the memcheck output:
> 
> ==13487== Memcheck, a memory error detector
> ==13487== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
> ==13487== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for
> copyright info
> ==13487== Command:
> /home/evansl/download/llvm/svn/top/out/debug/install/bin/clang -cc1
> -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all
> -disable-llvm-verifier -main-file-name tuple.benchmark.nop.cpp
> -mrelocation-model static -mdisable-fp-elim -fmath-errno -masm-verbose
> -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu
> x86-64 -target-linker-version 2.20.1 -momit-leaf-frame-pointer
> -coverage-file
> /home/evansl/prog_dev/boost-svn/ro/boost_1_49_0/sandbox/rw/variadic_templates/sandbox/slim/test.work/tuple.benchmark.nop.o
> -resource-dir
> /home/evansl/download/llvm/svn/top/out/debug/install/bin/../lib/clang/3.3 -D
> TUPLE_IMPL=bcon12_horizontal -D TUPLE_SIZE=10 -D TUPLE_UNROLL_MAX=-1 -D
> TREE_DEPTH=2 -D TUPLE_TEMPLATED_CTOR=1 -I
> /home/evansl/prog_dev/boost-svn/ro/boost_1_49_0 -fmodule-cache-path
> /var/tmp/clang-module-cache -internal-isystem
> /home/evansl/download/gcc/4.8-20121028/install/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../include/c++/4.8.0
> -internal-isystem
> /home/evansl/download/gcc/4.8-20121028/install/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../include/c++/4.8.0/x86_64-unknown-linux-gnu
> -internal-isystem
> /home/evansl/download/gcc/4.8-20121028/install/lib/gcc/x86_64-unknown-linux-gnu/4.8.0/../../../../include/c++/4.8.0/backward
> -internal-isystem /usr/local/include -internal-isystem
> /home/evansl/download/llvm/svn/top/out/debug/install/bin/../lib/clang/3.3/include
> -internal-externc-isystem /usr/include/x86_64-linux-gnu
> -internal-externc-isystem /include -internal-externc-isystem
> /usr/include -std=c++11 -fdeprecated-macro -fdebug-compilation-dir
> /home/evansl/prog_dev/boost-svn/ro/boost_1_49_0/sandbox/rw/variadic_templates/sandbox/slim/test.work
> -ferror-limit 19 -fmessage-length 0 -mstackrealign -fobjc-runtime=gcc
> -fcxx-exceptions -fexceptions -fdiagnostics-show-option -backend-option
> -vectorize-loops -o tuple.benchmark.nop.o -x c++ tuple.benchmark.nop.cpp
> ==13487==
> --13487-- Valgrind options:
> --13487--    --suppressions=/usr/lib/valgrind/debian-libc6-dbg.supp
> --13487--    --tool=memcheck
> --13487--    -v
> --13487--    --leak-check=full
> --13487--    --show-reachable=yes
> --13487-- Contents of /proc/version:
> --13487--   Linux version 2.6.32-41-generic (buildd at yellow) (gcc version
> 4.4.3 (Ubuntu 4.4.3-4ubuntu5.1) ) #90-Ubuntu SMP Tue May 22 11:29:51 UTC
> 2012
> --13487-- Arch and hwcaps: AMD64, amd64-sse3-cx16
> --13487-- Page sizes: currently 4096, max supported 4096
> --13487-- Valgrind library directory: /usr/lib/valgrind
> --13487-- Reading syms from
> /home/evansl/download/llvm/svn/top/out/debug/install/bin/clang (0x400000)
> --13487-- Reading syms from /lib/ld-2.11.1.so (0x4000000)
> --13487-- Reading debug info from /lib/ld-2.11.1.so ..
> --13487-- .. CRC mismatch (computed d6b02b0b wanted 324d1273)
> --13487-- Reading debug info from /usr/lib/debug/lib/ld-2.11.1.so ..
> --13487-- Reading syms from /usr/lib/valgrind/memcheck-amd64-linux
> (0x38000000)
> --13487--    object doesn't have a dynamic symbol table
> --13487-- Reading suppressions file: /usr/lib/valgrind/debian-libc6-dbg.supp
> --13487-- Reading suppressions file: /usr/lib/valgrind/default.supp
> --13487-- REDIR: 0x4018390 (strlen) redirected to 0x380402d7
> (vgPlain_amd64_linux_REDIR_FOR_strlen)
> --13487-- Reading syms from
> /usr/lib/valgrind/vgpreload_core-amd64-linux.so (0x4a22000)
> --13487-- Reading syms from
> /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so (0x4c24000)
> ==13487== WARNING: new redirection conflicts with existing -- ignoring it
> --13487--     new: 0x04018390 (strlen              ) R-> 0x04c28710 strlen
> --13487-- REDIR: 0x4018200 (index) redirected to 0x4c28320 (index)
> --13487-- REDIR: 0x4018280 (strcmp) redirected to 0x4c28cf0 (strcmp)
> --13487-- Reading syms from /lib/libpthread-2.11.1.so (0x4e2d000)
> --13487-- Reading debug info from /lib/libpthread-2.11.1.so ..
> --13487-- .. CRC mismatch (computed d460a184 wanted 81aea168)
> .
> .
> .
> 
> 
> However, there's still a fair sized leak:

Could you file a bug?  It would be very reasonable for clang to delete
the TargetMachine after it's done with it when -disable-free isn't passed.

John.



More information about the cfe-dev mailing list