From 7e619cb45a59390c781ae359fc20a24f5853ad8c Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 8 May 2014 14:33:38 +0000 Subject: [PATCH] Small simplification: Reduce the use of cast<>. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208320 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenModule.cpp | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 01a2b25932..22ff2081c6 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -2182,27 +2182,27 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, llvm::FunctionType *Ty = getTypes().GetFunctionType(FI); // Get or create the prototype for the function. - llvm::Constant *Entry = - GV ? GV - : GetAddrOfFunction(GD, Ty, /*ForVTable=*/false, /*DontDefer*/ true); + if (!GV) { + llvm::Constant *C = + GetAddrOfFunction(GD, Ty, /*ForVTable=*/false, /*DontDefer*/ true); - // Strip off a bitcast if we got one back. - if (llvm::ConstantExpr *CE = dyn_cast(Entry)) { - assert(CE->getOpcode() == llvm::Instruction::BitCast); - Entry = CE->getOperand(0); + // Strip off a bitcast if we got one back. + if (llvm::ConstantExpr *CE = dyn_cast(C)) { + assert(CE->getOpcode() == llvm::Instruction::BitCast); + GV = cast(CE->getOperand(0)); + } else { + GV = cast(C); + } } - if (!cast(Entry)->isDeclaration()) { + if (!GV->isDeclaration()) { getDiags().Report(D->getLocation(), diag::err_duplicate_mangled_name); return; } - if (cast(Entry)->getType()->getElementType() != Ty) { - llvm::GlobalValue *OldFn = cast(Entry); - + if (GV->getType()->getElementType() != Ty) { // If the types mismatch then we have to rewrite the definition. - assert(OldFn->isDeclaration() && - "Shouldn't replace non-declaration"); + assert(GV->isDeclaration() && "Shouldn't replace non-declaration"); // F is the Function* for the one with the wrong type, we must make a new // Function* and update everything that used F (a declaration) with the new @@ -2212,8 +2212,8 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, // (e.g. "int f()") and then a definition of a different type // (e.g. "int f(int x)"). Move the old function aside so that it // doesn't interfere with GetAddrOfFunction. - OldFn->setName(StringRef()); - llvm::Function *NewFn = cast(GetAddrOfFunction(GD, Ty)); + GV->setName(StringRef()); + auto *NewFn = cast(GetAddrOfFunction(GD, Ty)); // This might be an implementation of a function without a // prototype, in which case, try to do special replacement of @@ -2222,29 +2222,29 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD, // so as to make a direct call, which makes the inliner happier // and suppresses a number of optimizer warnings (!) about // dropping arguments. - if (!OldFn->use_empty()) { - ReplaceUsesOfNonProtoTypeWithRealFunction(OldFn, NewFn); - OldFn->removeDeadConstantUsers(); + if (!GV->use_empty()) { + ReplaceUsesOfNonProtoTypeWithRealFunction(GV, NewFn); + GV->removeDeadConstantUsers(); } // Replace uses of F with the Function we will endow with a body. - if (!Entry->use_empty()) { + if (!GV->use_empty()) { llvm::Constant *NewPtrForOldDecl = - llvm::ConstantExpr::getBitCast(NewFn, Entry->getType()); - Entry->replaceAllUsesWith(NewPtrForOldDecl); + llvm::ConstantExpr::getBitCast(NewFn, GV->getType()); + GV->replaceAllUsesWith(NewPtrForOldDecl); } // Ok, delete the old function now, which is dead. - OldFn->eraseFromParent(); + GV->eraseFromParent(); - Entry = NewFn; + GV = NewFn; } // We need to set linkage and visibility on the function before // generating code for it because various parts of IR generation // want to propagate this information down (e.g. to local static // declarations). - llvm::Function *Fn = cast(Entry); + llvm::Function *Fn = cast(GV); setFunctionLinkage(GD, Fn); // FIXME: this is redundant with part of SetFunctionDefinitionAttributes -- 2.40.0