summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CGExpr.cpp2
-rw-r--r--clang/test/CodeGenCXX/ubsan-suppress-checks.cpp2
-rw-r--r--clang/test/CodeGenCXX/ubsan-type-checks.cpp20
3 files changed, 20 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 428c8ffd2a1..265ef27a46b 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -599,7 +599,7 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
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));
diff --git a/clang/test/CodeGenCXX/ubsan-suppress-checks.cpp b/clang/test/CodeGenCXX/ubsan-suppress-checks.cpp
index 6ad417e211d..8ec94556c13 100644
--- a/clang/test/CodeGenCXX/ubsan-suppress-checks.cpp
+++ b/clang/test/CodeGenCXX/ubsan-suppress-checks.cpp
@@ -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;
diff --git a/clang/test/CodeGenCXX/ubsan-type-checks.cpp b/clang/test/CodeGenCXX/ubsan-type-checks.cpp
index 150b2fc40c2..786d049dfb5 100644
--- a/clang/test/CodeGenCXX/ubsan-type-checks.cpp
+++ b/clang/test/CodeGenCXX/ubsan-type-checks.cpp
@@ -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();
}
OpenPOWER on IntegriCloud