r305546 - [ubsan] PR33081: Skip the standard type checks for volatile

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 15 20:27:36 PDT 2017


Author: vedantk
Date: Thu Jun 15 22:27:36 2017
New Revision: 305546

URL: http://llvm.org/viewvc/llvm-project?rev=305546&view=rev
Log:
[ubsan] PR33081: Skip the standard type checks for volatile

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

Added:
    cfe/trunk/test/CodeGen/ubsan-volatile.c
Modified:
    cfe/trunk/lib/CodeGen/CGExpr.cpp

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=305546&r1=305545&r2=305546&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Jun 15 22:27:36 2017
@@ -549,6 +549,11 @@ void CodeGenFunction::EmitTypeCheck(Type
   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;

Added: cfe/trunk/test/CodeGen/ubsan-volatile.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ubsan-volatile.c?rev=305546&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/ubsan-volatile.c (added)
+++ cfe/trunk/test/CodeGen/ubsan-volatile.c Thu Jun 15 22:27:36 2017
@@ -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;
+}




More information about the cfe-commits mailing list