Browse Source

Fix memory leaks and improve build (#156)

* Remove clang header generation from the build

These headers aren't used by the compiler nor by HLSL program.

* Remove references to clang-headers and redundant discard test.

* Fix a few leaks to make tests pass with AppVerifier.
Marcelo Lopez Ruiz 8 years ago
parent
commit
f9401736a6

+ 2 - 0
include/dxc/HLSL/DxilContainer.h

@@ -375,6 +375,7 @@ inline uint32_t EncodeVersion(DXIL::ShaderKind shaderType, uint32_t major,
 
 class DxilPartWriter {
 public:
+  virtual ~DxilPartWriter() {}
   virtual uint32_t size() const = 0;
   virtual void write(AbstractMemoryStream *pStream) = 0;
 };
@@ -387,6 +388,7 @@ DxilPartWriter *NewPSVWriter(const DxilModule &M);
 class DxilContainerWriter : public DxilPartWriter  {
 public:
   typedef std::function<void(AbstractMemoryStream*)> WriteFn;
+  virtual ~DxilContainerWriter() {}
   virtual void AddPart(uint32_t FourCC, uint32_t Size, WriteFn Write) = 0;
 };
 

+ 1 - 1
lib/IR/DIBuilder.cpp

@@ -658,7 +658,7 @@ DISubprogram *DIBuilder::createFunction(DIScope *Context, StringRef Name,
       LinkageName, File, LineNo, Ty, isLocalToUnit, isDefinition, ScopeLine,
       nullptr, 0, 0, Flags, isOptimized, Fn, cast_or_null<MDTuple>(TParams),
       cast_or_null<DISubprogram>(Decl),
-      MDTuple::getTemporary(VMContext, None).release());
+      nullptr); // HLSL Change - this leaked, better nullptr than empty anyway - MDTuple::getTemporary(VMContext, None).release());
 
   if (isDefinition)
     AllSubprograms.push_back(Node);

+ 1 - 1
tools/clang/lib/CMakeLists.txt

@@ -1,4 +1,4 @@
-add_subdirectory(Headers)
+# add_subdirectory(Headers)
 add_subdirectory(Basic)
 add_subdirectory(Lex)
 add_subdirectory(Parse)

+ 1 - 1
tools/clang/tools/driver/CMakeLists.txt

@@ -58,7 +58,7 @@ if(CLANG_PLUGIN_SUPPORT)
   export_executable_symbols(clang)
 endif()
 
-add_dependencies(clang clang-headers)
+# add_dependencies(clang clang-headers) - HLSL Change
 
 if(UNIX)
   set(CLANGXX_LINK_OR_COPY create_symlink)

+ 0 - 1
tools/clang/tools/dxcompiler/CMakeLists.txt

@@ -83,7 +83,6 @@ set(GENERATED_HEADERS
 
 add_clang_library(dxcompiler SHARED ${SOURCES})
 target_link_libraries(dxcompiler PRIVATE ${LIBRARIES} ${DIASDK_LIBRARIES})
-add_dependencies(dxcompiler ${GENERATED_HEADERS} clang-headers)
 add_dependencies(dxcompiler DxcEtw)
 include_directories(AFTER ${LLVM_INCLUDE_DIR}/dxc/Tracing ${DIASDK_INCLUDE_DIRS})
 

+ 1 - 1
tools/clang/tools/libclang/CMakeLists.txt

@@ -100,7 +100,7 @@ if(1) # HLSL Change don't build the static target like this
 add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC}
   OUTPUT_NAME ${output_name}
   ${SOURCES}
-  DEPENDS clang-headers
+#  DEPENDS clang-headers - HLSL Change
 
   LINK_LIBS
   ${LIBS}

+ 0 - 1
tools/clang/unittests/HLSL/CMakeLists.txt

@@ -18,7 +18,6 @@ add_clang_library(clang-hlsl-tests SHARED
   AllocatorTest.cpp
   CompilationResult.h
   CompilerTest.cpp
-  DiscardStmt.cpp
   DxilContainerTest.cpp
   DXIsenseTest.cpp
   ExecutionTest.cpp

+ 0 - 28
tools/clang/unittests/HLSL/DiscardStmt.cpp

@@ -1,28 +0,0 @@
-///////////////////////////////////////////////////////////////////////////////
-//                                                                           //
-// DiscardStmt.cpp                                                           //
-// Copyright (C) Microsoft Corporation. All rights reserved.                 //
-// This file is distributed under the University of Illinois Open Source     //
-// License. See LICENSE.TXT for details.                                     //
-//                                                                           //
-//                                                                           //
-///////////////////////////////////////////////////////////////////////////////
-
-#include "CompilationResult.h"
-#include "HLSLTestData.h"
-
-#include "WexTestClass.h"
-#include "HlslTestUtils.h"
-
-class DiscardTestFixture {
-public:
-  BEGIN_TEST_CLASS(DiscardTestFixture)
-    TEST_METHOD_PROPERTY(L"Priority", L"0")
-  END_TEST_CLASS()
-  TEST_METHOD(TestBasic);
-};
-
-TEST_F(DiscardTestFixture, TestBasic) {
-  CompilationResult result(CompilationResult::CreateForProgram("void foo() { discard; }", 0));
-  EXPECT_EQ(true, result.ParseSucceeded());
-}

+ 1 - 1
tools/clang/unittests/HLSL/ValidationTest.cpp

@@ -465,7 +465,7 @@ public:
     const DxilContainerHeader *pHeader2 = IsDxilContainerLike(pProgram2->GetBufferPointer(), pProgram2->GetBufferSize());
     VERIFY_IS_NOT_NULL(pHeader2);
 
-    DxilContainerWriter *pContainerWriter = NewDxilContainerWriter();
+    unique_ptr<DxilContainerWriter> pContainerWriter(NewDxilContainerWriter());
 
     // Add desired parts from first container
     for (auto pPart : pHeader1) {

+ 17 - 0
tools/clang/unittests/HLSL/VerifierTest.cpp

@@ -13,6 +13,7 @@
 #include <string>
 #include "CompilationResult.h"
 #include "HLSLTestData.h"
+#include "llvm/Support/ManagedStatic.h"
 
 #include <fstream>
 
@@ -21,6 +22,9 @@
 
 using namespace std;
 
+MODULE_SETUP(TestModuleSetup);
+MODULE_CLEANUP(TestModuleCleanup);
+
 // The test fixture.
 class VerifierTest
 {
@@ -116,6 +120,19 @@ public:
   }
 };
 
+bool TestModuleSetup() {
+  // Use this module-level function to set up LLVM dependencies.
+  return true;
+}
+
+bool TestModuleCleanup() {
+  // Use this module-level function to set up LLVM dependencies.
+  // In particular, clean up managed static allocations used by
+  // parsing options with the LLVM library.
+  ::llvm::llvm_shutdown();
+  return true;
+}
+
 TEST_F(VerifierTest, RunAttributes) {
   CheckVerifiesHLSL(L"attributes.hlsl");
 }