在LLVM中设置DebugLoc后,子程序错误不匹配

时间:2019-07-09 15:40:59

标签: c++ llvm

我试图在LLVM中设置某些指令的DebugLoc,在上一遍中已向它们添加了一些元数据。但是,在编译过程中出现错误。例如,在这里您可以看到LLVM输出的一部分:

mismatched subprogram between llvm.dbg.value variable and !dbg attachment
  call void @llvm.dbg.value(metadata i8 %361, metadata !42467, metadata !DIExpression()), !dbg !45649, !metadata_dependent !45650
label %for.body238.preheader.3
i32 (%struct.hmmfile_s*, %struct.plan7_s**)* @read_bin20hmm
!42467 = !DILocalVariable(name: "byte", scope: !42461, file: !179, line: 1316, type: !9)
!42461 = distinct !DISubprogram(name: "byteswap", scope: !179, file: !179, line: 1313, type: !42462, isLocal: true, isDefinition: true, scopeLine: 1314, flags: DIFlagPrototyped, isOptimized: true, unit: !178, retainedNodes: !42464)
!45649 = !DILocation(line: 201356, scope: !42421)
!42421 = distinct !DISubprogram(name: "read_bin20hmm", scope: !179, file: !179, line: 782, type: !42422, isLocal: true, isDefinition: true, scopeLine: 783, flags: DIFlagPrototyped, isOptimized: true, unit: !178, retainedNodes: !42424)

在这里您可以看到第一阶段的一部分,该阶段将一些元数据插入指令中:

int dependent_counter = 0;
for (auto it = total_dependent_insts.begin(), eit = total_dependent_insts.end(); it != eit; it++)
{
    LLVMContext& CC = (*it)->getContext();
    std::string MDS2 = "some_information#" + (*it)->getParent()->getParent()->getName().str() + "#" + std::to_string(dependent_counter);
    MDNode* NN = MDNode::get(CC, MDString::get(CC, MDS2));
    (*it)->setMetadata("metadata_information", NN);
    dependent_counter++;
}

在这里,您可以在第二遍中看到部分代码,这些代码设置了这些指令的DebugLoc,以便添加一些调试信息,然后在编译后收集它们:

for (auto it = inst->dependent_insts.begin(), eit = inst->dependent_insts.end(); eit != it; it++)
{
    if (MDNode* NN = (*it)->getMetadata("metadata_information"))
    {
        if ((*it)->getDebugLoc())
        {
            std::string MDStr = cast<MDString>(NN->getOperand(0))->getString();

            DebugLoc L = DebugLoc::get((unsigned)line, (unsigned)0, (*it)->getParent()->getParent()->getSubprogram());
            line++;

            (*it)->setDebugLoc(L);

            errs() << "Metadata String: " << MDStr << "\n";
        }
    }
}

我不知道为什么会这样。另外,对于另一组指令,我也在做同样的事情(插入元数据和调试信息)。

如果您能给我一个解决此问题的线索,我将不胜感激。

谢谢

0 个答案:

没有答案