[PATCH] Add a no_sanitize_vptr function attribute.

Arthur O'Dwyer arthur.j.odwyer+phab+github at gmail.com
Thu Apr 16 17:28:12 PDT 2015


================
Comment at: test/CodeGen/no-sanitize-vtpr.cpp:1
@@ +1,2 @@
+// Verify ubsan doesn't emit checks for functions with the no_sanitize_vptr attribute.
+// RUN: %clang_cc1 -fsanitize=vptr -emit-llvm %s -o - | FileCheck %s
----------------
Typo in the name of this test: `vtpr` should be `vptr`.

================
Comment at: test/CodeGen/no-sanitize-vtpr.cpp:17
@@ +16,3 @@
+  // CHECK-NOT: call void @__ubsan_handle_dynamic_type_cache_miss
+  Foo* foo = static_cast<Foo*>(&bar); // down-casting
+  // CHECK: ret void
----------------
If I understand the feature correctly, the idea is that UBSan inserts runtime checks for various undefined behaviors, including the undefined behavior of down-casting `Bar*` to `Foo*` in the case that the original `Bar*` doesn't actually point to an instance of `Foo`.

However, this particular test case is statically detectable as undefined behavior, isn't it? and then on top of that, the assignment is dead and shouldn't really be generating any code at all. I don't think a proper implementation of UBSan would insert any runtime check here (and if the current implementation *does* insert a check here, it's not a proper implementation yet).

A real test case would be something like

```
Foo *testfunc1(Bar *bar) {
  // CHECK: testfunc1
  // CHECK: call void @__ubsan_handle_dynamic_type_cache_miss
  return static_cast<Foo*>(bar); // down-casting
}
__attribute__((no_sanitize_vptr)) Foo *testfunc2(Bar *bar) {
  // CHECK: testfunc2
  // CHECK-NOT: call void @__ubsan_handle_dynamic_type_cache_miss
  return static_cast<Foo*>(bar); // down-casting
}
```

http://reviews.llvm.org/D9059

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list