Hi ISPC developers,
I am trying to link two bitcode files using llvm-link. Both the bitcode files are generated with debug flag enabled (-g option). The first bitcode file is generated using clang++ with a regular cpp file while the second bitcode file is generated using ispc --emit-llvm flag. Below are the sample commands.
$ clang++ foo_nonispc.cpp -emit-llvm -g -c -o foo_nonispc.bc
$ ispc ao.ispc -o ao_ispc.bc --emit-llvm -g
$ llvm-link foo_nonispc.bc ao_ispc.bc -o result.bc
When trying to run the third command, it fails with follow error message:
Error: llvm-link: link error in 'ao_ispc.bc': linking module flags 'Debug Info Version': IDs have conflicting behavior
Debugging it further I could narrow down the offended code in the LLVM source code (release_35 branch) located at: LLVM_SRC/lib/Linker/LinkModules.cpp: 1318 (code snippet mentioned below for easy reference)
// Diagnose inconsistent merge behavior types.
if (SrcBehaviorValue != DstBehaviorValue) {
MDString *DestID = cast<MDString>(DstOp->getOperand(1));
HasErr |= emitError("linking module flags '" + ID->getString() +
"': IDs have conflicting behaviors");
continue;
}
After further debugging, I noticed that there is a
mismatch in the value of the "behaviour" set for the
same "flag ID": Debug Info Version
ISPC sets the flag value as 2 (i.e. Warning) whereas LLVM set it as 1 (i.e. Error)..
Going through the LLVM doc (
http://llvm.org/docs/LangRef.html#module-flags-metadata), it seems that we can't define/set different behaviours for the same flag ID in two or more different modules. Below is the relevant excerpt:
"It is an error for a particular unique flag ID to have multiple behaviors,
except in the case of Require (which adds restrictions on another metadata
value) or Override." Therefore, I think we just require a minor fix in ISPC where the behaviour for "Debug Info Version" flag should be set to 1 instead of 2 to make it consistent with LLVM.
Your thoughts? Thanks for your help!
Vishal