[cfe-commits] r166727 - /cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp

Richard Smith richard-llvm at metafoo.co.uk
Thu Oct 25 14:59:46 PDT 2012


Author: rsmith
Date: Thu Oct 25 16:59:45 2012
New Revision: 166727

URL: http://llvm.org/viewvc/llvm-project?rev=166727&view=rev
Log:
Add a more direct test for r166661.

Modified:
    cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp

Modified: cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp?rev=166727&r1=166726&r2=166727&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/catch-undef-behavior.cpp Thu Oct 25 16:59:45 2012
@@ -26,9 +26,7 @@
 
 // CHECK: @_Z13member_access
 void member_access(S *p) {
-  // (1) Check 'p' is appropriately sized and aligned for member access.
-
-  // FIXME: Check vptr is for 'S' or a class derived from 'S'.
+  // (1a) Check 'p' is appropriately sized and aligned for member access.
 
   // CHECK: icmp ne {{.*}}, null
 
@@ -39,6 +37,36 @@
   // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 7
   // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
 
+  // (1b) Check that 'p' actually points to an 'S'.
+
+  // CHECK: %[[VPTRADDR:.*]] = bitcast {{.*}} to i64*
+  // CHECK-NEXT: %[[VPTR:.*]] = load i64* %[[VPTRADDR]]
+  //
+  // hash_16_bytes:
+  //
+  // If this number changes, it indicates that either the mangled name of ::S
+  // has changed, or that LLVM's hashing function has changed. The latter case
+  // is OK if the hashing function is still stable.
+  // CHECK-NEXT: xor i64 -4030275160588942838, %[[VPTR]]
+  // CHECK-NEXT: mul i64 {{.*}}, -7070675565921424023
+  // CHECK-NEXT: lshr i64 {{.*}}, 47
+  // CHECK-NEXT: xor i64
+  // CHECK-NEXT: xor i64 %[[VPTR]]
+  // CHECK-NEXT: mul i64 {{.*}}, -7070675565921424023
+  // CHECK-NEXT: lshr i64 {{.*}}, 47
+  // CHECK-NEXT: xor i64
+  // CHECK-NEXT: %[[HASH:.*]] = mul i64 {{.*}}, -7070675565921424023
+  //
+  // Check the hash against the table:
+  //
+  // CHECK-NEXT: %[[IDX:.*]] = and i64 %{{.*}}, 127
+  // CHECK-NEXT: getelementptr inbounds [128 x i64]* @__ubsan_vptr_type_cache, i32 0, i64 %[[IDX]]
+  // CHECK-NEXT: %[[CACHEVAL:.*]] = load i64*
+  // CHECK-NEXT: icmp eq i64 %[[CACHEVAL]], %[[HASH]]
+  // CHECK-NEXT: br i1
+
+  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss({{.*}}, i64 %{{.*}}, i64 %[[HASH]])
+
   // (2) Check 'p->b' is appropriately sized and aligned for a load.
 
   // FIXME: Suppress this in the trivial case of a member access, because we
@@ -52,9 +80,7 @@
   // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
   int k = p->b;
 
-  // (3) Check 'p' is appropriately sized and aligned for member function call.
-
-  // FIXME: Check vptr is for 'S' or a class derived from 'S'.
+  // (3a) Check 'p' is appropriately sized and aligned for member function call.
 
   // CHECK: icmp ne {{.*}}, null
 
@@ -64,6 +90,16 @@
   // CHECK: %[[PTRINT:.*]] = ptrtoint
   // CHECK-NEXT: %[[MISALIGN:.*]] = and i64 %[[PTRINT]], 7
   // CHECK-NEXT: icmp eq i64 %[[MISALIGN]], 0
+
+  // (3b) Check that 'p' actually points to an 'S'
+
+  // CHECK: load i64*
+  // CHECK-NEXT: xor i64 -4030275160588942838,
+  // [...]
+  // CHECK: getelementptr inbounds [128 x i64]* @__ubsan_vptr_type_cache, i32 0, i64 %
+  // CHECK: br i1
+  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss({{.*}}, i64 %{{.*}}, i64 %{{.*}})
+
   k = p->f();
 }
 





More information about the cfe-commits mailing list