[llvm-dev] MSVC CRT Leak Checker Crashing with my unit tests

Pierre van Houtryve via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 27 06:12:28 PDT 2019


Hello!

This is my first time posting to the mailing list. I hope I am doing this
correctly. If it isn't the right place for this kind of message, please let
me know!

I'm developing a small compiler (https://github.com/Pierre-vh/Sora) that
uses LLVM. I am working on Windows using Visual Studio. For my previous
projects, I've always used Visual Studio's CRT leak-checker to identify
memory leaks, and it has always worked well until now: It doesn't seem to
play well with LLVM.

My current environment uses a version of LLVM that I built on my machine
and installed using cmake as per the instructions (
https://llvm.org/docs/CMake.html
<https://llvm.org/docs/CMake.html#embedding-llvm-in-your-project>).

It works well, I can build my project's main executable just fine, but
there's one issue. It doesn't seem to give me access to the llvm/utils
folder, so I have to use my own version of gtest (I can't use the one in
llvm/utils/unittests/googletest) and build the unit-test executable myself
(no add_unittest unfortunately)

At first I didn't think that was that big of a problem, I cloned gtest and
created a main.cpp for my unit-test executable (
https://github.com/Pierre-vh/Sora/blob/master/unittests/src/main.cpp) but I
quickly noticed some memory leaks reported by the CRT leak-checker. It
turned out that I forgot to use llvm::InitLLVM.

When I added the "llvm::InitLLVM llvmInit(argc, argv)" line at the top of
my main.cpp, I noticed that the unit-test executable triggered a breakpoint
upon exiting. The CRT seem to crash when dumping memory leaks for some
reason.

I didn't find an obvious solution to this. Is this something I can fix
myself?

If not, maybe I can fix this by using LLVM directly from the build folder
(to gain access to llvm/utils/unittests/googletest & the add_unittest
macro), or by using another, better Windows memory-leak checker? Can
someone guide me in the right direction then?

Also, as a beginner, I'll gladly take any piece of advice you may have for
me.

Thank you very much.

Kind Regards,
Pierre van Houtryve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190827/bbf686a0/attachment.html>


More information about the llvm-dev mailing list