Sanitize debug source location tracking for implicit branch and return
This patch tries to attach debug location of a branch/return instruction to its predecessor or the closing brace. If none could be found, no debug info should be emitted.
This commit is contained in:
parent
b1fac200c4
commit
a496a34b43
30 changed files with 4713 additions and 4253 deletions
|
|
@ -2182,6 +2182,10 @@ void Builder::addInstruction(std::unique_ptr<Instruction> inst) {
|
|||
buildPoint->addInstruction(std::move(inst));
|
||||
}
|
||||
|
||||
void Builder::addInstructionNoDebugInfo(std::unique_ptr<Instruction> inst) {
|
||||
buildPoint->addInstruction(std::move(inst));
|
||||
}
|
||||
|
||||
// Comments in header
|
||||
Function* Builder::makeEntryPoint(const char* entryPoint)
|
||||
{
|
||||
|
|
@ -3659,6 +3663,7 @@ Builder::If::If(Id cond, unsigned int ctrl, Builder& gb) :
|
|||
// Save the current block, so that we can add in the flow control split when
|
||||
// makeEndIf is called.
|
||||
headerBlock = builder.getBuildPoint();
|
||||
builder.createSelectionMerge(mergeBlock, control);
|
||||
|
||||
function->addBlock(thenBlock);
|
||||
builder.setBuildPoint(thenBlock);
|
||||
|
|
@ -3668,7 +3673,7 @@ Builder::If::If(Id cond, unsigned int ctrl, Builder& gb) :
|
|||
void Builder::If::makeBeginElse()
|
||||
{
|
||||
// Close out the "then" by having it jump to the mergeBlock
|
||||
builder.createBranch(mergeBlock);
|
||||
builder.createBranch(true, mergeBlock);
|
||||
|
||||
// Make the first else block and add it to the function
|
||||
elseBlock = new Block(builder.getUniqueId(), *function);
|
||||
|
|
@ -3682,11 +3687,10 @@ void Builder::If::makeBeginElse()
|
|||
void Builder::If::makeEndIf()
|
||||
{
|
||||
// jump to the merge block
|
||||
builder.createBranch(mergeBlock);
|
||||
builder.createBranch(true, mergeBlock);
|
||||
|
||||
// Go back to the headerBlock and make the flow control split
|
||||
builder.setBuildPoint(headerBlock);
|
||||
builder.createSelectionMerge(mergeBlock, control);
|
||||
if (elseBlock)
|
||||
builder.createConditionalBranch(condition, thenBlock, elseBlock);
|
||||
else
|
||||
|
|
@ -3732,10 +3736,10 @@ void Builder::makeSwitch(Id selector, unsigned int control, int numSegments, con
|
|||
}
|
||||
|
||||
// Comments in header
|
||||
void Builder::addSwitchBreak()
|
||||
void Builder::addSwitchBreak(bool implicit)
|
||||
{
|
||||
// branch to the top of the merge block stack
|
||||
createBranch(switchMerges.top());
|
||||
createBranch(implicit, switchMerges.top());
|
||||
createAndSetNoPredecessorBlock("post-switch-break");
|
||||
}
|
||||
|
||||
|
|
@ -3746,7 +3750,7 @@ void Builder::nextSwitchSegment(std::vector<Block*>& segmentBlock, int nextSegme
|
|||
if (lastSegment >= 0) {
|
||||
// Close out previous segment by jumping, if necessary, to next segment
|
||||
if (! buildPoint->isTerminated())
|
||||
createBranch(segmentBlock[nextSegment]);
|
||||
createBranch(true, segmentBlock[nextSegment]);
|
||||
}
|
||||
Block* block = segmentBlock[nextSegment];
|
||||
block->getParent().addBlock(block);
|
||||
|
|
@ -3758,7 +3762,7 @@ void Builder::endSwitch(std::vector<Block*>& /*segmentBlock*/)
|
|||
{
|
||||
// Close out previous segment by jumping, if necessary, to next segment
|
||||
if (! buildPoint->isTerminated())
|
||||
addSwitchBreak();
|
||||
addSwitchBreak(true);
|
||||
|
||||
switchMerges.top()->getParent().addBlock(switchMerges.top());
|
||||
setBuildPoint(switchMerges.top());
|
||||
|
|
@ -3791,14 +3795,14 @@ Builder::LoopBlocks& Builder::makeNewLoop()
|
|||
|
||||
void Builder::createLoopContinue()
|
||||
{
|
||||
createBranch(&loops.top().continue_target);
|
||||
createBranch(false, &loops.top().continue_target);
|
||||
// Set up a block for dead code.
|
||||
createAndSetNoPredecessorBlock("post-loop-continue");
|
||||
}
|
||||
|
||||
void Builder::createLoopExit()
|
||||
{
|
||||
createBranch(&loops.top().merge);
|
||||
createBranch(false, &loops.top().merge);
|
||||
// Set up a block for dead code.
|
||||
createAndSetNoPredecessorBlock("post-loop-break");
|
||||
}
|
||||
|
|
@ -4240,11 +4244,16 @@ void Builder::createAndSetNoPredecessorBlock(const char* /*name*/)
|
|||
}
|
||||
|
||||
// Comments in header
|
||||
void Builder::createBranch(Block* block)
|
||||
void Builder::createBranch(bool implicit, Block* block)
|
||||
{
|
||||
Instruction* branch = new Instruction(OpBranch);
|
||||
branch->addIdOperand(block->getId());
|
||||
addInstruction(std::unique_ptr<Instruction>(branch));
|
||||
if (implicit) {
|
||||
addInstructionNoDebugInfo(std::unique_ptr<Instruction>(branch));
|
||||
}
|
||||
else {
|
||||
addInstruction(std::unique_ptr<Instruction>(branch));
|
||||
}
|
||||
block->addPredecessor(buildPoint);
|
||||
}
|
||||
|
||||
|
|
@ -4277,7 +4286,10 @@ void Builder::createConditionalBranch(Id condition, Block* thenBlock, Block* els
|
|||
branch->addIdOperand(condition);
|
||||
branch->addIdOperand(thenBlock->getId());
|
||||
branch->addIdOperand(elseBlock->getId());
|
||||
addInstruction(std::unique_ptr<Instruction>(branch));
|
||||
|
||||
// A conditional branch is always attached to a condition expression
|
||||
addInstructionNoDebugInfo(std::unique_ptr<Instruction>(branch));
|
||||
|
||||
thenBlock->addPredecessor(buildPoint);
|
||||
elseBlock->addPredecessor(buildPoint);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue