解析 Rust 生成的 LLVM-IR 时字段无效 'subprograms'

Invalid field 'subprograms' while parsing LLVM-IR generated by Rust

我在解析从 Rust 生成的 LLVM-IR 时得到 "invalid field 'subprograms'"。它立即发生在 !0

用于解析的代码:

MemoryBuffer* buf = MemoryBuffer::getMemBuffer(StringRef(fC)).release();
SMDiagnostic err;
LLVMContext *Context=new LLVMContext();
Module* module = parseIR(buf->getMemBufferRef(), err, *Context).release();
if(!module){
    NSString* errorMsg=[NSString stringWithFormat:@"%@ at line:%@ col:%@\n>>%@",[NSString stringWithCString:err.getMessage().str().c_str() encoding:NSUTF8StringEncoding], @(err.getLineNo()), @(err.getColumnNo()), [NSString stringWithCString:err.getLineContents().str().c_str() encoding:NSUTF8StringEncoding]];
    NSError* error=[[NSError alloc] initWithDomain:errorMsg code:-1 userInfo:nil];
    //Deal with NSError later
}
DebugInfoFinder* dif = new DebugInfoFinder();
dif->processModule(*module);

发生地点:

!0 = distinct !DICompileUnit(language: 36864, file: !1, producer: "rustc version 1.7.0 (a5d1e7a59 2016-02-29)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !10, subprograms: !29)

正如预期的那样,引用只是对子程序的引用数组:

!29 = !{!30, !47, !55, !65, !77, !83, !92, !99, !113, !114}
!30 = !DISubprogram(name: "main", linkageName: "_ZN8fizzbuzz4mainE", scope: !32, file: !31, line: 3, type: !33, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, function: void ()* @_ZN4main20hbe8861d85740ed2deaaE, templateParams: !35, variables: !36)

我觉得IR码没问题;这可能是 Rust 使用的 LLVM 版本与 llvm-ir 解析片段使用的版本之间的问题吗?

最近对调试元数据格式进行了重大更改。

有关详细信息,请参阅 http://llvm.org/PR27284