[llvm-dev] CloneFunctionInto produces invalid debug info

Matthias Bernad via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 15 08:31:52 PDT 2017


Hi!

We are currently working on a science project and implemented a
FunctionPass that clones a function (more precisely a constructor of a
struct/class) and adds a parameter.

First, we create a new function with a new function type, which includes
the newly added parameter:

Function *NF = Function::Create(NewFTy, F.getLinkage(), F.getName() +
"Cloned", F.getParent());


and after setting up the ValueToValueMapTy, we use the CloneFunctionInto
method to clone the function body

CloneFunctionInto(NF, &F, Map, true, Returns, "Cloned");


The code seems to work as intended, but when we try to emit debug symbols
(clang -g flag) the pass fails with following message:

"All DICompileUnits must be listed in llvm.dbg.cu"


Nevertheless, we can dump the Module and therefore can print out the
annotated IR.

This is what the function to be cloned looks like:

; Function Attrs: noinline nounwind uwtable
define linkonce_odr void @_ZN12MyFunnyClassC2Ev(%struct.MyFunnyClass*
%this) unnamed_addr #4 comdat align 2 !dbg !46 {
entry:
  %this.addr = alloca %struct.MyFunnyClass*, align 8
  store %struct.MyFunnyClass* %this, %struct.MyFunnyClass** %this.addr,
align 8
  call void @llvm.dbg.declare(metadata %struct.MyFunnyClass** %this.addr,
metadata !49, metadata !31), !dbg !50

... rest of function code

}

!46 = distinct !DISubprogram(name: "MyFunnyClass", linkageName:
"_ZN12MyFunnyClassC2Ev", scope: !15, file: !1, line: 1, type: !25, isLocal:
false, isDefinition: true, scopeLine: 1, flags: DIFlagArtificial |
DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !47,
variables: !2)


and the cloned function:

; Function Attrs: noinline nounwind uwtable
define linkonce_odr void @_ZN12MyFunnyClassC2EvCloned(%struct.MyFunnyClass*
%this, { [6 x i8*] }* %newparam) unnamed_addr #4 align 2 !dbg !73 {
entry:
  %this.addr = alloca %struct.MyFunnyClass*, align 8
  store %struct.MyFunnyClass* %this, %struct.MyFunnyClass** %this.addr,
align 8
  call void @llvm.dbg.declare(metadata %struct.MyFunnyClass** %this.addr,
metadata !89, metadata !31), !dbg !91

... rest of function code

}

!73 = distinct !DISubprogram(name: "MyFunnyClass", linkageName:
"_ZN12MyFunnyClassC2Ev", scope: !74, file: !1, line: 1, type: !81, isLocal:
false, isDefinition: true, scopeLine: 1, flags: DIFlagArtificial |
DIFlagPrototyped, isOptimized: false, unit: !87, declaration: !88,
variables: !2)

So the cloned function gets annotated with debug symbols as expected. We
noticed that the linkageName of the cloned function is the same as the
original one's. Could that cause the error mentioned above? If so, how can
we fix that error?

Best regards and thanks in advance,
Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170615/a724dc14/attachment.html>


More information about the llvm-dev mailing list