Merge remote-tracking branch 'origin/swift-4.0-branch' into stable
diff --git a/lib/CodeGen/CGExpr.cpp b/lib/CodeGen/CGExpr.cpp
index e46fe21..f7e4272 100644
--- a/lib/CodeGen/CGExpr.cpp
+++ b/lib/CodeGen/CGExpr.cpp
@@ -545,6 +545,11 @@
   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
index 0000000..ce54aad
--- /dev/null
+++ b/test/CodeGen/ubsan-volatile.c
@@ -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;
+}