1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 20:51:52 +01:00

Silence more static analyzer warnings.

Add in definedness checks for shift operators, null checks when
pointers are assumed by the code to be non-null, and explicit
unreachables.

llvm-svn: 224255
This commit is contained in:
Michael Ilseman 2014-12-15 18:48:43 +00:00
parent af63007e28
commit dd56e9aa72
13 changed files with 45 additions and 11 deletions

View File

@ -239,6 +239,7 @@ public:
} }
BitVector &set(unsigned Idx) { BitVector &set(unsigned Idx) {
assert(Bits && "Bits never allocated");
Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE); Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE);
return *this; return *this;
} }
@ -546,6 +547,7 @@ private:
void grow(unsigned NewSize) { void grow(unsigned NewSize) {
Capacity = std::max(NumBitWords(NewSize), Capacity * 2); Capacity = std::max(NumBitWords(NewSize), Capacity * 2);
assert(Capacity > 0 && "realloc-ing zero space");
Bits = (BitWord *)std::realloc(Bits, Capacity * sizeof(BitWord)); Bits = (BitWord *)std::realloc(Bits, Capacity * sizeof(BitWord));
clear_unused_bits(); clear_unused_bits();

View File

@ -768,6 +768,7 @@ protected:
assert(NumValues == VTs.NumVTs && assert(NumValues == VTs.NumVTs &&
"NumValues wasn't wide enough for its operands!"); "NumValues wasn't wide enough for its operands!");
for (unsigned i = 0; i != Ops.size(); ++i) { for (unsigned i = 0; i != Ops.size(); ++i) {
assert(OperandList && "no operands available");
OperandList[i].setUser(this); OperandList[i].setUser(this);
OperandList[i].setInitial(Ops[i]); OperandList[i].setInitial(Ops[i]);
} }

View File

@ -276,12 +276,14 @@ public:
} }
const StringTableOffset &getStringTableOffset() const { const StringTableOffset &getStringTableOffset() const {
assert(isSet() && "COFFSymbolRef points to nothing!");
return CS16 ? CS16->Name.Offset : CS32->Name.Offset; return CS16 ? CS16->Name.Offset : CS32->Name.Offset;
} }
uint32_t getValue() const { return CS16 ? CS16->Value : CS32->Value; } uint32_t getValue() const { return CS16 ? CS16->Value : CS32->Value; }
int32_t getSectionNumber() const { int32_t getSectionNumber() const {
assert(isSet() && "COFFSymbolRef points to nothing!");
if (CS16) { if (CS16) {
// Reserved sections are returned as negative numbers. // Reserved sections are returned as negative numbers.
if (CS16->SectionNumber <= COFF::MaxNumberOfSections16) if (CS16->SectionNumber <= COFF::MaxNumberOfSections16)
@ -291,13 +293,18 @@ public:
return static_cast<int32_t>(CS32->SectionNumber); return static_cast<int32_t>(CS32->SectionNumber);
} }
uint16_t getType() const { return CS16 ? CS16->Type : CS32->Type; } uint16_t getType() const {
assert(isSet() && "COFFSymbolRef points to nothing!");
return CS16 ? CS16->Type : CS32->Type;
}
uint8_t getStorageClass() const { uint8_t getStorageClass() const {
assert(isSet() && "COFFSymbolRef points to nothing!");
return CS16 ? CS16->StorageClass : CS32->StorageClass; return CS16 ? CS16->StorageClass : CS32->StorageClass;
} }
uint8_t getNumberOfAuxSymbols() const { uint8_t getNumberOfAuxSymbols() const {
assert(isSet() && "COFFSymbolRef points to nothing!");
return CS16 ? CS16->NumberOfAuxSymbols : CS32->NumberOfAuxSymbols; return CS16 ? CS16->NumberOfAuxSymbols : CS32->NumberOfAuxSymbols;
} }
@ -360,6 +367,8 @@ public:
} }
private: private:
bool isSet() const { return CS16 || CS32; }
const coff_symbol16 *CS16; const coff_symbol16 *CS16;
const coff_symbol32 *CS32; const coff_symbol32 *CS32;
}; };

View File

@ -1492,10 +1492,12 @@ void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalObject *GV) const {
if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment. if (NumBits == 0) return; // 1-byte aligned: no need to emit alignment.
assert(NumBits < std::numeric_limits<unsigned>::digits &&
"undefined behavior");
if (getCurrentSection()->getKind().isText()) if (getCurrentSection()->getKind().isText())
OutStreamer.EmitCodeAlignment(1 << NumBits); OutStreamer.EmitCodeAlignment(1u << NumBits);
else else
OutStreamer.EmitValueToAlignment(1 << NumBits); OutStreamer.EmitValueToAlignment(1u << NumBits);
} }
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//

View File

@ -74,6 +74,8 @@ struct DomainValue {
// Is domain available? // Is domain available?
bool hasDomain(unsigned domain) const { bool hasDomain(unsigned domain) const {
assert(domain < std::numeric_limits<unsigned>::digits &&
"undefined behavior");
return AvailableDomains & (1u << domain); return AvailableDomains & (1u << domain);
} }
@ -338,9 +340,11 @@ bool ExeDepsFix::merge(DomainValue *A, DomainValue *B) {
// All uses of B are referred to A. // All uses of B are referred to A.
B->Next = retain(A); B->Next = retain(A);
for (unsigned rx = 0; rx != NumRegs; ++rx) for (unsigned rx = 0; rx != NumRegs; ++rx) {
assert(LiveRegs && "no space allocated for live registers");
if (LiveRegs[rx].Value == B) if (LiveRegs[rx].Value == B)
setLiveReg(rx, A); setLiveReg(rx, A);
}
return true; return true;
} }
@ -645,6 +649,7 @@ void ExeDepsFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
SmallVector<LiveReg, 4> Regs; SmallVector<LiveReg, 4> Regs;
for (SmallVectorImpl<int>::iterator i=used.begin(), e=used.end(); i!=e; ++i) { for (SmallVectorImpl<int>::iterator i=used.begin(), e=used.end(); i!=e; ++i) {
int rx = *i; int rx = *i;
assert(LiveRegs && "no space allocated for live registers");
const LiveReg &LR = LiveRegs[rx]; const LiveReg &LR = LiveRegs[rx];
// This useless DomainValue could have been missed above. // This useless DomainValue could have been missed above.
if (!LR.Value->getCommonDomains(available)) { if (!LR.Value->getCommonDomains(available)) {
@ -684,9 +689,11 @@ void ExeDepsFix::visitSoftInstr(MachineInstr *mi, unsigned mask) {
continue; continue;
// If latest didn't merge, it is useless now. Kill all registers using it. // If latest didn't merge, it is useless now. Kill all registers using it.
for (SmallVectorImpl<int>::iterator i=used.begin(), e=used.end(); i!=e; ++i) for (int i : used) {
if (LiveRegs[*i].Value == Latest) assert(LiveRegs && "no space allocated for live registers");
kill(*i); if (LiveRegs[i].Value == Latest)
kill(i);
}
} }
// dv is the DomainValue we are going to use for this instruction. // dv is the DomainValue we are going to use for this instruction.

View File

@ -129,6 +129,7 @@ void MachineRegisterInfo::verifyUseList(unsigned Reg) const {
<< " use list MachineOperand " << MO << " use list MachineOperand " << MO
<< " has no parent instruction.\n"; << " has no parent instruction.\n";
Valid = false; Valid = false;
continue;
} }
MachineOperand *MO0 = &MI->getOperand(0); MachineOperand *MO0 = &MI->getOperand(0);
unsigned NumOps = MI->getNumOperands(); unsigned NumOps = MI->getNumOperands();

View File

@ -47,6 +47,7 @@ void RegisterClassInfo::runOnMachineFunction(const MachineFunction &mf) {
} }
// Does this MF have different CSRs? // Does this MF have different CSRs?
assert(TRI && "no register info set");
const MCPhysReg *CSR = TRI->getCalleeSavedRegs(MF); const MCPhysReg *CSR = TRI->getCalleeSavedRegs(MF);
if (Update || CSR != CalleeSaved) { if (Update || CSR != CalleeSaved) {
// Build a CSRNum map. Every CSR alias gets an entry pointing to the last // Build a CSRNum map. Every CSR alias gets an entry pointing to the last
@ -76,6 +77,7 @@ void RegisterClassInfo::runOnMachineFunction(const MachineFunction &mf) {
/// registers filtered out. Volatile registers come first followed by CSR /// registers filtered out. Volatile registers come first followed by CSR
/// aliases ordered according to the CSR order specified by the target. /// aliases ordered according to the CSR order specified by the target.
void RegisterClassInfo::compute(const TargetRegisterClass *RC) const { void RegisterClassInfo::compute(const TargetRegisterClass *RC) const {
assert(RC && "no register class given");
RCInfo &RCI = RegClass[RC->getID()]; RCInfo &RCI = RegClass[RC->getID()];
// Raw register count, including all reserved regs. // Raw register count, including all reserved regs.

View File

@ -566,6 +566,7 @@ static void getCopyToPartsVector(SelectionDAG &DAG, SDLoc DL,
} else if (NumParts > 0) { } else if (NumParts > 0) {
// If the intermediate type was expanded, split each the value into // If the intermediate type was expanded, split each the value into
// legal parts. // legal parts.
assert(NumIntermediates != 0 && "division by zero");
assert(NumParts % NumIntermediates == 0 && assert(NumParts % NumIntermediates == 0 &&
"Must expand into a divisible number of parts!"); "Must expand into a divisible number of parts!");
unsigned Factor = NumParts / NumIntermediates; unsigned Factor = NumParts / NumIntermediates;
@ -1408,7 +1409,7 @@ SelectionDAGBuilder::EmitBranchForMergedCondition(const Value *Cond,
if (TM.Options.NoNaNsFPMath) if (TM.Options.NoNaNsFPMath)
Condition = getFCmpCodeWithoutNaN(Condition); Condition = getFCmpCodeWithoutNaN(Condition);
} else { } else {
Condition = ISD::SETEQ; // silence warning. (void)Condition; // silence warning.
llvm_unreachable("Unknown compare instruction"); llvm_unreachable("Unknown compare instruction");
} }

View File

@ -76,7 +76,9 @@ void DWARFDebugInfoEntryMinimal::dump(raw_ostream &OS, DWARFUnit *u,
static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) { static void dumpApplePropertyAttribute(raw_ostream &OS, uint64_t Val) {
OS << " ("; OS << " (";
do { do {
uint64_t Bit = 1ULL << countTrailingZeros(Val); uint64_t Shift = countTrailingZeros(Val);
assert(Shift < 64 && "undefined behavior");
uint64_t Bit = 1ULL << Shift;
if (const char *PropName = ApplePropertyString(Bit)) if (const char *PropName = ApplePropertyString(Bit))
OS << PropName; OS << PropName;
else else

View File

@ -181,6 +181,8 @@ void IRObjectFile::moveSymbolNext(DataRefImpl &Symb) const {
Res = (Index << 2) | 3; Res = (Index << 2) | 3;
break; break;
} }
default:
llvm_unreachable("unreachable case");
} }
Symb.p = Res; Symb.p = Res;

View File

@ -236,6 +236,7 @@ static inline bool processLogicalImmediate(uint64_t Imm, unsigned RegSize,
if (isShiftedMask_64(Imm)) { if (isShiftedMask_64(Imm)) {
I = countTrailingZeros(Imm); I = countTrailingZeros(Imm);
assert(I < 64 && "undefined behavior");
CTO = CountTrailingOnes_64(Imm >> I); CTO = CountTrailingOnes_64(Imm >> I);
} else { } else {
Imm |= ~Mask; Imm |= ~Mask;

View File

@ -177,7 +177,9 @@ private:
MCELF::SetType(SD, ELF::STT_NOTYPE); MCELF::SetType(SD, ELF::STT_NOTYPE);
MCELF::SetBinding(SD, ELF::STB_LOCAL); MCELF::SetBinding(SD, ELF::STB_LOCAL);
SD.setExternal(false); SD.setExternal(false);
Symbol->setSection(*getCurrentSection().first); auto Sec = getCurrentSection().first;
assert(Sec && "need a section");
Symbol->setSection(*Sec);
const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext()); const MCExpr *Value = MCSymbolRefExpr::Create(Start, getContext());
Symbol->setVariableValue(Value); Symbol->setVariableValue(Value);

View File

@ -8577,7 +8577,9 @@ static SDValue PerformBFICombine(SDNode *N,
unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue(); unsigned InvMask = cast<ConstantSDNode>(N->getOperand(2))->getZExtValue();
unsigned LSB = countTrailingZeros(~InvMask); unsigned LSB = countTrailingZeros(~InvMask);
unsigned Width = (32 - countLeadingZeros(~InvMask)) - LSB; unsigned Width = (32 - countLeadingZeros(~InvMask)) - LSB;
unsigned Mask = (1 << Width)-1; assert(Width < std::numeric_limits<unsigned>::digits &&
"undefined behavior");
unsigned Mask = (1u << Width) - 1;
unsigned Mask2 = N11C->getZExtValue(); unsigned Mask2 = N11C->getZExtValue();
if ((Mask & (~Mask2)) == 0) if ((Mask & (~Mask2)) == 0)
return DCI.DAG.getNode(ARMISD::BFI, SDLoc(N), N->getValueType(0), return DCI.DAG.getNode(ARMISD::BFI, SDLoc(N), N->getValueType(0),