[PATCH] D34262: [ubsan] PR33081: Skip the standard type checks for volatile

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 15 17:01:16 PDT 2017


vsk created this revision.

Skip checks for null dereference, alignment violation, object size
violation, and dynamic type violation if the pointer points to volatile
data.

https://bugs.llvm.org/show_bug.cgi?id=33081


https://reviews.llvm.org/D34262

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGen/ubsan-volatile.c


Index: test/CodeGen/ubsan-volatile.c
===================================================================
--- /dev/null
+++ test/CodeGen/ubsan-volatile.c
@@ -0,0 +1,11 @@
+// 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() {
+  // CHECK: [[P:%.*]] = alloca i32*
+  // CHECK-NEXT: [[V:%.*]] = load i32*, i32** [[P]]
+  // CHECK-NEXT: load volatile i32, i32* [[V]]
+  // CHECK-NEXT: ret void
+  volatile int *p;
+  *p;
+}
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -549,6 +549,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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34262.102758.patch
Type: text/x-patch
Size: 1044 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170616/98e35111/attachment-0001.bin>


More information about the cfe-commits mailing list