r257738 - CodeGen: Only emit CFI unrelated cast checks for bit casts.
Peter Collingbourne via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 13 18:49:49 PST 2016
Author: pcc
Date: Wed Jan 13 20:49:48 2016
New Revision: 257738
URL: http://llvm.org/viewvc/llvm-project?rev=257738&view=rev
Log:
CodeGen: Only emit CFI unrelated cast checks for bit casts.
We were previously emitting them for no-op casts (e.g. implicit casts
to const).
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=257738&r1=257737&r2=257738&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Wed Jan 13 20:49:48 2016
@@ -824,7 +824,8 @@ Address CodeGenFunction::EmitPointerWith
getNaturalPointeeTypeAlignment(E->getType(), Source));
}
- if (SanOpts.has(SanitizerKind::CFIUnrelatedCast)) {
+ if (SanOpts.has(SanitizerKind::CFIUnrelatedCast) &&
+ CE->getCastKind() == CK_BitCast) {
if (auto PT = E->getType()->getAs<PointerType>())
EmitVTablePtrCheckForCast(PT->getPointeeType(), Addr.getPointer(),
/*MayBeNull=*/true,
Modified: cfe/trunk/test/CodeGenCXX/cfi-cast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/cfi-cast.cpp?rev=257738&r1=257737&r2=257738&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/cfi-cast.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/cfi-cast.cpp Wed Jan 13 20:49:48 2016
@@ -8,6 +8,7 @@
struct A {
virtual void f();
+ int i() const;
};
struct B : A {
@@ -103,23 +104,31 @@ void vbrr(char &&r) {
// CHECK-UCAST-LABEL: define void @_Z3vcpPv
// CHECK-UCAST-STRICT-LABEL: define void @_Z3vcpPv
void vcp(void *p) {
- // CHECK-UCAST: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
- // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
+ // CHECK-UCAST: call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
+ // CHECK-UCAST-STRICT: call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
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 !"_ZTS1A")
- // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
+ // CHECK-UCAST: call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
+ // CHECK-UCAST-STRICT: call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
(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 !"_ZTS1A")
- // CHECK-UCAST-STRICT: [[P:%[^ ]*]] = call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
+ // CHECK-UCAST: call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1A")
+ // CHECK-UCAST-STRICT: call i1 @llvm.bitset.test(i8* {{%[^ ]*}}, metadata !"_ZTS1C")
((C *)p)->f();
}
+
+// CHECK-UCAST-LABEL: define i32 @_Z6a_callP1A
+// CHECK-UCAST-STRICT-LABEL: define i32 @_Z6a_callP1A
+int a_call(A *a) {
+ // CHECK-UCAST-NOT: @llvm.bitset.test
+ // CHECK-UCAST-STRICT-NOT: @llvm.bitset.test
+ return a->i();
+}
More information about the cfe-commits
mailing list