]> granicus.if.org Git - clang/commitdiff
[MS ABI] Tolerate invokes of __RTDynamicCast
authorDavid Majnemer <david.majnemer@gmail.com>
Mon, 23 Nov 2015 03:01:14 +0000 (03:01 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Mon, 23 Nov 2015 03:01:14 +0000 (03:01 +0000)
The pointer returned by __RTDynamicCast must be bitcasted.  However, it
was not expected that __RTDynamicCast would be invoked, resulting in the
bitcast occuring in a different BasicBlock than the invoke.  This caused
a down-stream PHI to get confused about which BasicBlock the incomming
value was from.

This fixes PR25606.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253843 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprCXX.cpp
test/CodeGenCXX/microsoft-abi-dynamic-cast.cpp

index 6565f8346fa1f8c060f4cf5da32f5fb16b742232..604cde76a7b1d161ce774242f8ba00277aac3c0e 100644 (file)
@@ -1904,6 +1904,7 @@ llvm::Value *CodeGenFunction::EmitDynamicCast(Address ThisAddr,
            "destination type must be a record type!");
     Value = CGM.getCXXABI().EmitDynamicCastCall(*this, ThisAddr, SrcRecordTy,
                                                 DestTy, DestRecordTy, CastEnd);
+    CastNotNull = Builder.GetInsertBlock();
   }
 
   if (ShouldNullCheckSrcValue) {
index 49ba9500e9492c263d1d8e9e2f681025ed561865..e9eba6ed0b209f44aa4a73b814b3b34cd6f16fe0 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -O1 -o - -triple=i386-pc-win32 %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O1 -o - -fexceptions -triple=i386-pc-win32 %s | FileCheck %s
 
 struct S { char a; };
 struct V { virtual void f(); };
@@ -122,3 +122,22 @@ void* test9(B* x) { return dynamic_cast<void*>(x); }
 // CHECK:        [[RET:%.*]] = phi i8*
 // CHECK-NEXT:   ret i8* [[RET]]
 
+namespace PR25606 {
+struct Cleanup {
+  ~Cleanup();
+};
+struct S1 { virtual ~S1(); };
+struct S2 : virtual S1 {};
+struct S3 : S2 {};
+
+S3 *f(S2 &s) {
+  Cleanup c;
+  return dynamic_cast<S3 *>(&s);
+}
+// CHECK-LABEL: define %"struct.PR25606::S3"* @"\01?f@PR25606@@YAPAUS3@1@AAUS2@1@@Z"(
+// CHECK:    [[CALL:%.*]] = invoke i8* @__RTDynamicCast
+
+// CHECK:    [[BC:%.*]] = bitcast i8* [[CALL]] to %"struct.PR25606::S3"*
+// CHECK:    call x86_thiscallcc void @"\01??_DCleanup@PR25606@@QAE@XZ"(
+// CHECK:    ret %"struct.PR25606::S3"* [[BC]]
+}