]> granicus.if.org Git - clang/commitdiff
Fix regression I introduced when dynamic_cast-ing to a reference type.
authorAnders Carlsson <andersca@mac.com>
Fri, 18 Dec 2009 14:55:04 +0000 (14:55 +0000)
committerAnders Carlsson <andersca@mac.com>
Fri, 18 Dec 2009 14:55:04 +0000 (14:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@91687 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprCXX.cpp
test/CodeGenCXX/dynamic-cast.cpp [new file with mode: 0644]

index 6a3b8bf3c0385982abdaef819de01e397d9b57c7..bfdff985cf33db1abefc2dae97ca78c2ab680a14 100644 (file)
@@ -501,7 +501,7 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(llvm::Value *V,
     SrcTy = SrcTy->getPointeeType();
   SrcTy = SrcTy.getUnqualifiedType();
 
-  if (DestTy->isPointerType())
+  if (DestTy->isPointerType() || DestTy->isReferenceType())
     DestTy = DestTy->getPointeeType();
   DestTy = DestTy.getUnqualifiedType();
 
diff --git a/test/CodeGenCXX/dynamic-cast.cpp b/test/CodeGenCXX/dynamic-cast.cpp
new file mode 100644 (file)
index 0000000..aeb2a64
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 %s -emit-llvm-only
+
+struct A { virtual void f(); };
+struct B : A { };
+
+const B& f(A *a) {
+  return dynamic_cast<const B&>(*a);
+}