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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits