From 7feaed312af4ee9630394ed2c01d4316dd4591b0 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 7 Aug 2023 09:59:11 -0700 Subject: [PATCH] Fix bug in the VFS construction. (#3067) The constructor accepts a `bool` which we were setting to `true` by converting from a heap allocated, and thus non-null, pointer. But that heap allocation was dead and leaked, somewhat obviously. Leak checking is disabled on our CI at the moment, but this was failing for me locally with our default build on Linux where it uses ASan. The `true` value also had no effect because the default argument to the bool parameter is itself, `true`. :sigh: It's really sad that this compiled. But it's the same thing as using a non-null pointer in an `if`. There doesn't seem to be any `clang-tidy` check for a `new` expression that is implicitly converted to a `bool` type either. I've filled https://github.com/llvm/llvm-project/issues/64461 requesting a check or warning to catch this in the future. --- explorer/file_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/explorer/file_test.cpp b/explorer/file_test.cpp index 19d83239dbe2..16be4245c17f 100644 --- a/explorer/file_test.cpp +++ b/explorer/file_test.cpp @@ -31,7 +31,7 @@ class ExplorerFileTest : public FileTestBase { llvm::raw_pwrite_stream& stdout, llvm::raw_pwrite_stream& stderr) -> ErrorOr override { // Create the files in-memory. - llvm::vfs::InMemoryFileSystem fs(new llvm::vfs::InMemoryFileSystem()); + llvm::vfs::InMemoryFileSystem fs; for (const auto& test_file : test_files) { if (!fs.addFile(test_file.filename, /*ModificationTime=*/0, llvm::MemoryBuffer::getMemBuffer(test_file.content))) {