Skip to content

Commit c244dae

Browse files
authored
[LLVM][TableGen] Fix Windows failure in DecoderEmitter (llvm#136310)
- Avoid dereferencing the end() iterator to get the end pointer, instead calculate it explicitly - Fixes a regression introduced in llvm#136220. - The windows build failure shows the following call stack: ``` | Exception Code: 0x80000003 | #0 0x00007ff74bc05897 std::_Vector_const_iterator<class std::_Vector_val<struct std::_Simple_types<unsigned char>>>::operator*(void) const C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.37.32822\include\vector:52:0 | #1 0x00007ff74bbd3d64 `anonymous namespace'::DecoderEmitter::emitTable D:\buildbot\llvm-worker\clang-cmake-x86_64-avx512-win\llvm\llvm\utils\TableGen\DecoderEmitter.cpp:852:0 ```
1 parent 2a692d2 commit c244dae

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
833833
// appropriate indentation levels.
834834
DecoderTable::const_iterator I = Table.begin();
835835
DecoderTable::const_iterator E = Table.end();
836+
const uint8_t *const EndPtr = Table.data() + Table.size();
836837
while (I != E) {
837838
assert(I < E && "incomplete decode table entry!");
838839

@@ -849,7 +850,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
849850

850851
// ULEB128 encoded start value.
851852
const char *ErrMsg = nullptr;
852-
unsigned Start = decodeULEB128(&*I, nullptr, &*E, &ErrMsg);
853+
unsigned Start = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
853854
assert(ErrMsg == nullptr && "ULEB128 value too large!");
854855
emitULEB128(I, OS);
855856

@@ -903,7 +904,7 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
903904
++I;
904905
// Decode the Opcode value.
905906
const char *ErrMsg = nullptr;
906-
unsigned Opc = decodeULEB128(&*I, nullptr, &*E, &ErrMsg);
907+
unsigned Opc = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
907908
assert(ErrMsg == nullptr && "ULEB128 value too large!");
908909

909910
OS << Indent << "MCD::OPC_" << (IsTry ? "Try" : "") << "Decode, ";
@@ -935,12 +936,12 @@ void DecoderEmitter::emitTable(formatted_raw_ostream &OS, DecoderTable &Table,
935936
OS << Indent << "MCD::OPC_SoftFail, ";
936937
// Decode the positive mask.
937938
const char *ErrMsg = nullptr;
938-
uint64_t PositiveMask = decodeULEB128(&*I, nullptr, &*E, &ErrMsg);
939+
uint64_t PositiveMask = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
939940
assert(ErrMsg == nullptr && "ULEB128 value too large!");
940941
emitULEB128(I, OS);
941942

942943
// Decode the negative mask.
943-
uint64_t NegativeMask = decodeULEB128(&*I, nullptr, &*E, &ErrMsg);
944+
uint64_t NegativeMask = decodeULEB128(&*I, nullptr, EndPtr, &ErrMsg);
944945
assert(ErrMsg == nullptr && "ULEB128 value too large!");
945946
emitULEB128(I, OS);
946947
OS << "// +ve mask: 0x";

0 commit comments

Comments
 (0)