Skip to content

Commit

Permalink
Fix PR14568: Avoid the DFA packetizer from making an invalid read
Browse files Browse the repository at this point in the history
beyond array bounds.

No test case since I cannot reproduce an ICE with this bug. According
to Carlos -- the bug reporter -- a segfault occurs only when LLVM is
compiled with a specific version of GCC.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@169783 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
adasgupt1 committed Dec 10, 2012
1 parent 617d183 commit 079e081
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion utils/TableGen/DFAPacketizerEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ DFAPacketizerEmitter::DFAPacketizerEmitter(RecordKeeper &R):
//
//
void DFA::writeTableAndAPI(raw_ostream &OS, const std::string &TargetName) {
static const std::string SentinelEntry = "{-1, -1}";
DFA::StateSet::iterator SI = states.begin();
// This table provides a map to the beginning of the transitions for State s
// in DFAStateInputTable.
Expand All @@ -305,12 +306,17 @@ void DFA::writeTableAndAPI(raw_ostream &OS, const std::string &TargetName) {
// If there are no valid transitions from this stage, we need a sentinel
// transition.
if (ValidTransitions == StateEntry[i]) {
OS << "{-1, -1},";
OS << SentinelEntry << ",";
++ValidTransitions;
}

OS << "\n";
}

// Print out a sentinel entry at the end of the StateInputTable. This is
// needed to iterate over StateInputTable in DFAPacketizer::ReadTable()
OS << SentinelEntry << "\n";

OS << "};\n\n";
OS << "const unsigned int " << TargetName << "DFAStateEntryTable[] = {\n";

Expand All @@ -319,6 +325,9 @@ void DFA::writeTableAndAPI(raw_ostream &OS, const std::string &TargetName) {
for (unsigned i = 0; i < states.size(); ++i)
OS << StateEntry[i] << ", ";

// Print out the index to the sentinel entry in StateInputTable
OS << ValidTransitions << ", ";

OS << "\n};\n";
OS << "} // namespace\n";

Expand Down

0 comments on commit 079e081

Please sign in to comment.