r300371 - [ubsan] Don't check alignment if the alignment is 1
Vedant Kumar via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 14 15:03:37 PDT 2017
Author: vedantk
Date: Fri Apr 14 17:03:37 2017
New Revision: 300371
URL: http://llvm.org/viewvc/llvm-project?rev=300371&view=rev
Log:
[ubsan] Don't check alignment if the alignment is 1
If a pointer is 1-byte aligned, there's no use in checking its
alignment. Somewhat surprisingly, ubsan can spend a significant amount
of time doing just that!
This loosely depends on D30283.
Testing: check-clang, check-ubsan, and a stage2 ubsan build.
Differential Revision: https://reviews.llvm.org/D30285
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=300371&r1=300370&r2=300371&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Apr 14 17:03:37 2017
@@ -599,7 +599,7 @@ void CodeGenFunction::EmitTypeCheck(Type
AlignVal = getContext().getTypeAlignInChars(Ty).getQuantity();
// The glvalue must be suitably aligned.
- if (AlignVal) {
+ if (AlignVal > 1) {
llvm::Value *Align =
Builder.CreateAnd(Builder.CreatePtrToInt(Ptr, IntPtrTy),
llvm::ConstantInt::get(IntPtrTy, AlignVal - 1));
Modified: cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp?rev=300371&r1=300370&r2=300371&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ubsan-suppress-checks.cpp Fri Apr 14 17:03:37 2017
@@ -133,7 +133,7 @@ struct B {
// CHECK: call void @__ubsan_handle_type_mismatch
//
// Check the result of the conversion before using it.
- // CHECK: call void @__ubsan_handle_type_mismatch
+ // NULL: call void @__ubsan_handle_type_mismatch
//
// CHECK-NOT: call void @__ubsan_handle_type_mismatch
B b;
Modified: cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp?rev=300371&r1=300370&r2=300371&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/ubsan-type-checks.cpp Fri Apr 14 17:03:37 2017
@@ -5,8 +5,7 @@
struct A {
// COMMON-LABEL: define linkonce_odr void @_ZN1A10do_nothingEv
void do_nothing() {
- // ALIGN: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
- // ALIGN: and i64 %{{.*}}, 0, !nosanitize
+ // ALIGN-NOT: ptrtoint %struct.A* %{{.*}} to i64, !nosanitize
// NULL: icmp ne %struct.A* %{{.*}}, null, !nosanitize
@@ -14,7 +13,24 @@ struct A {
}
};
+struct B {
+ int x;
+
+ // COMMON-LABEL: define linkonce_odr void @_ZN1B10do_nothingEv
+ void do_nothing() {
+ // ALIGN: ptrtoint %struct.B* %{{.*}} to i64, !nosanitize
+ // ALIGN: and i64 %{{.*}}, 3, !nosanitize
+
+ // NULL: icmp ne %struct.B* %{{.*}}, null, !nosanitize
+
+ // OBJSIZE-NOT: call i64 @llvm.objectsize
+ }
+};
+
void force_irgen() {
A a;
a.do_nothing();
+
+ B b;
+ b.do_nothing();
}
More information about the cfe-commits
mailing list