]> granicus.if.org Git - clang/commitdiff
[ubsan] PR33081: Skip the standard type checks for volatile
authorVedant Kumar <vsk@apple.com>
Fri, 16 Jun 2017 03:27:36 +0000 (03:27 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 16 Jun 2017 03:27:36 +0000 (03:27 +0000)
Skip checks for null dereference, alignment violation, object size
violation, and dynamic type violation if the pointer points to volatile
data.

Differential Revision: https://reviews.llvm.org/D34262

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

lib/CodeGen/CGExpr.cpp
test/CodeGen/ubsan-volatile.c [new file with mode: 0644]

index 15829888ead9c5bb8081075e066896c488b0d8be..7359006677f420efc5449bcaf2c97eee0fe0a743 100644 (file)
@@ -549,6 +549,11 @@ void CodeGenFunction::EmitTypeCheck(TypeCheckKind TCK, SourceLocation Loc,
   if (Ptr->getType()->getPointerAddressSpace())
     return;
 
+  // Don't check pointers to volatile data. The behavior here is implementation-
+  // defined.
+  if (Ty.isVolatileQualified())
+    return;
+
   SanitizerScope SanScope(this);
 
   SmallVector<std::pair<llvm::Value *, SanitizerMask>, 3> Checks;
diff --git a/test/CodeGen/ubsan-volatile.c b/test/CodeGen/ubsan-volatile.c
new file mode 100644 (file)
index 0000000..ce54aad
--- /dev/null
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsanitize=null,alignment,object-size,vptr -S -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @volatile_null_deref
+void volatile_null_deref(volatile int *p) {
+  // CHECK-NOT: call{{.*}}ubsan
+  *p;
+}