[Analysis] Fix some Clang-tidy modernize and Include What You Use warnings; other minor fixes (NFC).

llvm-svn: 327687
This commit is contained in:
Eugene Zelenko 2018-03-16 00:37:51 +00:00
parent 14e5a1b05b
commit 87fe1a79f7
3 changed files with 340 additions and 344 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
//===- ThreadSafetyUtil.h --------------------------------------*- C++ --*-===//
//===- ThreadSafetyUtil.h ---------------------------------------*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
@ -14,18 +14,23 @@
#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYUTIL_H
#define LLVM_CLANG_ANALYSIS_ANALYSES_THREADSAFETYUTIL_H
#include "clang/AST/ExprCXX.h"
#include "clang/AST/Decl.h"
#include "clang/Basic/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/AlignOf.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Compiler.h"
#include <cassert>
#include <cstddef>
#include <cstring>
#include <iterator>
#include <ostream>
#include <utility>
#include <string>
#include <vector>
namespace clang {
class Expr;
namespace threadSafety {
namespace til {
@ -41,7 +46,7 @@ private:
};
public:
MemRegionRef() : Allocator(nullptr) {}
MemRegionRef() = default;
MemRegionRef(llvm::BumpPtrAllocator *A) : Allocator(A) {}
void *allocate(size_t Sz) {
@ -55,12 +60,13 @@ public:
}
private:
llvm::BumpPtrAllocator *Allocator;
llvm::BumpPtrAllocator *Allocator = nullptr;
};
} // end namespace til
} // end namespace threadSafety
} // end namespace clang
} // namespace til
} // namespace threadSafety
} // namespace clang
inline void *operator new(size_t Sz,
clang::threadSafety::til::MemRegionRef &R) {
@ -70,10 +76,7 @@ inline void *operator new(size_t Sz,
namespace clang {
namespace threadSafety {
std::string getSourceLiteralString(const clang::Expr *CE);
using llvm::StringRef;
using clang::SourceLocation;
std::string getSourceLiteralString(const Expr *CE);
namespace til {
@ -81,11 +84,13 @@ namespace til {
// suitable for use with bump pointer allocation.
template <class T> class SimpleArray {
public:
SimpleArray() : Data(nullptr), Size(0), Capacity(0) {}
SimpleArray() = default;
SimpleArray(T *Dat, size_t Cp, size_t Sz = 0)
: Data(Dat), Size(Sz), Capacity(Cp) {}
SimpleArray(MemRegionRef A, size_t Cp)
: Data(Cp == 0 ? nullptr : A.allocateT<T>(Cp)), Size(0), Capacity(Cp) {}
SimpleArray(const SimpleArray<T> &A) = delete;
SimpleArray(SimpleArray<T> &&A)
: Data(A.Data), Size(A.Size), Capacity(A.Capacity) {
A.Data = nullptr;
@ -123,10 +128,10 @@ public:
reserve(u_max(Size + N, Capacity * 2), A);
}
typedef T *iterator;
typedef const T *const_iterator;
typedef std::reverse_iterator<iterator> reverse_iterator;
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
using iterator = T *;
using const_iterator = const T *;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
size_t size() const { return Size; }
size_t capacity() const { return Capacity; }
@ -135,27 +140,30 @@ public:
assert(i < Size && "Array index out of bounds.");
return Data[i];
}
const T &operator[](unsigned i) const {
assert(i < Size && "Array index out of bounds.");
return Data[i];
}
T &back() {
assert(Size && "No elements in the array.");
return Data[Size - 1];
}
const T &back() const {
assert(Size && "No elements in the array.");
return Data[Size - 1];
}
iterator begin() { return Data; }
iterator end() { return Data + Size; }
iterator end() { return Data + Size; }
const_iterator begin() const { return Data; }
const_iterator end() const { return Data + Size; }
const_iterator end() const { return Data + Size; }
const_iterator cbegin() const { return Data; }
const_iterator cend() const { return Data + Size; }
const_iterator cend() const { return Data + Size; }
reverse_iterator rbegin() { return reverse_iterator(end()); }
reverse_iterator rend() { return reverse_iterator(begin()); }
@ -163,6 +171,7 @@ public:
const_reverse_iterator rbegin() const {
return const_reverse_iterator(end());
}
const_reverse_iterator rend() const {
return const_reverse_iterator(begin());
}
@ -198,6 +207,7 @@ public:
llvm::iterator_range<reverse_iterator> reverse() {
return llvm::make_range(rbegin(), rend());
}
llvm::iterator_range<const_reverse_iterator> reverse() const {
return llvm::make_range(rbegin(), rend());
}
@ -209,14 +219,12 @@ private:
static const size_t InitialCapacity = 4;
SimpleArray(const SimpleArray<T> &A) = delete;
T *Data;
size_t Size;
size_t Capacity;
T *Data = nullptr;
size_t Size = 0;
size_t Capacity = 0;
};
} // end namespace til
} // namespace til
// A copy on write vector.
// The vector can be in one of three states:
@ -228,20 +236,28 @@ template<typename T>
class CopyOnWriteVector {
class VectorData {
public:
VectorData() : NumRefs(1) { }
VectorData(const VectorData &VD) : NumRefs(1), Vect(VD.Vect) { }
unsigned NumRefs;
unsigned NumRefs = 1;
std::vector<T> Vect;
VectorData() = default;
VectorData(const VectorData &VD) : Vect(VD.Vect) {}
};
// No copy constructor or copy assignment. Use clone() with move assignment.
CopyOnWriteVector(const CopyOnWriteVector &V) = delete;
void operator=(const CopyOnWriteVector &V) = delete;
public:
CopyOnWriteVector() : Data(nullptr) {}
CopyOnWriteVector() = default;
CopyOnWriteVector(CopyOnWriteVector &&V) : Data(V.Data) { V.Data = nullptr; }
CopyOnWriteVector &operator=(CopyOnWriteVector &&V) {
destroy();
Data = V.Data;
V.Data = nullptr;
return *this;
}
// No copy constructor or copy assignment. Use clone() with move assignment.
CopyOnWriteVector(const CopyOnWriteVector &) = delete;
CopyOnWriteVector &operator=(const CopyOnWriteVector &) = delete;
~CopyOnWriteVector() { destroy(); }
// Returns true if this holds a valid vector.
@ -283,14 +299,7 @@ public:
// Create a lazy copy of this vector.
CopyOnWriteVector clone() { return CopyOnWriteVector(Data); }
CopyOnWriteVector &operator=(CopyOnWriteVector &&V) {
destroy();
Data = V.Data;
V.Data = nullptr;
return *this;
}
typedef typename std::vector<T>::const_iterator const_iterator;
using const_iterator = typename std::vector<T>::const_iterator;
const std::vector<T> &elements() const { return Data->Vect; }
@ -336,14 +345,14 @@ private:
++Data->NumRefs;
}
VectorData *Data;
VectorData *Data = nullptr;
};
inline std::ostream& operator<<(std::ostream& ss, const StringRef str) {
return ss.write(str.data(), str.size());
}
} // end namespace threadSafety
} // end namespace clang
} // namespace threadSafety
} // namespace clang
#endif // LLVM_CLANG_THREAD_SAFETY_UTIL_H

View File

@ -1,4 +1,4 @@
//===- ThreadSafetyTIL.cpp -------------------------------------*- C++ --*-===//
//===- ThreadSafetyTIL.cpp ------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
@ -8,7 +8,11 @@
//===----------------------------------------------------------------------===//
#include "clang/Analysis/Analyses/ThreadSafetyTIL.h"
#include "clang/Analysis/Analyses/ThreadSafetyTraverse.h"
#include "clang/Basic/LLVM.h"
#include "llvm/Support/Casting.h"
#include <cassert>
#include <cstddef>
using namespace clang;
using namespace threadSafety;
using namespace til;
@ -19,7 +23,7 @@ StringRef til::getUnaryOpcodeString(TIL_UnaryOpcode Op) {
case UOP_BitNot: return "~";
case UOP_LogicNot: return "!";
}
return "";
return {};
}
StringRef til::getBinaryOpcodeString(TIL_BinaryOpcode Op) {
@ -42,10 +46,9 @@ StringRef til::getBinaryOpcodeString(TIL_BinaryOpcode Op) {
case BOP_LogicAnd: return "&&";
case BOP_LogicOr: return "||";
}
return "";
return {};
}
SExpr* Future::force() {
Status = FS_evaluating;
Result = compute();
@ -53,13 +56,12 @@ SExpr* Future::force() {
return Result;
}
unsigned BasicBlock::addPredecessor(BasicBlock *Pred) {
unsigned Idx = Predecessors.size();
Predecessors.reserveCheck(1, Arena);
Predecessors.push_back(Pred);
for (SExpr *E : Args) {
if (Phi* Ph = dyn_cast<Phi>(E)) {
for (auto *E : Args) {
if (auto *Ph = dyn_cast<Phi>(E)) {
Ph->values().reserveCheck(1, Arena);
Ph->values().push_back(nullptr);
}
@ -67,28 +69,26 @@ unsigned BasicBlock::addPredecessor(BasicBlock *Pred) {
return Idx;
}
void BasicBlock::reservePredecessors(unsigned NumPreds) {
Predecessors.reserve(NumPreds, Arena);
for (SExpr *E : Args) {
if (Phi* Ph = dyn_cast<Phi>(E)) {
for (auto *E : Args) {
if (auto *Ph = dyn_cast<Phi>(E)) {
Ph->values().reserve(NumPreds, Arena);
}
}
}
// If E is a variable, then trace back through any aliases or redundant
// Phi nodes to find the canonical definition.
const SExpr *til::getCanonicalVal(const SExpr *E) {
while (true) {
if (auto *V = dyn_cast<Variable>(E)) {
if (const auto *V = dyn_cast<Variable>(E)) {
if (V->kind() == Variable::VK_Let) {
E = V->definition();
continue;
}
}
if (const Phi *Ph = dyn_cast<Phi>(E)) {
if (const auto *Ph = dyn_cast<Phi>(E)) {
if (Ph->status() == Phi::PH_SingleVal) {
E = Ph->values()[0];
continue;
@ -99,7 +99,6 @@ const SExpr *til::getCanonicalVal(const SExpr *E) {
return E;
}
// If E is a variable, then trace back through any aliases or redundant
// Phi nodes to find the canonical definition.
// The non-const version will simplify incomplete Phi nodes.
@ -129,7 +128,6 @@ SExpr *til::simplifyToCanonicalVal(SExpr *E) {
}
}
// Trace the arguments of an incomplete Phi node to see if they have the same
// canonical definition. If so, mark the Phi node as redundant.
// getCanonicalVal() will recursively call simplifyIncompletePhi().
@ -140,7 +138,7 @@ void til::simplifyIncompleteArg(til::Phi *Ph) {
Ph->setStatus(Phi::PH_MultiVal);
SExpr *E0 = simplifyToCanonicalVal(Ph->values()[0]);
for (unsigned i=1, n=Ph->values().size(); i<n; ++i) {
for (unsigned i = 1, n = Ph->values().size(); i < n; ++i) {
SExpr *Ei = simplifyToCanonicalVal(Ph->values()[i]);
if (Ei == Ph)
continue; // Recursive reference to itself. Don't count.
@ -151,7 +149,6 @@ void til::simplifyIncompleteArg(til::Phi *Ph) {
Ph->setStatus(Phi::PH_SingleVal);
}
// Renumbers the arguments and instructions to have unique, sequential IDs.
int BasicBlock::renumberInstrs(int ID) {
for (auto *Arg : Args)
@ -166,7 +163,7 @@ int BasicBlock::renumberInstrs(int ID) {
// Each block will be written into the Blocks array in order, and its BlockID
// will be set to the index in the array. Sorting should start from the entry
// block, and ID should be the total number of blocks.
int BasicBlock::topologicalSort(SimpleArray<BasicBlock*>& Blocks, int ID) {
int BasicBlock::topologicalSort(SimpleArray<BasicBlock *> &Blocks, int ID) {
if (Visited) return ID;
Visited = true;
for (auto *Block : successors())
@ -258,7 +255,6 @@ void BasicBlock::computePostDominator() {
PostDominatorNode.SizeOfSubTree = 1;
}
// Renumber instructions in all blocks
void SCFG::renumberInstrs() {
int InstrID = 0;
@ -266,7 +262,6 @@ void SCFG::renumberInstrs() {
InstrID = Block->renumberInstrs(InstrID);
}
static inline void computeNodeSize(BasicBlock *B,
BasicBlock::TopologyNode BasicBlock::*TN) {
BasicBlock::TopologyNode *N = &(B->*TN);
@ -287,7 +282,6 @@ static inline void computeNodeID(BasicBlock *B,
}
}
// Normalizes a CFG. Normalization has a few major components:
// 1) Removing unreachable blocks.
// 2) Computing dominators and post-dominators