]> granicus.if.org Git - clang/commitdiff
[ubsan] Mark overflow checks with !nosanitize
authorVedant Kumar <vsk@apple.com>
Tue, 9 May 2017 23:34:49 +0000 (23:34 +0000)
committerVedant Kumar <vsk@apple.com>
Tue, 9 May 2017 23:34:49 +0000 (23:34 +0000)
Sanitizer instrumentation generally needs to be marked with !nosanitize,
but we're not doing this properly for ubsan's overflow checks.

r213291 has more information about why this is needed.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302598 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExprScalar.cpp
test/CodeGen/sanitize-recover.c

index 7462f99a2ae80a5f41a0f6983482dd3771d6ec3f..b8d830ee9f3f0044c6d85573f746c99f00d480d2 100644 (file)
@@ -2552,6 +2552,7 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
   if (isSigned)
     OpID |= 1;
 
+  CodeGenFunction::SanitizerScope SanScope(&CGF);
   llvm::Type *opTy = CGF.CGM.getTypes().ConvertType(Ops.Ty);
 
   llvm::Function *intrinsic = CGF.CGM.getIntrinsic(IID, opTy);
@@ -2567,7 +2568,6 @@ Value *ScalarExprEmitter::EmitOverflowCheckedBinOp(const BinOpInfo &Ops) {
     // If the signed-integer-overflow sanitizer is enabled, emit a call to its
     // runtime. Otherwise, this is a -ftrapv check, so just emit a trap.
     if (!isSigned || CGF.SanOpts.has(SanitizerKind::SignedIntegerOverflow)) {
-      CodeGenFunction::SanitizerScope SanScope(&CGF);
       llvm::Value *NotOverflow = Builder.CreateNot(overflow);
       SanitizerMask Kind = isSigned ? SanitizerKind::SignedIntegerOverflow
                               : SanitizerKind::UnsignedIntegerOverflow;
index d714d58c7f26cc11165f72b1a9c3c6897eefa44a..6358d9d04aa176e11c4497059966de36ef039b7c 100644 (file)
@@ -7,12 +7,12 @@
 void test() {
   extern volatile unsigned x, y, z;
 
-  // RECOVER: uadd.with.overflow.i32
-  // RECOVER: ubsan_handle_add_overflow(
+  // RECOVER: uadd.with.overflow.i32{{.*}}, !nosanitize
+  // RECOVER: ubsan_handle_add_overflow({{.*}}, !nosanitize
   // RECOVER-NOT: unreachable
-  // ABORT: uadd.with.overflow.i32
-  // ABORT: ubsan_handle_add_overflow_abort(
-  // ABORT: unreachable
+  // ABORT: uadd.with.overflow.i32{{.*}}, !nosanitize
+  // ABORT: ubsan_handle_add_overflow_abort({{.*}}, !nosanitize
+  // ABORT: unreachable{{.*}}, !nosanitize
   x = y + z;
 }