فهرست منبع

Giving instructions from global variable initialization function "inlinedAt" property. (#2055)

Adam Yang 6 سال پیش
والد
کامیت
3811872f2f
2فایلهای تغییر یافته به همراه29 افزوده شده و 0 حذف شده
  1. 15 0
      lib/Transforms/Utils/InlineFunction.cpp
  2. 14 0
      tools/clang/test/CodeGenHLSL/debug/static_init_inline.hlsl

+ 15 - 0
lib/Transforms/Utils/InlineFunction.cpp

@@ -873,8 +873,23 @@ updateInlinedAtInfo(DebugLoc DL, DILocation *InlinedAtNode, LLVMContext &Ctx,
 static void fixupLineNumbers(Function *Fn, Function::iterator FI,
 static void fixupLineNumbers(Function *Fn, Function::iterator FI,
                              Instruction *TheCall) {
                              Instruction *TheCall) {
   DebugLoc TheCallDL = TheCall->getDebugLoc();
   DebugLoc TheCallDL = TheCall->getDebugLoc();
+#if 0 // HLSL Change
   if (!TheCallDL)
   if (!TheCallDL)
     return;
     return;
+#else // HLSL Change - Begin
+  // Global variable initialization code gets inlined but the call inst doesn't
+  // get a location. Fix it here by giving it a dummy location so the debug
+  // info is well-formed.
+  if (!TheCallDL) {
+    if (DISubprogram *Subprogram = getDISubprogram(Fn)) {
+      TheCallDL = DebugLoc(llvm::DILocation::get(Fn->getContext(), 0, 0, Subprogram));
+      TheCall->setDebugLoc(TheCallDL);
+    }
+    else {
+      return;
+    }
+  }
+#endif // HLSL Change - End
 
 
   auto &Ctx = Fn->getContext();
   auto &Ctx = Fn->getContext();
   DILocation *InlinedAtNode = TheCallDL;
   DILocation *InlinedAtNode = TheCallDL;

+ 14 - 0
tools/clang/test/CodeGenHLSL/debug/static_init_inline.hlsl

@@ -0,0 +1,14 @@
+// RUN: %dxc -E main -T ps_6_0 %s -Zi -Od | FileCheck %s
+
+// Make sure when there is non-trivial global variable initialization, the
+// inlined initialization instructions have "inlinedAt" property
+
+// CHECK: !{{[0-9]+}} = !DILocation(line: {{[0-9]+}}, column: {{[0-9]+}}, scope: !{{[0-9]+}}, inlinedAt:
+
+static float4 my_value = float4(1,2,3,4);
+static float4 my_value2 = my_value*2;
+
+[RootSignature("")]
+float4 main() : SV_Target {
+  return my_value2;
+}