Index: llvm/include/llvm/CodeGen/MachineFunction.h =================================================================== --- llvm/include/llvm/CodeGen/MachineFunction.h +++ llvm/include/llvm/CodeGen/MachineFunction.h @@ -546,7 +546,7 @@ /// examine for substitutions to the first N operands by setting /// \p MaxOperand. void substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New, - unsigned MaxOperand = UINT_MAX); + uint16_t MaxOperand = USHORT_MAX); /// Find the underlying defining instruction / operand for a COPY instruction /// while in SSA form. Copies do not actually define values -- they move them Index: llvm/include/llvm/CodeGen/MachineInstr.h =================================================================== --- llvm/include/llvm/CodeGen/MachineInstr.h +++ llvm/include/llvm/CodeGen/MachineInstr.h @@ -120,7 +120,7 @@ // Operands are allocated by an ArrayRecycler. MachineOperand *Operands = nullptr; // Pointer to the first operand. - unsigned NumOperands = 0; // Number of operands on instruction. + uint16_t NumOperands = 0; // Number of operands on instruction. uint16_t Flags = 0; // Various bits of additional // information about machine @@ -516,7 +516,7 @@ unsigned getOpcode() const { return MCID->Opcode; } /// Retuns the total number of operands. - unsigned getNumOperands() const { return NumOperands; } + uint16_t getNumOperands() const { return NumOperands; } /// Returns the total number of operands which are debug locations. unsigned getNumDebugOperands() const { @@ -604,7 +604,7 @@ } /// Returns the implicit operands number. - unsigned getNumImplicitOperands() const { + uint16_t getNumImplicitOperands() const { return getNumOperands() - getNumExplicitOperands(); } @@ -623,7 +623,7 @@ } /// Returns the number of non-implicit operands. - unsigned getNumExplicitOperands() const; + unsigned short getNumExplicitOperands() const; /// Returns the number of non-implicit definitions. unsigned getNumExplicitDefs() const; Index: llvm/lib/CodeGen/MachineFunction.cpp =================================================================== --- llvm/lib/CodeGen/MachineFunction.cpp +++ llvm/lib/CodeGen/MachineFunction.cpp @@ -934,7 +934,7 @@ void MachineFunction::substituteDebugValuesForInst(const MachineInstr &Old, MachineInstr &New, - unsigned MaxOperand) { + uint16_t MaxOperand) { // If the Old instruction wasn't tracked at all, there is no work to do. unsigned OldInstrNum = Old.peekDebugInstrNum(); if (!OldInstrNum) Index: llvm/lib/CodeGen/MachineInstr.cpp =================================================================== --- llvm/lib/CodeGen/MachineInstr.cpp +++ llvm/lib/CodeGen/MachineInstr.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include using namespace llvm; @@ -192,6 +193,7 @@ /// an explicit operand it is added at the end of the explicit operand list /// (before the first implicit operand). void MachineInstr::addOperand(MachineFunction &MF, const MachineOperand &Op) { + assert(NumOperands < std::numeric_limits::max() && "Cannot add more operands."); assert(MCID && "Cannot add operands before providing an instr descriptor"); // Check if we're adding one of our existing operands. @@ -738,12 +740,12 @@ return isCandidateForCallSiteEntry(); } -unsigned MachineInstr::getNumExplicitOperands() const { - unsigned NumOperands = MCID->getNumOperands(); +uint16_t MachineInstr::getNumExplicitOperands() const { + uint16_t NumOperands = MCID->getNumOperands(); if (!MCID->isVariadic()) return NumOperands; - for (unsigned I = NumOperands, E = getNumOperands(); I != E; ++I) { + for (uint16_t I = NumOperands, E = getNumOperands(); I != E; ++I) { const MachineOperand &MO = getOperand(I); // The operands must always be in the following order: // - explicit reg defs,