Skip to content
Snippets Groups Projects
Commit a957e583 authored by Duncan P. N. Exon Smith's avatar Duncan P. N. Exon Smith
Browse files

Sema: Avoid a stack overflow on large CFGs

Large CFGs cause `checkForFunctionCall()` to overflow its stack.  Break
the recursion by manually managing the call stack instead.

Patch by Vedant Kumar!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243039 91177308-0d34-0410-b5e6-96231b3b80d8
parent ef22647e
No related branches found
No related tags found
No related merge requests found
...@@ -207,27 +207,35 @@ static void checkForFunctionCall(Sema &S, const FunctionDecl *FD, ...@@ -207,27 +207,35 @@ static void checkForFunctionCall(Sema &S, const FunctionDecl *FD,
CFGBlock &Block, unsigned ExitID, CFGBlock &Block, unsigned ExitID,
llvm::SmallVectorImpl<RecursiveState> &States, llvm::SmallVectorImpl<RecursiveState> &States,
RecursiveState State) { RecursiveState State) {
unsigned ID = Block.getBlockID(); SmallVector<std::pair<CFGBlock *, RecursiveState>, 16> Stack;
Stack.emplace_back(&Block, State);
// A block's state can only move to a higher state. while (!Stack.empty()) {
if (States[ID] >= State) CFGBlock &CurBlock = *Stack.back().first;
return; RecursiveState CurState = Stack.back().second;
Stack.pop_back();
States[ID] = State; unsigned ID = CurBlock.getBlockID();
if (State == FoundPathWithNoRecursiveCall) { // A block's state can only move to a higher state.
// Found a path to the exit node without a recursive call. if (States[ID] >= CurState)
if (ExitID == ID) continue;
return;
if (hasRecursiveCallInPath(FD, Block)) States[ID] = CurState;
State = FoundPath;
}
for (CFGBlock::succ_iterator I = Block.succ_begin(), E = Block.succ_end(); if (CurState == FoundPathWithNoRecursiveCall) {
I != E; ++I) // Found a path to the exit node without a recursive call.
if (*I) if (ExitID == ID)
checkForFunctionCall(S, FD, **I, ExitID, States, State); continue;
if (hasRecursiveCallInPath(FD, CurBlock))
CurState = FoundPath;
}
for (auto I = CurBlock.succ_begin(), E = CurBlock.succ_end(); I != E; ++I)
if (*I)
Stack.emplace_back(*I, CurState);
}
} }
static void checkRecursiveFunction(Sema &S, const FunctionDecl *FD, static void checkRecursiveFunction(Sema &S, const FunctionDecl *FD,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment