Skip to content
This repository was archived by the owner on Mar 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #708 from swaroop-sridhar/tidy
Browse files Browse the repository at this point in the history
ccFormat: Enable Clang-Tidy checks
  • Loading branch information
swaroop-sridhar committed Jul 17, 2015
2 parents a5892b1 + 48393e6 commit 0d623b5
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 138 deletions.
42 changes: 21 additions & 21 deletions include/Jit/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
#include "llvm/Config/llvm-config.h"

// The MethodID.NumArgs field may hold either of 2 values:
// EMPTY => the input string was all-blank, or empty.
// ANYARGS => the pattern did not specify any constraint on the number of
// Empty => the input string was all-blank, or empty.
// AnyArgs => the pattern did not specify any constraint on the number of
// arguments. Eg: "foo" as opposed to "foo()", "foo(3)", etc

enum MethodIDState { EMPTY = -7, ANYARGS = -1 };
enum MethodIDState { Empty = -7, AnyArgs = -1 };

/// \brief MethodID struct represents a Method Signature.
///
Expand All @@ -45,45 +45,45 @@ class MethodID {
std::unique_ptr<std::string> ClassName;
/// Method Name
std::unique_ptr<std::string> MethodName;
/// Number of method arguments. MethodIDState::ANYARGS => not specified
/// Number of method arguments. MethodIDState::AnyArgs => not specified
int NumArgs;

/// Default constructor.
MethodID()
: ClassName(nullptr), MethodName(nullptr),
NumArgs(MethodIDState::ANYARGS) {}
NumArgs(MethodIDState::AnyArgs) {}

/// Copy constructor.
MethodID(const MethodID &other) {
if (other.ClassName) {
ClassName = llvm::make_unique<std::string>(*other.ClassName);
MethodID(const MethodID &Other) {
if (Other.ClassName) {
ClassName = llvm::make_unique<std::string>(*Other.ClassName);
} else {
ClassName == nullptr;
ClassName = nullptr;
}
if (other.MethodName) {
MethodName = llvm::make_unique<std::string>(*other.MethodName);
if (Other.MethodName) {
MethodName = llvm::make_unique<std::string>(*Other.MethodName);
} else {
MethodName = nullptr;
}
this->NumArgs = other.NumArgs;
this->NumArgs = Other.NumArgs;
}

/// Copy assignment operator.

MethodID &operator=(const MethodID &other) {
if (this == &other)
MethodID &operator=(const MethodID &Other) {
if (this == &Other)
return *this;
if (other.ClassName) {
ClassName = llvm::make_unique<std::string>(*other.ClassName);
if (Other.ClassName) {
ClassName = llvm::make_unique<std::string>(*Other.ClassName);
} else {
ClassName = nullptr;
}
if (other.MethodName) {
MethodName = llvm::make_unique<std::string>(*other.MethodName);
if (Other.MethodName) {
MethodName = llvm::make_unique<std::string>(*Other.MethodName);
} else {
MethodName = nullptr;
}
NumArgs = other.NumArgs;
NumArgs = Other.NumArgs;
return *this;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ class MethodSet {
/// \return true if Method is contained in Set.

bool contains(const char *MethodName, const char *ClassName,
PCCOR_SIGNATURE sig);
PCCOR_SIGNATURE Sig);

/// Initialize a new MethodSet - once only.
void init(std::unique_ptr<std::string> ConfigValue);
Expand All @@ -170,7 +170,7 @@ class MethodSet {
class Convert {
public:
/// Convert a UTF-16 string to a UTF-8 string.
static std::unique_ptr<std::string> utf16ToUtf8(const char16_t *wideStr);
static std::unique_ptr<std::string> utf16ToUtf8(const char16_t *WideStr);
};

#endif // UTILITY_H
3 changes: 3 additions & 0 deletions include/Reader/abi.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ class ABIInfo {
ABIType ResultType, llvm::ArrayRef<ABIType> ArgTypes,
ABIArgInfo &ResultInfo,
std::vector<ABIArgInfo> &ArgInfos) const = 0;

/// \brief Virtual Destructor
virtual ~ABIInfo() = default;
};

#endif
6 changes: 3 additions & 3 deletions include/Reader/readerir.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ class GenIR : public ReaderBase {
/// \param Context Context to use for name generation..
/// \param Scope Scope to use for name generation.
/// \returns Name for the given token, handle, context, and scope.
std::string GetNameForToken(mdToken Token, CORINFO_GENERIC_HANDLE Handle,
std::string getNameForToken(mdToken Token, CORINFO_GENERIC_HANDLE Handle,
CORINFO_CONTEXT_HANDLE Context,
CORINFO_MODULE_HANDLE Scope);

Expand Down Expand Up @@ -1406,7 +1406,7 @@ class GenIR : public ReaderBase {
///
/// \param PHI PHI instruction.
/// \param NewOperand Operand to add to the PHI instruction.
void AddPHIOperand(llvm::PHINode *PHI, llvm::Value *NewOperand,
void addPHIOperand(llvm::PHINode *PHI, llvm::Value *NewOperand,
llvm::BasicBlock *NewBlock);

/// Change the type of a PHI instruction operand as a result of a stack merge.
Expand All @@ -1415,7 +1415,7 @@ class GenIR : public ReaderBase {
/// \param OperandBlock Basic block corresponding to the operand.
/// \param NewTy New type of the operand.
/// \returns Operand with the changed type.
llvm::Value *ChangePHIOperandType(llvm::Value *Operand,
llvm::Value *changePHIOperandType(llvm::Value *Operand,
llvm::BasicBlock *OperandBlock,
llvm::Type *NewTy);

Expand Down
6 changes: 3 additions & 3 deletions lib/Jit/LLILCJit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ObjectLoadListener {
///
/// \param LLVMRelocationType LLVM relocation type to translate from.
/// \returns EE relocation type.
uint64_t TranslateRelocationType(uint64_t LLVMRelocationType);
uint64_t translateRelocationType(uint64_t LLVMRelocationType);

private:
LLILCJitContext *Context;
Expand Down Expand Up @@ -582,7 +582,7 @@ void ObjectLoadListener::recordRelocations(const ObjectFile &Obj) {
uint64_t Target = Context->NameToHandleMap[TargetName];
Context->JitInfo->recordRelocation(MM->getCodeSection() + Offset,
(void *)Target,
TranslateRelocationType(RelType));
translateRelocationType(RelType));
}
++I;
}
Expand All @@ -591,7 +591,7 @@ void ObjectLoadListener::recordRelocations(const ObjectFile &Obj) {
}

uint64_t
ObjectLoadListener::TranslateRelocationType(uint64_t LLVMRelocationType) {
ObjectLoadListener::translateRelocationType(uint64_t LLVMRelocationType) {
switch (LLVMRelocationType) {
case IMAGE_REL_AMD64_ABSOLUTE:
return IMAGE_REL_BASED_ABSOLUTE;
Expand Down
68 changes: 34 additions & 34 deletions lib/Jit/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,51 @@ int MethodID::parseArgs(const string &S, size_t &I) {

I = S.find_first_of(")", I);
if (I == string::npos)
return MethodIDState::ANYARGS;
return MethodIDState::AnyArgs;

string num = string(S, Start, I - Start);
int NArgs = atoi(num.c_str());
string Num = string(S, Start, I - Start);
int NArgs = atoi(Num.c_str());
++I; // skip )
return NArgs;
}

unique_ptr<MethodID> MethodID::parse(const string &S, size_t &I) {
MethodID MID;
MethodID MId;
size_t SLen = S.length();

string token = MID.scan(S, I);
string Token = MId.scan(S, I);

if (token == "") // off the end of S
if (Token == "") // off the end of S
return nullptr;

if (token == "*") {
MID.ClassName = llvm::make_unique<string>(token);
MID.MethodName = nullptr;
if (Token == "*") {
MId.ClassName = llvm::make_unique<string>(Token);
MId.MethodName = nullptr;
if (I >= SLen || S[I] == ' ') {
MID.NumArgs = MethodIDState::ANYARGS;
MId.NumArgs = MethodIDState::AnyArgs;
}
return llvm::make_unique<MethodID>(MID);
return llvm::make_unique<MethodID>(MId);
return nullptr;
}

if (S[I] == ':') { // C:M | C:M(A)
MID.ClassName = llvm::make_unique<string>(token);
token = MID.scan(S, ++I); // M | M(A)
MId.ClassName = llvm::make_unique<string>(Token);
Token = MId.scan(S, ++I); // M | M(A)
}

MID.MethodName = llvm::make_unique<string>(token);
MId.MethodName = llvm::make_unique<string>(Token);

if (I >= SLen || S[I] == ' ') {
MID.NumArgs = MethodIDState::ANYARGS;
return llvm::make_unique<MethodID>(MID);
MId.NumArgs = MethodIDState::AnyArgs;
return llvm::make_unique<MethodID>(MId);
return nullptr;
}

if (S[I] != '(') // illegal
return nullptr;

MID.NumArgs = MID.parseArgs(S, I);
return llvm::make_unique<MethodID>(MID);
MId.NumArgs = MId.parseArgs(S, I);
return llvm::make_unique<MethodID>(MId);
return nullptr;
}

Expand Down Expand Up @@ -90,22 +90,22 @@ void MethodSet::init(unique_ptr<string> ConfigValue) {

void MethodSet::insert(unique_ptr<string> Ups) {
size_t I = 0;
std::list<MethodID> *MIDL = new std::list<MethodID>();
std::list<MethodID> *MIdList = new std::list<MethodID>();
string S = *Ups;

auto MID = MethodID::parse(S, I);
while (MID) {
MIDL->push_back(*MID);
MID = MethodID::parse(S, I);
auto MId = MethodID::parse(S, I);
while (MId) {
MIdList->push_back(*MId);
MId = MethodID::parse(S, I);
}

// This write should be atomic, delete if we're not the first.
llvm::sys::cas_flag F = llvm::sys::CompareAndSwap(
(llvm::sys::cas_flag *)&(this->Initialized), 0x1, 0x0);
if (F != 0x0) {
delete MIDL;
delete MIdList;
} else {
this->MethodIDList = MIDL;
this->MethodIDList = MIdList;
}
}

Expand All @@ -114,7 +114,7 @@ bool MethodSet::contains(const char *MethodName, const char *ClassName,

assert(this->isInitialized());

int NumArgs = MethodIDState::ANYARGS; // assume no signature supplied
int NumArgs = MethodIDState::AnyArgs; // assume no signature supplied

if (PCSig) {
PCSig++; // skip calling convention
Expand All @@ -124,28 +124,28 @@ bool MethodSet::contains(const char *MethodName, const char *ClassName,
string StrClassName = ClassName ? ClassName : "";
string StrMethodName = MethodName ? MethodName : "";

auto begin = this->MethodIDList->begin();
auto end = this->MethodIDList->end();
auto Begin = this->MethodIDList->begin();
auto End = this->MethodIDList->end();

for (auto p = begin; p != end; ++p) { // p => "pattern"
for (auto P = Begin; P != End; ++P) { // P => "pattern"

// Check for "*", the common case, first
if (p->ClassName && *p->ClassName == "*")
if (P->ClassName && *P->ClassName == "*")
return true;

// Check for mis-match on NumArgs
if (p->NumArgs != MethodIDState::ANYARGS && p->NumArgs != NumArgs)
if (P->NumArgs != MethodIDState::AnyArgs && P->NumArgs != NumArgs)
continue;

// Check for mis-match on MethodName
if (p->MethodName && (*p->MethodName != StrMethodName))
if (P->MethodName && (*P->MethodName != StrMethodName))
continue;

// Check for match on ClassName (we already match NumArgs and MethodName)
if (!p->ClassName) // no ClassName
if (!P->ClassName) // no ClassName
return true;

if (*p->ClassName == StrClassName)
if (*P->ClassName == StrClassName)
return true;
}

Expand Down
18 changes: 9 additions & 9 deletions lib/Reader/reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,7 @@ EHRegion *getFinallyRegion(EHRegion *TryRegion) {

#define CHECKTARGET(TargetOffset, BufSize) \
{ \
if (TargetOffset < 0 || TargetOffset >= BufSize) \
if ((TargetOffset) < 0 || (TargetOffset) >= (BufSize)) \
ReaderBase::verGlobalError(MVER_E_BAD_BRANCH); \
}

Expand Down Expand Up @@ -8000,9 +8000,9 @@ void ReaderBase::msilToIR(void) {
}

// Process the nodes in MSIL offset order.
std::list<FlowGraphNode *>::iterator it = FlowGraphMSILOffsetOrder.begin();
while (it != FlowGraphMSILOffsetOrder.end()) {
FlowGraphNode *CurrentNode = *it;
std::list<FlowGraphNode *>::iterator It = FlowGraphMSILOffsetOrder.begin();
while (It != FlowGraphMSILOffsetOrder.end()) {
FlowGraphNode *CurrentNode = *It;
readBytesForFlowGraphNode(CurrentNode, IsImportOnly);

#ifndef CC_PEVERIFY
Expand All @@ -8029,15 +8029,15 @@ void ReaderBase::msilToIR(void) {

// The two checks above ensure that it's safe to insert Successor after
// CurrentNode even if that breaks MSIL offset order.
++it;
FlowGraphMSILOffsetOrder.insert(it, Successor);
++It;
FlowGraphMSILOffsetOrder.insert(It, Successor);
// Point the iterator back to CurrentNode.
--it;
--it;
--It;
--It;
fgNodeSetVisited(Successor, true);
}
}
++it;
++It;
}

// global verification dataflow
Expand Down
Loading

0 comments on commit 0d623b5

Please sign in to comment.