diff options
author | Heejin Ahn <aheejin@gmail.com> | 2019-02-04 19:13:39 +0000 |
---|---|---|
committer | Heejin Ahn <aheejin@gmail.com> | 2019-02-04 19:13:39 +0000 |
commit | 18c56a07623e496480854f4927bcf1ba5213d177 (patch) | |
tree | cec8a82b24bff109a543144afe8f7b580841d0c2 /llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | |
parent | 2e862c7555e35e13850f321d754b658d93375b67 (diff) | |
download | bcm5719-llvm-18c56a07623e496480854f4927bcf1ba5213d177.tar.gz bcm5719-llvm-18c56a07623e496480854f4927bcf1ba5213d177.zip |
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp index 884a18751e0..d059ef69915 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFixFunctionBitcasts.cpp @@ -64,12 +64,12 @@ ModulePass *llvm::createWebAssemblyFixFunctionBitcasts() { // Recursively descend the def-use lists from V to find non-bitcast users of // bitcasts of V. -static void FindUses(Value *V, Function &F, +static void findUses(Value *V, Function &F, SmallVectorImpl<std::pair<Use *, Function *>> &Uses, SmallPtrSetImpl<Constant *> &ConstantBCs) { for (Use &U : V->uses()) { - if (BitCastOperator *BC = dyn_cast<BitCastOperator>(U.getUser())) - FindUses(BC, F, Uses, ConstantBCs); + if (auto *BC = dyn_cast<BitCastOperator>(U.getUser())) + findUses(BC, F, Uses, ConstantBCs); else if (U.get()->getType() != F.getType()) { CallSite CS(U.getUser()); if (!CS) @@ -81,8 +81,8 @@ static void FindUses(Value *V, Function &F, continue; if (isa<Constant>(U.get())) { // Only add constant bitcasts to the list once; they get RAUW'd - auto c = ConstantBCs.insert(cast<Constant>(U.get())); - if (!c.second) + auto C = ConstantBCs.insert(cast<Constant>(U.get())); + if (!C.second) continue; } Uses.push_back(std::make_pair(&U, &F)); @@ -113,7 +113,7 @@ static void FindUses(Value *V, Function &F, // For bitcasts that involve struct types we don't know at this stage if they // would be equivalent at the wasm level and so we can't know if we need to // generate a wrapper. -static Function *CreateWrapper(Function *F, FunctionType *Ty) { +static Function *createWrapper(Function *F, FunctionType *Ty) { Module *M = F->getParent(); Function *Wrapper = Function::Create(Ty, Function::PrivateLinkage, @@ -151,11 +151,11 @@ static Function *CreateWrapper(Function *F, FunctionType *Ty) { BB->getInstList().push_back(PtrCast); Args.push_back(PtrCast); } else if (ArgType->isStructTy() || ParamType->isStructTy()) { - LLVM_DEBUG(dbgs() << "CreateWrapper: struct param type in bitcast: " + LLVM_DEBUG(dbgs() << "createWrapper: struct param type in bitcast: " << F->getName() << "\n"); WrapperNeeded = false; } else { - LLVM_DEBUG(dbgs() << "CreateWrapper: arg type mismatch calling: " + LLVM_DEBUG(dbgs() << "createWrapper: arg type mismatch calling: " << F->getName() << "\n"); LLVM_DEBUG(dbgs() << "Arg[" << Args.size() << "] Expected: " << *ParamType << " Got: " << *ArgType << "\n"); @@ -191,11 +191,11 @@ static Function *CreateWrapper(Function *F, FunctionType *Ty) { BB->getInstList().push_back(Cast); ReturnInst::Create(M->getContext(), Cast, BB); } else if (RtnType->isStructTy() || ExpectedRtnType->isStructTy()) { - LLVM_DEBUG(dbgs() << "CreateWrapper: struct return type in bitcast: " + LLVM_DEBUG(dbgs() << "createWrapper: struct return type in bitcast: " << F->getName() << "\n"); WrapperNeeded = false; } else { - LLVM_DEBUG(dbgs() << "CreateWrapper: return type mismatch calling: " + LLVM_DEBUG(dbgs() << "createWrapper: return type mismatch calling: " << F->getName() << "\n"); LLVM_DEBUG(dbgs() << "Expected: " << *ExpectedRtnType << " Got: " << *RtnType << "\n"); @@ -212,18 +212,18 @@ static Function *CreateWrapper(Function *F, FunctionType *Ty) { new UnreachableInst(M->getContext(), BB); Wrapper->setName(F->getName() + "_bitcast_invalid"); } else if (!WrapperNeeded) { - LLVM_DEBUG(dbgs() << "CreateWrapper: no wrapper needed: " << F->getName() + LLVM_DEBUG(dbgs() << "createWrapper: no wrapper needed: " << F->getName() << "\n"); Wrapper->eraseFromParent(); return nullptr; } - LLVM_DEBUG(dbgs() << "CreateWrapper: " << F->getName() << "\n"); + LLVM_DEBUG(dbgs() << "createWrapper: " << F->getName() << "\n"); return Wrapper; } // Test whether a main function with type FuncTy should be rewritten to have // type MainTy. -bool ShouldFixMainFunction(FunctionType *FuncTy, FunctionType *MainTy) { +bool shouldFixMainFunction(FunctionType *FuncTy, FunctionType *MainTy) { // Only fix the main function if it's the standard zero-arg form. That way, // the standard cases will work as expected, and users will see signature // mismatches from the linker for non-standard cases. @@ -242,7 +242,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { // Collect all the places that need wrappers. for (Function &F : M) { - FindUses(&F, F, Uses, ConstantBCs); + findUses(&F, F, Uses, ConstantBCs); // If we have a "main" function, and its type isn't // "int main(int argc, char *argv[])", create an artificial call with it @@ -255,7 +255,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { PointerType::get(Type::getInt8PtrTy(C), 0)}; FunctionType *MainTy = FunctionType::get(Type::getInt32Ty(C), MainArgTys, /*isVarArg=*/false); - if (ShouldFixMainFunction(F.getFunctionType(), MainTy)) { + if (shouldFixMainFunction(F.getFunctionType(), MainTy)) { LLVM_DEBUG(dbgs() << "Found `main` function with incorrect type: " << *F.getFunctionType() << "\n"); Value *Args[] = {UndefValue::get(MainArgTys[0]), @@ -274,8 +274,8 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { for (auto &UseFunc : Uses) { Use *U = UseFunc.first; Function *F = UseFunc.second; - PointerType *PTy = cast<PointerType>(U->get()->getType()); - FunctionType *Ty = dyn_cast<FunctionType>(PTy->getElementType()); + auto *PTy = cast<PointerType>(U->get()->getType()); + auto *Ty = dyn_cast<FunctionType>(PTy->getElementType()); // If the function is casted to something like i8* as a "generic pointer" // to be later casted to something else, we can't generate a wrapper for it. @@ -285,7 +285,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { auto Pair = Wrappers.insert(std::make_pair(std::make_pair(F, Ty), nullptr)); if (Pair.second) - Pair.first->second = CreateWrapper(F, Ty); + Pair.first->second = createWrapper(F, Ty); Function *Wrapper = Pair.first->second; if (!Wrapper) @@ -301,7 +301,7 @@ bool FixFunctionBitcasts::runOnModule(Module &M) { // one that gets called from startup. if (CallMain) { Main->setName("__original_main"); - Function *MainWrapper = + auto *MainWrapper = cast<Function>(CallMain->getCalledValue()->stripPointerCasts()); delete CallMain; if (Main->isDeclaration()) { |