[PATCH] D34299: [ubsan] Improve diagnostics for return value checks (clang)

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 16 15:21:15 PDT 2017


vsk created this revision.

This patch makes ubsan's nonnull return value diagnostics more precise,
which makes the diagnostics more useful when there are multiple return
statements in a function. Example:

  1 |__attribute__((returns_nonnull)) char *foo() {
  2 |  if (...) {
  3 |    return expr_which_might_evaluate_to_null();
  4 |  } else {
  5 |    return another_expr_which_might_evaluate_to_null();
  6 |  }
  7 |} // <- The current diagnostic always points here!
  
  runtime error: Null returned from Line 7, Column 2!

With this patch, the diagnostic would point to either Line 3, Column 5
or Line 5, Column 5.

This is done by emitting source location metadata for each return
statement in a sanitized function. The runtime is passed a pointer to
the appropriate metadata so that it can prepare and deduplicate reports.

Compiler-rt patch (with more tests): https://reviews.llvm.org/D34298


https://reviews.llvm.org/D34299

Files:
  lib/CodeGen/CGCall.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  test/CodeGenObjC/ubsan-nonnull-and-nullability.m
  test/CodeGenObjC/ubsan-nullability.m

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34299.102890.patch
Type: text/x-patch
Size: 10382 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170616/5598d3e2/attachment.bin>


More information about the cfe-commits mailing list