[PATCH] [UBSan] Add returns-nonnull sanitizer.

Richard Smith richard at metafoo.co.uk
Tue Aug 12 15:56:59 PDT 2014

Looks good, a couple of minor comments.

Comment at: projects/compiler-rt/lib/ubsan/ubsan_handlers.cc:319
@@ +318,3 @@
+  Diag(Loc, DL_Error, "null return value where non-null is required");
Maybe "null pointer returned from function declared to never return null"? If we can produce a note pointing at the non-null attribute, that'd be even better.

Comment at: tools/clang/lib/CodeGen/CGCall.cpp:2005
@@ +2004,3 @@
+        CurGD.getDecl()->hasAttr<ReturnsNonNullAttr>() &&
+        RV->getType()->getPointerAddressSpace() == 0) {
+      SanitizerScope SanScope(this);
I don't think you should perform this address space check. LLVM is going to assume the pointer is non-null regardless of address space (see `CodeGenModule::ConstructAttributeList`) so we should sanitize it regardless.


More information about the cfe-commits mailing list