diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-05-08 15:44:45 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-05-08 15:44:45 +0000 |
commit | bf6e67f2e9edcf36ec6e20228766cc396d63e4a0 (patch) | |
tree | a3e363b9e3c0e711ce086802c4caf628b14ec444 /clang/lib/CodeGen/CGVTables.cpp | |
parent | 340ba0c5fee463245aa26600c5b6b6eeb39d4feb (diff) | |
download | bcm5719-llvm-bf6e67f2e9edcf36ec6e20228766cc396d63e4a0.tar.gz bcm5719-llvm-bf6e67f2e9edcf36ec6e20228766cc396d63e4a0.zip |
Simplify a few cast<>s.
llvm-svn: 208331
Diffstat (limited to 'clang/lib/CodeGen/CGVTables.cpp')
-rw-r--r-- | clang/lib/CodeGen/CGVTables.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/clang/lib/CodeGen/CGVTables.cpp b/clang/lib/CodeGen/CGVTables.cpp index 08537d5f25c..14cad8bc117 100644 --- a/clang/lib/CodeGen/CGVTables.cpp +++ b/clang/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<llvm::ConstantExpr>(Entry)) { + if (llvm::ConstantExpr *CE = dyn_cast<llvm::ConstantExpr>(C)) { assert(CE->getOpcode() == llvm::Instruction::BitCast); - Entry = CE->getOperand(0); + Entry = cast<llvm::GlobalValue>(CE->getOperand(0)); + } else { + Entry = cast<llvm::GlobalValue>(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<llvm::GlobalValue>(Entry)->getType()->getElementType() != + if (Entry->getType()->getElementType() != CGM.getTypes().GetFunctionTypeForVTable(GD)) { - llvm::GlobalValue *OldThunkFn = cast<llvm::GlobalValue>(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<llvm::GlobalValue>(CGM.GetAddrOfThunk(GD, Thunk)); // If needed, replace the old thunk with a bitcast. if (!OldThunkFn->use_empty()) { |