[PATCH 43/79] [DebugInfo] Fix translation of Target Function operand (#1982)
authorViktoria Maximova <viktoria.maksimova@intel.com>
Thu, 27 Apr 2023 18:36:13 +0000 (11:36 -0700)
committerAndreas Beckmann <anbe@debian.org>
Thu, 8 Feb 2024 21:48:18 +0000 (22:48 +0100)
Before reading Target function name operand of `DebugFunction` we need
to make sure it's the translation of appropriate debug extension.
Otherwise, we can get in a situation, where we do have 11 operands, but
the last one is not a `String` with name, but the `DebugFunctionDeclaration`.

Gbp-Pq: Name 0043-DebugInfo-Fix-translation-of-Target-Function-operand.patch

lib/SPIRV/SPIRVToLLVMDbgTran.cpp
lib/SPIRV/libSPIRV/SPIRV.debug.h

index 037cb1aba03a23b2f0b15096508965ef7590b32b..46e0daf1565d6a43100e3fca407c0899276e1455 100644 (file)
@@ -745,7 +745,9 @@ DINode *SPIRVToLLVMDbgTran::transFunction(const SPIRVExtInst *DebugInst,
                                           bool IsMainSubprogram) {
   using namespace SPIRVDebug::Operand::Function;
   const SPIRVWordVec &Ops = DebugInst->getArguments();
-  assert(Ops.size() >= MinOperandCount && "Invalid number of operands");
+  assert(Ops.size() >= MinOperandCountNonSem && "Invalid number of operands");
+  if (!isNonSemanticDebugInfo(DebugInst->getExtSetKind()))
+    assert(Ops.size() >= MinOperandCount && "Invalid number of operands");
 
   StringRef Name = getString(Ops[NameIdx]);
   DISubroutineType *Ty =
@@ -781,7 +783,8 @@ DINode *SPIRVToLLVMDbgTran::transFunction(const SPIRVExtInst *DebugInst,
   bool IsLocal = SPIRVDebugFlags & SPIRVDebug::FlagIsLocal;
   bool IsMainSubprogramFlag =
       IsMainSubprogram ||
-      BM->isEntryPoint(spv::ExecutionModelKernel, Ops[FunctionIdIdx]);
+      (!isNonSemanticDebugInfo(DebugInst->getExtSetKind()) &&
+       BM->isEntryPoint(spv::ExecutionModelKernel, Ops[FunctionIdIdx]));
 
   DISubprogram::DISPFlags SPFlags = DISubprogram::toSPFlags(
       IsLocal, IsDefinition, IsOptimized, DISubprogram::SPFlagNonvirtual,
@@ -820,8 +823,10 @@ DINode *SPIRVToLLVMDbgTran::transFunction(const SPIRVExtInst *DebugInst,
   else {
     // Create targetFuncName mostly for Fortran trampoline function if it is
     // the case
-    StringRef TargetFunction;
-    if (Ops.size() > MinOperandCount) {
+    StringRef TargetFunction = "";
+    if (DebugInst->getExtSetKind() ==
+            SPIRVEIS_NonSemantic_Shader_DebugInfo_200 &&
+        Ops.size() > TargetFunctionNameIdx) {
       TargetFunction = getString(Ops[TargetFunctionNameIdx]);
     }
     DIS = getDIBuilder(DebugInst).createFunction(
index dd08563b60913c3de611cf0627e4401d58e4f551..cd181faa1842fb580166be2dda03260e9f5de675 100644 (file)
@@ -543,21 +543,25 @@ enum {
 
 namespace Function {
 enum {
-  NameIdx         = 0,
-  TypeIdx         = 1,
-  SourceIdx       = 2,
-  LineIdx         = 3,
-  ColumnIdx       = 4,
-  ParentIdx       = 5,
-  LinkageNameIdx  = 6,
-  FlagsIdx        = 7,
-  ScopeLineIdx    = 8,
-  FunctionIdIdx   = 9,
-  DeclarationNonSemIdx = 9,
-  DeclarationIdx  = 10,
+  NameIdx               = 0,
+  TypeIdx               = 1,
+  SourceIdx             = 2,
+  LineIdx               = 3,
+  ColumnIdx             = 4,
+  ParentIdx             = 5,
+  LinkageNameIdx        = 6,
+  FlagsIdx              = 7,
+  ScopeLineIdx          = 8,
+  FunctionIdIdx         = 9,
+  DeclarationIdx        = 10,
+  MinOperandCount       = 10,
+
+// Only for NonSemantic.Shader.DebugInfo.*
+// No operand FunctionId
+  DeclarationNonSemIdx  = 9,
+  MinOperandCountNonSem = 9,
   // Only for NonSemantic.Shader.DebugInfo.200
-  TargetFunctionNameIdx  = 10,
-  MinOperandCount = 10
+  TargetFunctionNameIdx = 10,
 };
 }