[compiler-rt] r235567 - [UBSan] Make sure proper error summary is printed for -fsanitize=float-cast-overflow.

Alexey Samsonov vonosmas at gmail.com
Wed Apr 22 18:08:31 PDT 2015


Author: samsonov
Date: Wed Apr 22 20:08:31 2015
New Revision: 235567

URL: http://llvm.org/viewvc/llvm-project?rev=235567&view=rev
Log:
[UBSan] Make sure proper error summary is printed for -fsanitize=float-cast-overflow.

float-cast-overflow handler doesn't have source location provided by the
compiler, but we still have *some* source location if we have a
symbolizer.

Modified:
    compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
    compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp

Modified: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=235567&r1=235566&r2=235567&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc Wed Apr 22 20:08:31 2015
@@ -46,8 +46,7 @@ static void MaybePrintStackTrace(uptr pc
 static void MaybeReportErrorSummary(Location Loc) {
   if (!common_flags()->print_summary)
     return;
-  // Don't try to unwind the stack trace in UBSan summaries: just use the
-  // provided location.
+  const char *ErrorType = "undefined-behavior";
   if (Loc.isSourceLocation()) {
     SourceLocation SLoc = Loc.getSourceLocation();
     if (!SLoc.isInvalid()) {
@@ -56,12 +55,16 @@ static void MaybeReportErrorSummary(Loca
       AI.line = SLoc.getLine();
       AI.column = SLoc.getColumn();
       AI.function = internal_strdup("");  // Avoid printing ?? as function name.
-      ReportErrorSummary("undefined-behavior", AI);
+      ReportErrorSummary(ErrorType, AI);
       AI.Clear();
       return;
     }
+  } else if (Loc.isSymbolizedStack()) {
+    const AddressInfo &AI = Loc.getSymbolizedStack()->info;
+    ReportErrorSummary(ErrorType, AI);
+    return;
   }
-  ReportErrorSummary("undefined-behavior");
+  ReportErrorSummary(ErrorType);
 }
 
 namespace {

Modified: compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp?rev=235567&r1=235566&r2=235567&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/Float/cast-overflow.cpp Wed Apr 22 20:08:31 2015
@@ -1,7 +1,7 @@
 // FIXME: run this (and other) UBSan tests in both 32- and 64-bit modes (?).
-// RUN: %clangxx -fsanitize=float-cast-overflow %s -o %t
+// RUN: %clangxx -fsanitize=float-cast-overflow -g %s -o %t
 // RUN: %run %t _
-// RUN: %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-0
+// RUN: env UBSAN_OPTIONS=print_summary=1 %run %t 0 2>&1 | FileCheck %s --check-prefix=CHECK-0
 // RUN: %run %t 1 2>&1 | FileCheck %s --check-prefix=CHECK-1
 // RUN: %run %t 2 2>&1 | FileCheck %s --check-prefix=CHECK-2
 // RUN: %run %t 3 2>&1 | FileCheck %s --check-prefix=CHECK-3
@@ -85,6 +85,7 @@ int main(int argc, char **argv) {
     // successfully round-trip, depending on the rounding mode.
     // CHECK-0: runtime error: value 2.14748{{.*}} is outside the range of representable values of type 'int'
     static int test_int = MaxFloatRepresentableAsInt + 0x80;
+    // CHECK-0: SUMMARY: {{.*}}Sanitizer: undefined-behavior {{.*}}cast-overflow.cpp:[[@LINE-1]]
     return 0;
     }
   case '1': {





More information about the llvm-commits mailing list