diff options
author | Anshuman Dasgupta <adasgupt@codeaurora.org> | 2012-12-10 22:45:57 +0000 |
---|---|---|
committer | Anshuman Dasgupta <adasgupt@codeaurora.org> | 2012-12-10 22:45:57 +0000 |
commit | 079e0819bc4a0dde6ce427757130db85216167de (patch) | |
tree | 72951e43e9c4ff9c7f5eec555f0eecda5ff804bd /utils/TableGen | |
parent | 617d18385f7fc33082c91710676a01ed528555af (diff) | |
download | external_llvm-079e0819bc4a0dde6ce427757130db85216167de.zip external_llvm-079e0819bc4a0dde6ce427757130db85216167de.tar.gz external_llvm-079e0819bc4a0dde6ce427757130db85216167de.tar.bz2 |
Fix PR14568: Avoid the DFA packetizer from making an invalid read
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
Diffstat (limited to 'utils/TableGen')
-rw-r--r-- | utils/TableGen/DFAPacketizerEmitter.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/utils/TableGen/DFAPacketizerEmitter.cpp b/utils/TableGen/DFAPacketizerEmitter.cpp index 0ad25a5..2549c47 100644 --- a/utils/TableGen/DFAPacketizerEmitter.cpp +++ b/utils/TableGen/DFAPacketizerEmitter.cpp @@ -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. @@ -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"; @@ -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"; |