<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:"Segoe UI";
panose-1:2 11 5 2 4 2 4 2 2 3;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
span.EmailStyle21
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hi Alexandre,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I tried removing `-disable-free` from CLANG default commandline, but VALGRIND still reports leaks(quantitatively same as with `-disable-free` passed):<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Summary:<o:p></o:p></p>
<p class="MsoNormal"><b>**with -disable-free**<o:p></o:p></b></p>
<p class="MsoNormal">==22725== Command: /home/trunk/build/release/bin/clang main.c -g<o:p></o:p></p>
<p class="MsoNormal">==22725==<o:p></o:p></p>
<p class="MsoNormal">==22725==<o:p></o:p></p>
<p class="MsoNormal">==22725== HEAP SUMMARY:<o:p></o:p></p>
<p class="MsoNormal">==22725== in use at exit: 251,896 bytes in 12 blocks<o:p></o:p></p>
<p class="MsoNormal">==22725== total heap usage: 3,754 allocs, 3,742 frees, 734,893 bytes allocated<o:p></o:p></p>
<p class="MsoNormal">==22725==<o:p></o:p></p>
<p class="MsoNormal">==22725== LEAK SUMMARY:<o:p></o:p></p>
<p class="MsoNormal">==22725== definitely lost: 67,584 bytes in 1 blocks<o:p></o:p></p>
<p class="MsoNormal">==22725== indirectly lost: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal">==22725== possibly lost: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal">==22725== still reachable: 184,312 bytes in 11 blocks<o:p></o:p></p>
<p class="MsoNormal">==22725== suppressed: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal">==22725== Rerun with --leak-check=full to see details of leaked memory
<o:p></o:p></p>
<p class="MsoNormal">==22725==<o:p></o:p></p>
<p class="MsoNormal">==22725== For counts of detected and suppressed errors, rerun with: -v
<o:p></o:p></p>
<p class="MsoNormal">==22725== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><b>**After removing -disable-free**<o:p></o:p></b></p>
<p class="MsoNormal">==22506== Command: /home/trunk/build/release/bin/clang main.c -g<o:p></o:p></p>
<p class="MsoNormal">==22506==<o:p></o:p></p>
<p class="MsoNormal">==22506==<o:p></o:p></p>
<p class="MsoNormal">==22506== HEAP SUMMARY:<o:p></o:p></p>
<p class="MsoNormal">==22506== in use at exit: 251,896 bytes in 12 blocks<o:p></o:p></p>
<p class="MsoNormal">==22506== total heap usage: 3,754 allocs, 3,742 frees, 734,869 bytes allocated<o:p></o:p></p>
<p class="MsoNormal">==22506==<o:p></o:p></p>
<p class="MsoNormal">==22506== LEAK SUMMARY:<o:p></o:p></p>
<p class="MsoNormal">==22506== definitely lost: 67,584 bytes in 1 blocks<o:p></o:p></p>
<p class="MsoNormal">==22506== indirectly lost: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal">==22506== possibly lost: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal">==22506== still reachable: 184,312 bytes in 11 blocks<o:p></o:p></p>
<p class="MsoNormal">==22506== suppressed: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal">==22506== Rerun with --leak-check=full to see details of leaked memory
<o:p></o:p></p>
<p class="MsoNormal">==22506==<o:p></o:p></p>
<p class="MsoNormal">==22506== For counts of detected and suppressed errors, rerun with: -v
<o:p></o:p></p>
<p class="MsoNormal">==22506== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Sourabh.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b>From:</b> Alexandre Ganea <alexandre.ganea@ubisoft.com> <br>
<b>Sent:</b> Monday, November 23, 2020 7:36 PM<br>
<b>To:</b> Tomar, Sourabh Singh <SourabhSingh.Tomar@amd.com><br>
<b>Cc:</b> llvm-dev <llvm-dev@lists.llvm.org>; cfe-dev@lists.llvm.org<br>
<b>Subject:</b> RE: Possible Memory leak while compiling.<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span lang="EN-CA">[CAUTION: External Email] <o:p></o:p></span></p>
<div>
<p class="MsoNormal"><span lang="FR-CA">Hello Tomar,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">If you look carefully at the invoked -cc1 command-line, there’s a flag
<span style="background:yellow;mso-highlight:yellow">-disable-free</span> which is always passed:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">$ clang-cl /c a.cpp -###<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="FR-CA">clang version 12.0.0 (<a href="https://github.com/llvm/llvm-project.git">https://github.com/llvm/llvm-project.git</a> 0eab9d5823815c6520697f8d725c402c88e5d050)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">Target: x86_64-pc-windows-msvc<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">Thread model: posix<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">InstalledDir: F:\llvm-project\__test\..\buildninjaRpMalloc2\bin<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">(in-process)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">"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"
<span style="background:yellow;mso-highlight:yellow">"-disable-free"</span> "-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)<a href="file://Microsoft">\\Microsoft</a>
Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.28.29333\\ATLMFC\\include" "-internal-isystem" "C:\\Program Files (x86)<a href="file://Microsoft">\\Microsoft</a> Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.28.29333\\include" "-internal-isystem"
"C:\\Program Files (x86)<a href="file://Windows">\\Windows</a> Kits\\NETFXSDK\\4.8\\include\\um" "-internal-isystem" "C:\\Program Files (x86)<a href="file://Windows">\\Windows</a> Kits\\10\\include\\10.0.18362.0\\ucrt" "-internal-isystem" "C:\\Program Files
(x86)<a href="file://Windows">\\Windows</a> Kits\\10\\include\\10.0.18362.0\\shared" "-internal-isystem" "C:\\Program Files (x86)<a href="file://Windows">\\Windows</a> Kits\\10\\include\\10.0.18362.0\\um" "-internal-isystem" "C:\\Program Files (x86)<a href="file://Windows">\\Windows</a>
Kits\\10\\include\\10.0.18362.0\\winrt" "-internal-isystem" "C:\\Program Files (x86)<a href="file://Windows">\\Windows</a> 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"<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">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</span><span lang="EN-CA" style="font-size:9.0pt;font-family:"Segoe UI",sans-serif;color:black">.
</span><span lang="EN-CA">Unless you call the -cc1 command directly or use libTooling, this flag is always active.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA">Alex.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span lang="FR">De :</span></b><span lang="FR"> llvm-dev <<a href="mailto:llvm-dev-bounces@lists.llvm.org">llvm-dev-bounces@lists.llvm.org</a>>
<b>De la part de</b> Tomar, Sourabh Singh via llvm-dev<br>
<b>Envoyé :</b> November 23, 2020 8:43 AM<br>
<b>À :</b> <a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<b>Objet :</b> [llvm-dev] Possible Memory leak while compiling.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><span lang="EN-CA"><o:p> </o:p></span></p>
<p class="MsoNormal">When compiling a .ll file as:<o:p></o:p></p>
<p class="MsoNormal">$ valgrind clang main.ll<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I noticed lot of memory leaks:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">==18396== HEAP SUMMARY:<o:p></o:p></p>
<p class="MsoNormal">==18396== in use at exit: 647,329 bytes in 619 blocks<o:p></o:p></p>
<p class="MsoNormal">==18396== total heap usage: 6,754 allocs, 6,135 frees, 1,571,191 bytes allocated<o:p></o:p></p>
<p class="MsoNormal">==18396==<o:p></o:p></p>
<p class="MsoNormal">==18396== LEAK SUMMARY:<o:p></o:p></p>
<p class="MsoNormal">==18396== definitely lost: 69,392 bytes in 4 blocks<o:p></o:p></p>
<p class="MsoNormal">==18396== indirectly lost: 374,050 bytes in 595 blocks<o:p></o:p></p>
<p class="MsoNormal">==18396== possibly lost: 12,207 bytes in 8 blocks<o:p></o:p></p>
<p class="MsoNormal">==18396== still reachable: 191,680 bytes in 12 blocks<o:p></o:p></p>
<p class="MsoNormal">==18396== suppressed: 0 bytes in 0 blocks<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Is this okay ? or Known issue ?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal">Sourabh.<o:p></o:p></p>
</div>
</div>
</body>
</html>