Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -618,6 +618,7 @@ auto PtrToAlloca = dyn_cast(Ptr->stripPointerCastsNoFollowAliases()); + llvm::Value *True = llvm::ConstantInt::getTrue(getLLVMContext()); llvm::Value *IsNonNull = nullptr; bool IsGuaranteedNonNull = SkippedChecks.has(SanitizerKind::Null) || PtrToAlloca; @@ -629,8 +630,7 @@ // The IR builder can constant-fold the null check if the pointer points to // a constant. - IsGuaranteedNonNull = - IsNonNull == llvm::ConstantInt::getTrue(getLLVMContext()); + IsGuaranteedNonNull = IsNonNull == True; // Skip the null check if the pointer is known to be non-null. if (!IsGuaranteedNonNull) { @@ -684,7 +684,8 @@ PtrAsInt, llvm::ConstantInt::get(IntPtrTy, AlignVal - 1)); llvm::Value *Aligned = Builder.CreateICmpEQ(Align, llvm::ConstantInt::get(IntPtrTy, 0)); - Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment)); + if (Aligned != True) + Checks.push_back(std::make_pair(Aligned, SanitizerKind::Alignment)); } } Index: test/CodeGenCXX/ubsan-suppress-checks.cpp =================================================================== --- test/CodeGenCXX/ubsan-suppress-checks.cpp +++ test/CodeGenCXX/ubsan-suppress-checks.cpp @@ -17,6 +17,15 @@ // CHECK: ret void } +// CHECK-LABEL: define void @_Z31use_char_aligned_array_elementsv +void use_char_aligned_array_elements() { + static const char Arr[] = {0, 1, 2}; + char X = Arr[2]; + + // CHECK-NOT: and i64 {{.*}}, !nosanitize + // CHECK: ret void +} + struct A { int foo; @@ -229,4 +238,5 @@ d->load_member_3(); load_non_null_pointers(); + use_char_aligned_array_elements(); }