From 434984ef583edf64c13962fa092197410a950369 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Thu, 23 Apr 2015 01:08:31 +0000 Subject: [PATCH] [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. llvm-svn: 235567 --- compiler-rt/lib/ubsan/ubsan_diag.cc | 11 +++++++---- compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/compiler-rt/lib/ubsan/ubsan_diag.cc b/compiler-rt/lib/ubsan/ubsan_diag.cc index 6f76c6a..cdcc0e4 100644 --- a/compiler-rt/lib/ubsan/ubsan_diag.cc +++ b/compiler-rt/lib/ubsan/ubsan_diag.cc @@ -46,8 +46,7 @@ static void MaybePrintStackTrace(uptr pc, uptr bp) { 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(Location Loc) { 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 { diff --git a/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp b/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp index 1193e7b..7fd6ab2 100644 --- a/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp +++ b/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp @@ -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': { -- 2.7.4