瀏覽代碼

use path::native on filenames for dx.source.contents (#2902)

Xiang Li 5 年之前
父節點
當前提交
aca6034a89

+ 7 - 3
tools/clang/lib/CodeGen/ModuleBuilder.cpp

@@ -26,6 +26,7 @@
 #include "llvm/IR/Module.h"
 #include <memory>
 #include "dxc/DXIL/DxilMetadataHelper.h" // HLSL Change - dx source info
+#include "llvm/Support/Path.h"
 using namespace clang;
 
 namespace {
@@ -228,7 +229,7 @@ namespace {
               llvm::MDString::get(LLVMCtx, content) });
           pContents->addOperand(pFileInfo);
         };
-        std::map<StringRef, StringRef> filesMap;
+        std::map<std::string, StringRef> filesMap;
         bool bFoundMainFile = false;
         for (SourceManager::fileinfo_iterator
                  it = Ctx.getSourceManager().fileinfo_begin(),
@@ -237,12 +238,15 @@ namespace {
           if (it->first->isValid() && !it->second->IsSystemFile) {
             // If main file, write that to metadata first.
             // Add the rest to filesMap to sort by name.
+            llvm::SmallString<128> NormalizedPath;
+            llvm::sys::path::native(it->first->getName(), NormalizedPath);
             if (CodeGenOpts.MainFileName.compare(it->first->getName()) == 0) {
               assert(!bFoundMainFile && "otherwise, more than one file matches main filename");
-              AddFile(it->first->getName(), it->second->getRawBuffer()->getBuffer());
+              AddFile(NormalizedPath, it->second->getRawBuffer()->getBuffer());
               bFoundMainFile = true;
             } else {
-              filesMap[it->first->getName()] = it->second->getRawBuffer()->getBuffer();
+              filesMap[NormalizedPath.str()] =
+                  it->second->getRawBuffer()->getBuffer();
             }
           }
         }

+ 12 - 0
tools/clang/test/HLSLFileCheck/dxil/debug/inc_dir/inc_dir.h

@@ -0,0 +1,12 @@
+
+
+
+#ifndef AA
+float foo(float a) {
+  return sin(a);
+}
+#else
+float bar(float b) {
+  return cos(b);
+}
+#endif

+ 12 - 0
tools/clang/test/HLSLFileCheck/dxil/debug/inc_dir/inc_dir2.h

@@ -0,0 +1,12 @@
+
+//#include "..\inc_dir\inc_dir.h"
+
+
+#define AA
+
+#include "inc_dir.h"
+
+
+float bar2(float a) {
+  return bar(a);
+}

+ 11 - 0
tools/clang/test/HLSLFileCheck/dxil/debug/inc_test.hlsl

@@ -0,0 +1,11 @@
+// RUN: %dxc -E main -T ps_6_0 -Zi %s | FileCheck %s
+
+// Make sure has 3 files in dx.source.contents instead of 4 which mix use / and \\ for same header.
+//CHECK:!dx.source.contents = !{!{{[0-9]+}}, !{{[0-9]+}}, !{{[0-9]+}}}
+
+#include "inc_dir\inc_dir.h"
+#include "inc_dir/inc_dir2.h"
+
+float main(float a:A) : SV_Target {
+  return foo(a) + bar2(a);
+}