[compiler-rt] r217400 - Report source location of returns_nonnull attribute in UBSan reports.

Alexey Samsonov vonosmas at gmail.com
Mon Sep 8 13:17:19 PDT 2014


Author: samsonov
Date: Mon Sep  8 15:17:19 2014
New Revision: 217400

URL: http://llvm.org/viewvc/llvm-project?rev=217400&view=rev
Log:
Report source location of returns_nonnull attribute in UBSan reports.

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
    compiler-rt/trunk/test/ubsan/TestCases/Misc/nonnull.cpp

Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc?rev=217400&r1=217399&r2=217400&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc Mon Sep  8 15:17:19 2014
@@ -340,6 +340,8 @@ static void handleNonNullReturn(NonNullR
 
   Diag(Loc, DL_Error, "null pointer returned from function declared to never "
                       "return null");
+  if (!Data->AttrLoc.isInvalid())
+    Diag(Data->AttrLoc, DL_Note, "returns_nonnull attribute specified here");
 }
 
 void __ubsan::__ubsan_handle_nonnull_return(NonNullReturnData *Data) {

Modified: compiler-rt/trunk/lib/ubsan/ubsan_handlers.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.h?rev=217400&r1=217399&r2=217400&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.h (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.h Mon Sep  8 15:17:19 2014
@@ -125,6 +125,7 @@ RECOVERABLE(function_type_mismatch,
 
 struct NonNullReturnData {
   SourceLocation Loc;
+  SourceLocation AttrLoc;
 };
 
 /// \brief Handle returning null from function with returns_nonnull attribute.

Modified: compiler-rt/trunk/test/ubsan/TestCases/Misc/nonnull.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/Misc/nonnull.cpp?rev=217400&r1=217399&r2=217400&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/Misc/nonnull.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/Misc/nonnull.cpp Mon Sep  8 15:17:19 2014
@@ -2,10 +2,12 @@
 // RUN: %run %t foo
 // RUN: %run %t 2>&1 | FileCheck %s
 
-__attribute__((returns_nonnull))
+__attribute__((returns_nonnull)) char *foo(char *a);
+
 char *foo(char *a) {
   return a;
-  // CHECK: nonnull.cpp:[[@LINE+1]]:1: runtime error: null pointer returned from function declared to never return null
+  // CHECK: nonnull.cpp:[[@LINE+2]]:1: runtime error: null pointer returned from function declared to never return null
+  // CHECK-NEXT: nonnull.cpp:[[@LINE-5]]:16: note: returns_nonnull attribute specified here
 }
 
 int main(int argc, char **argv) {





More information about the llvm-commits mailing list