[cfe-commits] r103810 - in /cfe/trunk: lib/CodeGen/CGExprAgg.cpp test/CodeGenCXX/dynamic-cast.cpp
Douglas Gregor
dgregor at apple.com
Fri May 14 14:31:02 PDT 2010
Author: dgregor
Date: Fri May 14 16:31:02 2010
New Revision: 103810
URL: http://llvm.org/viewvc/llvm-project?rev=103810&view=rev
Log:
Emit an lvalue dynamic_cast even if the result is not used. Another
part (or possibly all) of PR7132.
Modified:
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp
Modified: cfe/trunk/lib/CodeGen/CGExprAgg.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprAgg.cpp?rev=103810&r1=103809&r2=103810&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExprAgg.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprAgg.cpp Fri May 14 16:31:02 2010
@@ -178,7 +178,7 @@
//===----------------------------------------------------------------------===//
void AggExprEmitter::VisitCastExpr(CastExpr *E) {
- if (!DestPtr) {
+ if (!DestPtr && E->getCastKind() != CastExpr::CK_Dynamic) {
Visit(E->getSubExpr());
return;
}
@@ -186,6 +186,20 @@
switch (E->getCastKind()) {
default: assert(0 && "Unhandled cast kind!");
+ case CastExpr::CK_Dynamic: {
+ assert(isa<CXXDynamicCastExpr>(E) && "CK_Dynamic without a dynamic_cast?");
+ LValue LV = CGF.EmitCheckedLValue(E->getSubExpr());
+ // FIXME: Do we also need to handle property references here?
+ if (LV.isSimple())
+ CGF.EmitDynamicCast(LV.getAddress(), cast<CXXDynamicCastExpr>(E));
+ else
+ CGF.CGM.ErrorUnsupported(E, "non-simple lvalue dynamic_cast");
+
+ if (DestPtr)
+ CGF.CGM.ErrorUnsupported(E, "lvalue dynamic_cast with a destination");
+ break;
+ }
+
case CastExpr::CK_ToUnion: {
// GCC union extension
QualType PtrTy =
Modified: cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp?rev=103810&r1=103809&r2=103810&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/dynamic-cast.cpp Fri May 14 16:31:02 2010
@@ -10,7 +10,7 @@
// CHECK: call i8* @__dynamic_cast
// CHECK: br i1
// CHECK: invoke void @__cxa_bad_cast() noreturn
- return dynamic_cast<const B&>(*a);
+ dynamic_cast<const B&>(*a);
} catch (std::bad_cast&) {
// CHECK: call i8* @llvm.eh.exception
// CHECK: {{call.*llvm.eh.selector.*_ZTISt8bad_cast}}
More information about the cfe-commits
mailing list