Hey.
I created a post-isel-hook, that create a new MachineBasicBlock and push it after an instruction.
Here is a snippet from the function (only relevant code):
void MyTargetLowering::AdjustInstrPostInstrSelection(...) {
// Create a new label
MachineBasicBlock *NewLabel = MF.CreateMachineBasicBlock();
// Add it to the machine function - after the call instruction
MF.insert(std::next(MBBI), NewLabel);
// Build the new instruction
MachineInstrBuilder newInst = BuildMI(...);
// Set the label as the operand for the instruction
newInst.addMBB(NewLabel);
newInst->setPostInstrSymbol(MF, NewLabel->getSymbol());
}
Now, I encountered a problem when I try to compile the following code:
extern char getc();
int main() {
char c;
while (c = getc()) {
switch (c) {
case 'a':
break;
case 'b':
break;
}
}
return 0;
}
When trying to run llc
on the generated LLVM code, I got the error:
<unknown>:0: error: symbol 'LBB0_7' is already defined
When I tried to debug the code, I saw that there is a function MachineFunction::RenumberBlocks
that handles the MBB numbers.
I also noticed that when I call NewLabel->getSymbol
it uses its current Number attribute (which gets override by the renumber function), and so the post-instr-symbol seems to be incorrect.
Can someone please explain to me what am I doing wrong?
[Notice: I'm using LLVM v15]
If it's a known bug I would love to know about it.