Browse Source

Add debug info for constant in cbuffer. (#3037)

Xiang Li 5 years ago
parent
commit
8fa5563c62

+ 5 - 1
lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp

@@ -1861,7 +1861,11 @@ bool SROAGlobalAndAllocas(HLModule &HLM, bool bHasDbgInfo) {
           WorkList.push(*iter);
           GlobalVariable *EltGV = cast<GlobalVariable>(*iter);
           if (bHasDbgInfo) {
-            StringRef EltName = (*iter)->getName().ltrim(dbgOffset.base->getName());
+            StringRef OriginEltName = EltGV->getName();
+            StringRef OriginName = dbgOffset.base->getName();
+            StringRef EltName = OriginEltName.substr(OriginName.size());
+            StringRef EltParentName = OriginEltName.substr(0, OriginName.size());
+            DXASSERT_LOCALVAR(EltParentName, EltParentName == OriginName, "parent name mismatch");
             EltNameMap[EltGV] = EltName;
           }
           GVDbgOffset &EltDbgOffset = GVDbgOffsetMap[EltGV];

+ 6 - 0
tools/clang/lib/CodeGen/CGHLSLMS.cpp

@@ -3102,6 +3102,12 @@ void CGMSHLSLRuntime::AddConstant(VarDecl *constDecl, HLCBuffer &CB) {
     return;
   }
   llvm::Constant *constVal = CGM.GetAddrOfGlobalVar(constDecl);
+  // Add debug info for constVal.
+  if (CGDebugInfo *DI = CGM.getModuleDebugInfo())
+    if (CGM.getCodeGenOpts().getDebugInfo() >= CodeGenOptions::LimitedDebugInfo) {
+      DI->EmitGlobalVariable(cast<GlobalVariable>(constVal), constDecl);
+    }
+
   auto &regBindings = constantRegBindingMap[constVal];
   // Save resource properties for cbuffer variables.
   DxilResourceProperties RP = BuildResourceProperty(constDecl->getType());

+ 24 - 0
tools/clang/test/HLSLFileCheck/hlsl/objects/CbufferLegacy/write_const_debug_info.hlsl

@@ -0,0 +1,24 @@
+// RUN: %dxc -E main -T ps_6_0 -Gec -Zi %s | FileCheck %s
+
+// Make sure debug info for s.
+
+// CHECK:!DIGlobalVariable(name: "s.0"
+// Exclude quoted source file (see readme)
+// CHECK-LABEL: {{!"[^"]*\\0A[^"]*"}}
+
+
+struct S {
+  float a;
+};
+
+cbuffer A {
+  S s;
+};
+
+
+
+float main() : SV_Target {
+
+  s.a++;
+  return s.a;
+}