r247105 - CodeGen: Add CFI unrelated cast checks to the new pointer code path.

Peter Collingbourne via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 8 17:01:32 PDT 2015


Author: pcc
Date: Tue Sep  8 19:01:31 2015
New Revision: 247105

URL: http://llvm.org/viewvc/llvm-project?rev=247105&view=rev
Log:
CodeGen: Add CFI unrelated cast checks to the new pointer code path.

Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp
    cfe/trunk/test/CodeGenCXX/cfi-cast.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=247105&r1=247104&r2=247105&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Tue Sep  8 19:01:31 2015
@@ -820,6 +820,14 @@ Address CodeGenFunction::EmitPointerWith
                          getNaturalPointeeTypeAlignment(E->getType(), Source));
         }
 
+        if (SanOpts.has(SanitizerKind::CFIUnrelatedCast)) {
+          if (auto PT = E->getType()->getAs<PointerType>())
+            EmitVTablePtrCheckForCast(PT->getPointeeType(), Addr.getPointer(),
+                                      /*MayBeNull=*/true,
+                                      CodeGenFunction::CFITCK_UnrelatedCast,
+                                      CE->getLocStart());
+        }
+
         return Builder.CreateBitCast(Addr, ConvertType(E->getType()));
       }
       break;

Modified: cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cfi-cast.cpp?rev=247105&r1=247104&r2=247105&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cfi-cast.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cfi-cast.cpp Tue Sep  8 19:01:31 2015
@@ -107,3 +107,19 @@ void vcp(void *p) {
   // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1C")
   static_cast<C*>(p);
 }
+
+// CHECK-UCAST-LABEL: define void @_Z3bcpP1B
+// CHECK-UCAST-STRICT-LABEL: define void @_Z3bcpP1B
+void bcp(B *p) {
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1A")
+  // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1C")
+  (C *)p;
+}
+
+// CHECK-UCAST-LABEL: define void @_Z8bcp_callP1B
+// CHECK-UCAST-STRICT-LABEL: define void @_Z8bcp_callP1B
+void bcp_call(B *p) {
+  // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1A")
+  // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"1C")
+  ((C *)p)->f();
+}




More information about the cfe-commits mailing list