Diff Detail
Event Timeline
I'm not convinced that adding one attribute per sanitizer is the right design here -- it doesn't seem to scale very well. Have you considered an attribute like
__attribute__((no_sanitize("list,of,sanitizers"))) void fn() { ... }
where the list is parsed as if it were specified as -fno-sanitize=list,of,sanitizers on the command line?
include/clang/Basic/Attr.td | ||
---|---|---|
1406 | UBSan is not usually capitalized this way. | |
include/clang/Basic/AttrDocs.td | ||
965 | Grammar error around "for should". |
test/CodeGen/no-sanitize-vtpr.cpp | ||
---|---|---|
1 | Typo in the name of this test: vtpr should be vptr. | |
17 | 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 } |
This does seem like a much better way of doing this. Should I change this in this patch?
What does everyone else think?
include/clang/Basic/Attr.td | ||
---|---|---|
1406 | Fixed | |
include/clang/Basic/AttrDocs.td | ||
965 | Fixed. | |
test/CodeGen/no-sanitize-vtpr.cpp | ||
1 | Good catch, fixed. | |
17 | I based these tests off an existing test - ubsan-type-blacklist.cpp, which led me to assumed it was OK to assume that these checks will be inserted for those cases. Should I change that too? I've replaced this with something similar to yours (with added CHECK: ret) since call void @__ubsan_handle_dynamic_type_cache_miss gets inserted somewhere after testfunc2 too. |
I agree with this suggestion. It would be cool to have a single attribute like this, and later deprecate no_sanitize_address, no_sanitize_thread and no_sanitize_memory.
I can put together another patch in the next few days, unless someone else (more experienced) wants to take this?
+pcc who also encountered the requirement for this attribute in http://reviews.llvm.org/D6095
UBSan is not usually capitalized this way.