Browse Source

Fixed entry point string being empty when the commandline didn't specify /E (#3477)

Adam Yang 4 years ago
parent
commit
0d0d6e4b86

+ 5 - 0
tools/clang/tools/dxcompiler/dxcpdbutils.cpp

@@ -513,6 +513,11 @@ private:
           m_ArgPairs.push_back( std::move(newPair) );
           m_ArgPairs.push_back( std::move(newPair) );
         }
         }
 
 
+        // Entry point might have been omitted. Set it to main by default.
+        if (m_EntryPoint.empty()) {
+          m_EntryPoint = L"main";
+        }
+
         // Sources
         // Sources
         for (unsigned i = 0; i < reader.GetSourcesCount(); i++) {
         for (unsigned i = 0; i < reader.GetSourcesCount(); i++) {
           hlsl::SourceInfoReader::Source source_data = reader.GetSource(i);
           hlsl::SourceInfoReader::Source source_data = reader.GetSource(i);

+ 44 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -129,6 +129,7 @@ public:
   TEST_METHOD(CompileThenAddCustomDebugName)
   TEST_METHOD(CompileThenAddCustomDebugName)
   TEST_METHOD(CompileThenTestPdbUtils)
   TEST_METHOD(CompileThenTestPdbUtils)
   TEST_METHOD(CompileThenTestPdbUtilsStripped)
   TEST_METHOD(CompileThenTestPdbUtilsStripped)
+  TEST_METHOD(CompileThenTestPdbUtilsEmptyEntry)
   TEST_METHOD(CompileWithRootSignatureThenStripRootSignature)
   TEST_METHOD(CompileWithRootSignatureThenStripRootSignature)
 
 
   TEST_METHOD(CompileWhenIncludeThenLoadInvoked)
   TEST_METHOD(CompileWhenIncludeThenLoadInvoked)
@@ -1534,6 +1535,49 @@ TEST_F(CompilerTest, CompileThenTestPdbUtils) {
   TestPdbUtils(/*bSlim*/false, /*bSourceInDebugModule*/false, /*strip*/true);  // Full PDB, where source info is stored in its own part, and debug module is present
   TestPdbUtils(/*bSlim*/false, /*bSourceInDebugModule*/false, /*strip*/true);  // Full PDB, where source info is stored in its own part, and debug module is present
   TestPdbUtils(/*bSlim*/true,  /*bSourceInDebugModule*/false, /*strip*/true);  // Slim PDB, where source info is stored in its own part, and debug module is NOT present
   TestPdbUtils(/*bSlim*/true,  /*bSourceInDebugModule*/false, /*strip*/true);  // Slim PDB, where source info is stored in its own part, and debug module is NOT present
 }
 }
+
+TEST_F(CompilerTest, CompileThenTestPdbUtilsEmptyEntry) {
+  std::string main_source = R"x(
+      cbuffer MyCbuffer : register(b1) {
+        float4 my_cbuf_foo;
+      }
+
+      [RootSignature("CBV(b1)")]
+      float4 main() : SV_Target {
+        return my_cbuf_foo;
+      }
+  )x";
+
+  CComPtr<IDxcCompiler3> pCompiler;
+  VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcCompiler, &pCompiler));
+
+  DxcBuffer SourceBuf = {};
+  SourceBuf.Ptr = main_source.c_str();
+  SourceBuf.Size = main_source.size();
+  SourceBuf.Encoding = CP_UTF8;
+
+  std::vector<const WCHAR *> args;
+  args.push_back(L"/Tps_6_0");
+  args.push_back(L"/Zi");
+
+  CComPtr<IDxcResult> pResult;
+  VERIFY_SUCCEEDED(pCompiler->Compile(&SourceBuf, args.data(), args.size(), nullptr, IID_PPV_ARGS(&pResult)));
+
+  CComPtr<IDxcBlob> pPdb;
+  CComPtr<IDxcBlobUtf16> pPdbName;
+  VERIFY_SUCCEEDED(pResult->GetOutput(DXC_OUT_PDB, IID_PPV_ARGS(&pPdb), &pPdbName));
+
+  CComPtr<IDxcPdbUtils> pPdbUtils;
+  VERIFY_SUCCEEDED(m_dllSupport.CreateInstance(CLSID_DxcPdbUtils, &pPdbUtils));
+
+  VERIFY_SUCCEEDED(pPdbUtils->Load(pPdb));
+
+  CComBSTR pEntryName;
+  VERIFY_SUCCEEDED(pPdbUtils->GetEntryPoint(&pEntryName));
+
+  VERIFY_ARE_EQUAL(pEntryName, L"main");
+}
+
 #endif
 #endif
 
 
 TEST_F(CompilerTest, CompileWithRootSignatureThenStripRootSignature) {
 TEST_F(CompilerTest, CompileWithRootSignatureThenStripRootSignature) {