Leonardo Marques
Leonardo Marques

Reputation: 3951

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

I'm getting "invalid field 'subprograms'" when parsing LLVM-IR generated from Rust. It happens immediately at !0.

Code used to parse:

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);

Where it happens:

!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)

The reference is just an array of references to subprograms as expected:

!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)

I think the IR code looks OK; could this be an issue with the LLVM version used by Rust vs. the one used by the llvm-ir parsing snippet?

Upvotes: 1

Views: 485

Answers (1)

Anton Korobeynikov
Anton Korobeynikov

Reputation: 9324

There were breaking changes in debug metadata format recently.

See http://llvm.org/PR27284 for more information

Upvotes: 2

Related Questions