[llvm-dev] Possible Memory leak while compiling.

Tomar, Sourabh Singh via llvm-dev llvm-dev at lists.llvm.org
Tue Dec 8 23:15:34 PST 2020


Hi Alexandre,

I tried removing `-disable-free` from CLANG default commandline, but VALGRIND still reports leaks(quantitatively same as with `-disable-free` passed):

Summary:
**with -disable-free**
==22725== Command: /home/trunk/build/release/bin/clang main.c -g
==22725==
==22725==
==22725== HEAP SUMMARY:
==22725==     in use at exit: 251,896 bytes in 12 blocks
==22725==   total heap usage: 3,754 allocs, 3,742 frees, 734,893 bytes allocated
==22725==
==22725== LEAK SUMMARY:
==22725==    definitely lost: 67,584 bytes in 1 blocks
==22725==    indirectly lost: 0 bytes in 0 blocks
==22725==      possibly lost: 0 bytes in 0 blocks
==22725==    still reachable: 184,312 bytes in 11 blocks
==22725==         suppressed: 0 bytes in 0 blocks
==22725== Rerun with --leak-check=full to see details of leaked memory
==22725==
==22725== For counts of detected and suppressed errors, rerun with: -v
==22725== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

**After removing -disable-free**
==22506== Command: /home/trunk/build/release/bin/clang main.c -g
==22506==
==22506==
==22506== HEAP SUMMARY:
==22506==     in use at exit: 251,896 bytes in 12 blocks
==22506==   total heap usage: 3,754 allocs, 3,742 frees, 734,869 bytes allocated
==22506==
==22506== LEAK SUMMARY:
==22506==    definitely lost: 67,584 bytes in 1 blocks
==22506==    indirectly lost: 0 bytes in 0 blocks
==22506==      possibly lost: 0 bytes in 0 blocks
==22506==    still reachable: 184,312 bytes in 11 blocks
==22506==         suppressed: 0 bytes in 0 blocks
==22506== Rerun with --leak-check=full to see details of leaked memory
==22506==
==22506== For counts of detected and suppressed errors, rerun with: -v
==22506== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

Thanks,
Sourabh.

From: Alexandre Ganea <alexandre.ganea at ubisoft.com>
Sent: Monday, November 23, 2020 7:36 PM
To: Tomar, Sourabh Singh <SourabhSingh.Tomar at amd.com>
Cc: llvm-dev <llvm-dev at lists.llvm.org>; cfe-dev at lists.llvm.org
Subject: RE: Possible Memory leak while compiling.

[CAUTION: External Email]
Hello Tomar,

If you look carefully at the invoked -cc1 command-line, there's a flag -disable-free which is always passed:

$ clang-cl /c a.cpp -###
clang version 12.0.0 (https://github.com/llvm/llvm-project.git 0eab9d5823815c6520697f8d725c402c88e5d050)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: F:\llvm-project\__test\..\buildninjaRpMalloc2\bin
(in-process)
"F:\\llvm-project\\buildninjaRpMalloc2\\bin\\clang-cl.exe" "-cc1" "-triple" "x86_64-pc-windows-msvc19.28.29334" "-emit-obj" "-mrelax-all" "-mincremental-linker-compatible" "--mrelax-relocations" "-disable-free" "-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "a.cpp" "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=none" "-relaxed-aliasing" "-fmath-errno" "-fno-rounding-math" "-mconstructor-aliases" "-munwind-tables" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-D_MT" "-flto-visibility-public-std" "--dependent-lib=libcmt" "--dependent-lib=oldnames" "-stack-protector" "2" "-fms-volatile" "-fdiagnostics-format" "msvc" "-resource-dir" "F:\\llvm-project\\buildninjaRpMalloc2\\lib\\clang\\12.0.0" "-internal-isystem" "F:\\llvm-project\\buildninjaRpMalloc2\\lib\\clang\\12.0.0\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft<file://Microsoft> Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.28.29333\\ATLMFC\\include" "-internal-isystem" "C:\\Program Files (x86)\\Microsoft<file://Microsoft> Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.28.29333\\include" "-internal-isystem" "C:\\Program Files (x86)\\Windows<file://Windows> Kits\\NETFXSDK\\4.8\\include\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows<file://Windows> Kits\\10\\include\\10.0.18362.0\\ucrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows<file://Windows> Kits\\10\\include\\10.0.18362.0\\shared" "-internal-isystem" "C:\\Program Files (x86)\\Windows<file://Windows> Kits\\10\\include\\10.0.18362.0\\um" "-internal-isystem" "C:\\Program Files (x86)\\Windows<file://Windows> Kits\\10\\include\\10.0.18362.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)\\Windows<file://Windows> Kits\\10\\include\\10.0.18362.0\\cppwinrt" "-fdeprecated-macro" "-fdebug-compilation-dir" "F:\\llvm-project\\__test" "-ferror-limit" "19" "-fmessage-length=120" "-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.28.29334" "-std=c++14" "-fdelayed-template-parsing" "-fcolor-diagnostics" "-faddrsig" "-o" "a.obj" "-x" "c++" "a.cpp"

The purpose of the flag is to speed-up the process shutdown, by disabling heap deallocations on exit. It is used in conjunction with llvm::BuryPointer. Unless you call the -cc1 command directly or use libTooling, this flag is always active.

Alex.

De : llvm-dev <llvm-dev-bounces at lists.llvm.org<mailto:llvm-dev-bounces at lists.llvm.org>> De la part de Tomar, Sourabh Singh via llvm-dev
Envoyé : November 23, 2020 8:43 AM
À : llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>
Objet : [llvm-dev] Possible Memory leak while compiling.

When compiling a .ll file as:
$ valgrind clang main.ll

I noticed lot of memory leaks:

==18396== HEAP SUMMARY:
==18396==     in use at exit: 647,329 bytes in 619 blocks
==18396==   total heap usage: 6,754 allocs, 6,135 frees, 1,571,191 bytes allocated
==18396==
==18396== LEAK SUMMARY:
==18396==    definitely lost: 69,392 bytes in 4 blocks
==18396==    indirectly lost: 374,050 bytes in 595 blocks
==18396==      possibly lost: 12,207 bytes in 8 blocks
==18396==    still reachable: 191,680 bytes in 12 blocks
==18396==         suppressed: 0 bytes in 0 blocks

Is this okay ? or Known issue ?

Thanks,
Sourabh.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201209/3f467915/attachment.html>


More information about the llvm-dev mailing list