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 @@ -945,7 +945,7 @@ // While this has no functional effect, it risks confusing someone reading // MIR output. // Examine all the operands, or the first N specified by the caller. - MaxOperand = std::min(MaxOperand, Old.getNumOperands()); + MaxOperand = std::min(MaxOperand, static_cast(Old.getNumOperands())); for (unsigned int I = 0; I < MaxOperand; ++I) { const auto &OldMO = Old.getOperand(I); auto &NewMO = New.getOperand(I); 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,