From 40844b15d9da7a0f8c578000f3eb8226ec34c33d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 8 May 2014 15:44:45 +0000 Subject: [PATCH] Simplify a few cast<>s. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@208331 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGVTables.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/CodeGen/CGVTables.cpp b/lib/CodeGen/CGVTables.cpp index 08537d5f25..14cad8bc11 100644 --- a/lib/CodeGen/CGVTables.cpp +++ b/lib/CodeGen/CGVTables.cpp @@ -321,27 +321,30 @@ void CodeGenVTables::emitThunk(GlobalDecl GD, const ThunkInfo &Thunk, const CGFunctionInfo &FnInfo = CGM.getTypes().arrangeGlobalDeclaration(GD); // FIXME: re-use FnInfo in this computation. - llvm::Constant *Entry = CGM.GetAddrOfThunk(GD, Thunk); - + llvm::Constant *C = CGM.GetAddrOfThunk(GD, Thunk); + llvm::GlobalValue *Entry; + // Strip off a bitcast if we got one back. - if (llvm::ConstantExpr *CE = dyn_cast(Entry)) { + if (llvm::ConstantExpr *CE = dyn_cast(C)) { assert(CE->getOpcode() == llvm::Instruction::BitCast); - Entry = CE->getOperand(0); + Entry = cast(CE->getOperand(0)); + } else { + Entry = cast(C); } - + // There's already a declaration with the same name, check if it has the same // type or if we need to replace it. - if (cast(Entry)->getType()->getElementType() != + if (Entry->getType()->getElementType() != CGM.getTypes().GetFunctionTypeForVTable(GD)) { - llvm::GlobalValue *OldThunkFn = cast(Entry); - + llvm::GlobalValue *OldThunkFn = Entry; + // If the types mismatch then we have to rewrite the definition. assert(OldThunkFn->isDeclaration() && "Shouldn't replace non-declaration"); // Remove the name from the old thunk function and get a new thunk. OldThunkFn->setName(StringRef()); - Entry = CGM.GetAddrOfThunk(GD, Thunk); + Entry = cast(CGM.GetAddrOfThunk(GD, Thunk)); // If needed, replace the old thunk with a bitcast. if (!OldThunkFn->use_empty()) { -- 2.40.0