[compiler-rt] r367452 - compiler-rt: Rename .cc files in lib/ubsan to .cpp.

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 31 10:51:05 PDT 2019


Author: nico
Date: Wed Jul 31 10:51:05 2019
New Revision: 367452

URL: http://llvm.org/viewvc/llvm-project?rev=367452&view=rev
Log:
compiler-rt: Rename .cc files in lib/ubsan to .cpp.

See https://reviews.llvm.org/D58620 for discussion, and for the commands
I ran. In addition I also ran

  for f in $(svn diff | diffstat | grep .cc | cut -f 2 -d ' '); do rg $f . ; done

and manually updated references to renamed files found by that.

Added:
    compiler-rt/trunk/lib/ubsan/ubsan_diag.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
    compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_flags.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_init.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc
    compiler-rt/trunk/lib/ubsan/ubsan_monitor.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc
    compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc
    compiler-rt/trunk/lib/ubsan/ubsan_value.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_value.cc
    compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc
    compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc
    compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cpp
      - copied, changed from r367451, compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc
Removed:
    compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
    compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
    compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc
    compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc
    compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc
    compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc
    compiler-rt/trunk/lib/ubsan/ubsan_value.cc
    compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc
    compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc
    compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc
Modified:
    compiler-rt/trunk/lib/ubsan/CMakeLists.txt
    compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp

Modified: compiler-rt/trunk/lib/ubsan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/CMakeLists.txt?rev=367452&r1=367451&r2=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/ubsan/CMakeLists.txt Wed Jul 31 10:51:05 2019
@@ -1,25 +1,25 @@
 # Build for the undefined behavior sanitizer runtime support library.
 
 set(UBSAN_SOURCES
-  ubsan_diag.cc
-  ubsan_init.cc
-  ubsan_flags.cc
-  ubsan_handlers.cc
-  ubsan_monitor.cc
-  ubsan_value.cc
+  ubsan_diag.cpp
+  ubsan_init.cpp
+  ubsan_flags.cpp
+  ubsan_handlers.cpp
+  ubsan_monitor.cpp
+  ubsan_value.cpp
   )
 
 set(UBSAN_STANDALONE_SOURCES
-  ubsan_diag_standalone.cc
-  ubsan_init_standalone.cc
-  ubsan_signals_standalone.cc
+  ubsan_diag_standalone.cpp
+  ubsan_init_standalone.cpp
+  ubsan_signals_standalone.cpp
   )
 
 set(UBSAN_CXXABI_SOURCES
-  ubsan_handlers_cxx.cc
-  ubsan_type_hash.cc
-  ubsan_type_hash_itanium.cc
-  ubsan_type_hash_win.cc
+  ubsan_handlers_cxx.cpp
+  ubsan_type_hash.cpp
+  ubsan_type_hash_itanium.cpp
+  ubsan_type_hash_win.cpp
  )
 
 set(UBSAN_HEADERS
@@ -129,8 +129,8 @@ else()
     set(UBSAN_CXX_SOURCES ${UBSAN_CXXABI_SOURCES})
   else()
     # Dummy target if we don't have C++ ABI library.
-    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cc "")
-    set(UBSAN_CXX_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cc)
+    file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cpp "")
+    set(UBSAN_CXX_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/cxx_dummy.cpp)
   endif()
 
   add_compiler_rt_object_libraries(RTUbsan_cxx
@@ -143,14 +143,14 @@ else()
     add_compiler_rt_object_libraries(UbsanWeakInterception
       ${SANITIZER_COMMON_SUPPORTED_OS}
       ARCHS ${UBSAN_SUPPORTED_ARCH}
-      SOURCES ubsan_win_weak_interception.cc
+      SOURCES ubsan_win_weak_interception.cpp
       CFLAGS ${UBSAN_CFLAGS} -DSANITIZER_DYNAMIC
       DEFS ${UBSAN_COMMON_DEFINITIONS})
 
     add_compiler_rt_object_libraries(UbsanDllThunk
       ${SANITIZER_COMMON_SUPPORTED_OS}
       ARCHS ${UBSAN_SUPPORTED_ARCH}
-      SOURCES ubsan_win_dll_thunk.cc
+      SOURCES ubsan_win_dll_thunk.cpp
       CFLAGS ${UBSAN_CFLAGS} -DSANITIZER_DLL_THUNK
       DEFS ${UBSAN_COMMON_DEFINITIONS})
 
@@ -163,7 +163,7 @@ else()
     add_compiler_rt_object_libraries(UbsanDynamicRuntimeThunk
       ${SANITIZER_COMMON_SUPPORTED_OS}
       ARCHS ${UBSAN_SUPPORTED_ARCH}
-      SOURCES ubsan_win_dynamic_runtime_thunk.cc
+      SOURCES ubsan_win_dynamic_runtime_thunk.cpp
       CFLAGS ${UBSAN_CFLAGS} ${DYNAMIC_RUNTIME_THUNK_CFLAGS}
       DEFS ${UBSAN_COMMON_DEFINITIONS})
   endif()
@@ -179,7 +179,7 @@ else()
     add_compiler_rt_runtime(clang_rt.ubsan_standalone
       STATIC
       ARCHS ${UBSAN_SUPPORTED_ARCH}
-      SOURCES ubsan_init_standalone_preinit.cc
+      SOURCES ubsan_init_standalone_preinit.cpp
       ADDITIONAL_HEADERS ${UBSAN_HEADERS}
       OBJECT_LIBS RTSanitizerCommon
               RTSanitizerCommonLibc

Removed: compiler-rt/trunk/lib/ubsan/ubsan_diag.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (removed)
@@ -1,443 +0,0 @@
-//===-- ubsan_diag.cc -----------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Diagnostic reporting for the UBSan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_diag.h"
-#include "ubsan_init.h"
-#include "ubsan_flags.h"
-#include "ubsan_monitor.h"
-#include "sanitizer_common/sanitizer_placement_new.h"
-#include "sanitizer_common/sanitizer_report_decorator.h"
-#include "sanitizer_common/sanitizer_stacktrace.h"
-#include "sanitizer_common/sanitizer_stacktrace_printer.h"
-#include "sanitizer_common/sanitizer_suppressions.h"
-#include "sanitizer_common/sanitizer_symbolizer.h"
-#include <stdio.h>
-
-using namespace __ubsan;
-
-// UBSan is combined with runtimes that already provide this functionality
-// (e.g., ASan) as well as runtimes that lack it (e.g., scudo). Tried to use
-// weak linkage to resolve this issue which is not portable and breaks on
-// Windows.
-// TODO(yln): This is a temporary workaround. GetStackTrace functions will be
-// removed in the future.
-void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth,
-                         uptr pc, uptr bp, void *context, bool fast) {
-  uptr top = 0;
-  uptr bottom = 0;
-  if (StackTrace::WillUseFastUnwind(fast)) {
-    GetThreadStackTopAndBottom(false, &top, &bottom);
-    stack->Unwind(max_depth, pc, bp, nullptr, top, bottom, true);
-  } else
-    stack->Unwind(max_depth, pc, bp, context, 0, 0, false);
-}
-
-static void MaybePrintStackTrace(uptr pc, uptr bp) {
-  // We assume that flags are already parsed, as UBSan runtime
-  // will definitely be called when we print the first diagnostics message.
-  if (!flags()->print_stacktrace)
-    return;
-
-  BufferedStackTrace stack;
-  ubsan_GetStackTrace(&stack, kStackTraceMax, pc, bp, nullptr,
-                common_flags()->fast_unwind_on_fatal);
-  stack.Print();
-}
-
-static const char *ConvertTypeToString(ErrorType Type) {
-  switch (Type) {
-#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName)                      \
-  case ErrorType::Name:                                                        \
-    return SummaryKind;
-#include "ubsan_checks.inc"
-#undef UBSAN_CHECK
-  }
-  UNREACHABLE("unknown ErrorType!");
-}
-
-static const char *ConvertTypeToFlagName(ErrorType Type) {
-  switch (Type) {
-#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName)                      \
-  case ErrorType::Name:                                                        \
-    return FSanitizeFlagName;
-#include "ubsan_checks.inc"
-#undef UBSAN_CHECK
-  }
-  UNREACHABLE("unknown ErrorType!");
-}
-
-static void MaybeReportErrorSummary(Location Loc, ErrorType Type) {
-  if (!common_flags()->print_summary)
-    return;
-  if (!flags()->report_error_type)
-    Type = ErrorType::GenericUB;
-  const char *ErrorKind = ConvertTypeToString(Type);
-  if (Loc.isSourceLocation()) {
-    SourceLocation SLoc = Loc.getSourceLocation();
-    if (!SLoc.isInvalid()) {
-      AddressInfo AI;
-      AI.file = internal_strdup(SLoc.getFilename());
-      AI.line = SLoc.getLine();
-      AI.column = SLoc.getColumn();
-      AI.function = internal_strdup("");  // Avoid printing ?? as function name.
-      ReportErrorSummary(ErrorKind, AI, GetSanititizerToolName());
-      AI.Clear();
-      return;
-    }
-  } else if (Loc.isSymbolizedStack()) {
-    const AddressInfo &AI = Loc.getSymbolizedStack()->info;
-    ReportErrorSummary(ErrorKind, AI, GetSanititizerToolName());
-    return;
-  }
-  ReportErrorSummary(ErrorKind, GetSanititizerToolName());
-}
-
-namespace {
-class Decorator : public SanitizerCommonDecorator {
- public:
-  Decorator() : SanitizerCommonDecorator() {}
-  const char *Highlight() const { return Green(); }
-  const char *Note() const { return Black(); }
-};
-}
-
-SymbolizedStack *__ubsan::getSymbolizedLocation(uptr PC) {
-  InitAsStandaloneIfNecessary();
-  return Symbolizer::GetOrInit()->SymbolizePC(PC);
-}
-
-Diag &Diag::operator<<(const TypeDescriptor &V) {
-  return AddArg(V.getTypeName());
-}
-
-Diag &Diag::operator<<(const Value &V) {
-  if (V.getType().isSignedIntegerTy())
-    AddArg(V.getSIntValue());
-  else if (V.getType().isUnsignedIntegerTy())
-    AddArg(V.getUIntValue());
-  else if (V.getType().isFloatTy())
-    AddArg(V.getFloatValue());
-  else
-    AddArg("<unknown>");
-  return *this;
-}
-
-/// Hexadecimal printing for numbers too large for Printf to handle directly.
-static void RenderHex(InternalScopedString *Buffer, UIntMax Val) {
-#if HAVE_INT128_T
-  Buffer->append("0x%08x%08x%08x%08x", (unsigned int)(Val >> 96),
-                 (unsigned int)(Val >> 64), (unsigned int)(Val >> 32),
-                 (unsigned int)(Val));
-#else
-  UNREACHABLE("long long smaller than 64 bits?");
-#endif
-}
-
-static void RenderLocation(InternalScopedString *Buffer, Location Loc) {
-  switch (Loc.getKind()) {
-  case Location::LK_Source: {
-    SourceLocation SLoc = Loc.getSourceLocation();
-    if (SLoc.isInvalid())
-      Buffer->append("<unknown>");
-    else
-      RenderSourceLocation(Buffer, SLoc.getFilename(), SLoc.getLine(),
-                           SLoc.getColumn(), common_flags()->symbolize_vs_style,
-                           common_flags()->strip_path_prefix);
-    return;
-  }
-  case Location::LK_Memory:
-    Buffer->append("%p", Loc.getMemoryLocation());
-    return;
-  case Location::LK_Symbolized: {
-    const AddressInfo &Info = Loc.getSymbolizedStack()->info;
-    if (Info.file)
-      RenderSourceLocation(Buffer, Info.file, Info.line, Info.column,
-                           common_flags()->symbolize_vs_style,
-                           common_flags()->strip_path_prefix);
-    else if (Info.module)
-      RenderModuleLocation(Buffer, Info.module, Info.module_offset,
-                           Info.module_arch, common_flags()->strip_path_prefix);
-    else
-      Buffer->append("%p", Info.address);
-    return;
-  }
-  case Location::LK_Null:
-    Buffer->append("<unknown>");
-    return;
-  }
-}
-
-static void RenderText(InternalScopedString *Buffer, const char *Message,
-                       const Diag::Arg *Args) {
-  for (const char *Msg = Message; *Msg; ++Msg) {
-    if (*Msg != '%') {
-      Buffer->append("%c", *Msg);
-      continue;
-    }
-    const Diag::Arg &A = Args[*++Msg - '0'];
-    switch (A.Kind) {
-    case Diag::AK_String:
-      Buffer->append("%s", A.String);
-      break;
-    case Diag::AK_TypeName: {
-      if (SANITIZER_WINDOWS)
-        // The Windows implementation demangles names early.
-        Buffer->append("'%s'", A.String);
-      else
-        Buffer->append("'%s'", Symbolizer::GetOrInit()->Demangle(A.String));
-      break;
-    }
-    case Diag::AK_SInt:
-      // 'long long' is guaranteed to be at least 64 bits wide.
-      if (A.SInt >= INT64_MIN && A.SInt <= INT64_MAX)
-        Buffer->append("%lld", (long long)A.SInt);
-      else
-        RenderHex(Buffer, A.SInt);
-      break;
-    case Diag::AK_UInt:
-      if (A.UInt <= UINT64_MAX)
-        Buffer->append("%llu", (unsigned long long)A.UInt);
-      else
-        RenderHex(Buffer, A.UInt);
-      break;
-    case Diag::AK_Float: {
-      // FIXME: Support floating-point formatting in sanitizer_common's
-      //        printf, and stop using snprintf here.
-      char FloatBuffer[32];
-#if SANITIZER_WINDOWS
-      sprintf_s(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
-#else
-      snprintf(FloatBuffer, sizeof(FloatBuffer), "%Lg", (long double)A.Float);
-#endif
-      Buffer->append("%s", FloatBuffer);
-      break;
-    }
-    case Diag::AK_Pointer:
-      Buffer->append("%p", A.Pointer);
-      break;
-    }
-  }
-}
-
-/// Find the earliest-starting range in Ranges which ends after Loc.
-static Range *upperBound(MemoryLocation Loc, Range *Ranges,
-                         unsigned NumRanges) {
-  Range *Best = 0;
-  for (unsigned I = 0; I != NumRanges; ++I)
-    if (Ranges[I].getEnd().getMemoryLocation() > Loc &&
-        (!Best ||
-         Best->getStart().getMemoryLocation() >
-         Ranges[I].getStart().getMemoryLocation()))
-      Best = &Ranges[I];
-  return Best;
-}
-
-static inline uptr subtractNoOverflow(uptr LHS, uptr RHS) {
-  return (LHS < RHS) ? 0 : LHS - RHS;
-}
-
-static inline uptr addNoOverflow(uptr LHS, uptr RHS) {
-  const uptr Limit = (uptr)-1;
-  return (LHS > Limit - RHS) ? Limit : LHS + RHS;
-}
-
-/// Render a snippet of the address space near a location.
-static void PrintMemorySnippet(const Decorator &Decor, MemoryLocation Loc,
-                               Range *Ranges, unsigned NumRanges,
-                               const Diag::Arg *Args) {
-  // Show at least the 8 bytes surrounding Loc.
-  const unsigned MinBytesNearLoc = 4;
-  MemoryLocation Min = subtractNoOverflow(Loc, MinBytesNearLoc);
-  MemoryLocation Max = addNoOverflow(Loc, MinBytesNearLoc);
-  MemoryLocation OrigMin = Min;
-  for (unsigned I = 0; I < NumRanges; ++I) {
-    Min = __sanitizer::Min(Ranges[I].getStart().getMemoryLocation(), Min);
-    Max = __sanitizer::Max(Ranges[I].getEnd().getMemoryLocation(), Max);
-  }
-
-  // If we have too many interesting bytes, prefer to show bytes after Loc.
-  const unsigned BytesToShow = 32;
-  if (Max - Min > BytesToShow)
-    Min = __sanitizer::Min(Max - BytesToShow, OrigMin);
-  Max = addNoOverflow(Min, BytesToShow);
-
-  if (!IsAccessibleMemoryRange(Min, Max - Min)) {
-    Printf("<memory cannot be printed>\n");
-    return;
-  }
-
-  // Emit data.
-  InternalScopedString Buffer(1024);
-  for (uptr P = Min; P != Max; ++P) {
-    unsigned char C = *reinterpret_cast<const unsigned char*>(P);
-    Buffer.append("%s%02x", (P % 8 == 0) ? "  " : " ", C);
-  }
-  Buffer.append("\n");
-
-  // Emit highlights.
-  Buffer.append(Decor.Highlight());
-  Range *InRange = upperBound(Min, Ranges, NumRanges);
-  for (uptr P = Min; P != Max; ++P) {
-    char Pad = ' ', Byte = ' ';
-    if (InRange && InRange->getEnd().getMemoryLocation() == P)
-      InRange = upperBound(P, Ranges, NumRanges);
-    if (!InRange && P > Loc)
-      break;
-    if (InRange && InRange->getStart().getMemoryLocation() < P)
-      Pad = '~';
-    if (InRange && InRange->getStart().getMemoryLocation() <= P)
-      Byte = '~';
-    if (P % 8 == 0)
-      Buffer.append("%c", Pad);
-    Buffer.append("%c", Pad);
-    Buffer.append("%c", P == Loc ? '^' : Byte);
-    Buffer.append("%c", Byte);
-  }
-  Buffer.append("%s\n", Decor.Default());
-
-  // Go over the line again, and print names for the ranges.
-  InRange = 0;
-  unsigned Spaces = 0;
-  for (uptr P = Min; P != Max; ++P) {
-    if (!InRange || InRange->getEnd().getMemoryLocation() == P)
-      InRange = upperBound(P, Ranges, NumRanges);
-    if (!InRange)
-      break;
-
-    Spaces += (P % 8) == 0 ? 2 : 1;
-
-    if (InRange && InRange->getStart().getMemoryLocation() == P) {
-      while (Spaces--)
-        Buffer.append(" ");
-      RenderText(&Buffer, InRange->getText(), Args);
-      Buffer.append("\n");
-      // FIXME: We only support naming one range for now!
-      break;
-    }
-
-    Spaces += 2;
-  }
-
-  Printf("%s", Buffer.data());
-  // FIXME: Print names for anything we can identify within the line:
-  //
-  //  * If we can identify the memory itself as belonging to a particular
-  //    global, stack variable, or dynamic allocation, then do so.
-  //
-  //  * If we have a pointer-size, pointer-aligned range highlighted,
-  //    determine whether the value of that range is a pointer to an
-  //    entity which we can name, and if so, print that name.
-  //
-  // This needs an external symbolizer, or (preferably) ASan instrumentation.
-}
-
-Diag::~Diag() {
-  // All diagnostics should be printed under report mutex.
-  ScopedReport::CheckLocked();
-  Decorator Decor;
-  InternalScopedString Buffer(1024);
-
-  // Prepare a report that a monitor process can inspect.
-  if (Level == DL_Error) {
-    RenderText(&Buffer, Message, Args);
-    UndefinedBehaviorReport UBR{ConvertTypeToString(ET), Loc, Buffer};
-    Buffer.clear();
-  }
-
-  Buffer.append(Decor.Bold());
-  RenderLocation(&Buffer, Loc);
-  Buffer.append(":");
-
-  switch (Level) {
-  case DL_Error:
-    Buffer.append("%s runtime error: %s%s", Decor.Warning(), Decor.Default(),
-                  Decor.Bold());
-    break;
-
-  case DL_Note:
-    Buffer.append("%s note: %s", Decor.Note(), Decor.Default());
-    break;
-  }
-
-  RenderText(&Buffer, Message, Args);
-
-  Buffer.append("%s\n", Decor.Default());
-  Printf("%s", Buffer.data());
-
-  if (Loc.isMemoryLocation())
-    PrintMemorySnippet(Decor, Loc.getMemoryLocation(), Ranges, NumRanges, Args);
-}
-
-ScopedReport::Initializer::Initializer() { InitAsStandaloneIfNecessary(); }
-
-ScopedReport::ScopedReport(ReportOptions Opts, Location SummaryLoc,
-                           ErrorType Type)
-    : Opts(Opts), SummaryLoc(SummaryLoc), Type(Type) {}
-
-ScopedReport::~ScopedReport() {
-  MaybePrintStackTrace(Opts.pc, Opts.bp);
-  MaybeReportErrorSummary(SummaryLoc, Type);
-  if (flags()->halt_on_error)
-    Die();
-}
-
-ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
-static SuppressionContext *suppression_ctx = nullptr;
-static const char kVptrCheck[] = "vptr_check";
-static const char *kSuppressionTypes[] = {
-#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName) FSanitizeFlagName,
-#include "ubsan_checks.inc"
-#undef UBSAN_CHECK
-    kVptrCheck,
-};
-
-void __ubsan::InitializeSuppressions() {
-  CHECK_EQ(nullptr, suppression_ctx);
-  suppression_ctx = new (suppression_placeholder) // NOLINT
-      SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
-  suppression_ctx->ParseFromFile(flags()->suppressions);
-}
-
-bool __ubsan::IsVptrCheckSuppressed(const char *TypeName) {
-  InitAsStandaloneIfNecessary();
-  CHECK(suppression_ctx);
-  Suppression *s;
-  return suppression_ctx->Match(TypeName, kVptrCheck, &s);
-}
-
-bool __ubsan::IsPCSuppressed(ErrorType ET, uptr PC, const char *Filename) {
-  InitAsStandaloneIfNecessary();
-  CHECK(suppression_ctx);
-  const char *SuppType = ConvertTypeToFlagName(ET);
-  // Fast path: don't symbolize PC if there is no suppressions for given UB
-  // type.
-  if (!suppression_ctx->HasSuppressionType(SuppType))
-    return false;
-  Suppression *s = nullptr;
-  // Suppress by file name known to runtime.
-  if (Filename != nullptr && suppression_ctx->Match(Filename, SuppType, &s))
-    return true;
-  // Suppress by module name.
-  if (const char *Module = Symbolizer::GetOrInit()->GetModuleNameForPc(PC)) {
-    if (suppression_ctx->Match(Module, SuppType, &s))
-      return true;
-  }
-  // Suppress by function or source file name from debug info.
-  SymbolizedStackHolder Stack(Symbolizer::GetOrInit()->SymbolizePC(PC));
-  const AddressInfo &AI = Stack.get()->info;
-  return suppression_ctx->Match(AI.function, SuppType, &s) ||
-         suppression_ctx->Match(AI.file, SuppType, &s);
-}
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_diag.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_diag.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_diag.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_diag.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_diag.cc -----------------------------------------------------===//
+//===-- ubsan_diag.cpp ----------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc (removed)
@@ -1,40 +0,0 @@
-//===-- ubsan_diag_standalone.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Diagnostic reporting for the standalone UBSan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_diag.h"
-
-using namespace __ubsan;
-
-void __sanitizer::BufferedStackTrace::UnwindImpl(
-    uptr pc, uptr bp, void *context, bool request_fast, u32 max_depth) {
-  uptr top = 0;
-  uptr bottom = 0;
-  if (StackTrace::WillUseFastUnwind(request_fast)) {
-    GetThreadStackTopAndBottom(false, &top, &bottom);
-    Unwind(max_depth, pc, bp, nullptr, top, bottom, true);
-  } else
-    Unwind(max_depth, pc, bp, context, 0, 0, false);
-}
-
-extern "C" {
-SANITIZER_INTERFACE_ATTRIBUTE
-void __sanitizer_print_stack_trace() {
-  GET_CURRENT_PC_BP;
-  BufferedStackTrace stack;
-  stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal);
-  stack.Print();
-}
-} // extern "C"
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_diag_standalone.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_diag_standalone.cc ------------------------------------------===//
+//===-- ubsan_diag_standalone.cpp -----------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_flags.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (removed)
@@ -1,85 +0,0 @@
-//===-- ubsan_flags.cc ----------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Runtime flags for UndefinedBehaviorSanitizer.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_flags.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_flags.h"
-#include "sanitizer_common/sanitizer_flag_parser.h"
-
-#include <stdlib.h>
-
-namespace __ubsan {
-
-const char *MaybeCallUbsanDefaultOptions() {
-  return (&__ubsan_default_options) ? __ubsan_default_options() : "";
-}
-
-static const char *GetFlag(const char *flag) {
-  // We cannot call getenv() from inside a preinit array initializer
-  if (SANITIZER_CAN_USE_PREINIT_ARRAY) {
-    return GetEnv(flag);
-  } else {
-    return getenv(flag);
-  }
-}
-
-Flags ubsan_flags;
-
-void Flags::SetDefaults() {
-#define UBSAN_FLAG(Type, Name, DefaultValue, Description) Name = DefaultValue;
-#include "ubsan_flags.inc"
-#undef UBSAN_FLAG
-}
-
-void RegisterUbsanFlags(FlagParser *parser, Flags *f) {
-#define UBSAN_FLAG(Type, Name, DefaultValue, Description) \
-  RegisterFlag(parser, #Name, Description, &f->Name);
-#include "ubsan_flags.inc"
-#undef UBSAN_FLAG
-}
-
-void InitializeFlags() {
-  SetCommonFlagsDefaults();
-  {
-    CommonFlags cf;
-    cf.CopyFrom(*common_flags());
-    cf.print_summary = false;
-    cf.external_symbolizer_path = GetFlag("UBSAN_SYMBOLIZER_PATH");
-    OverrideCommonFlags(cf);
-  }
-
-  Flags *f = flags();
-  f->SetDefaults();
-
-  FlagParser parser;
-  RegisterCommonFlags(&parser);
-  RegisterUbsanFlags(&parser, f);
-
-  // Override from user-specified string.
-  parser.ParseString(MaybeCallUbsanDefaultOptions());
-  // Override from environment variable.
-  parser.ParseStringFromEnv("UBSAN_OPTIONS");
-  InitializeCommonFlags();
-  if (Verbosity()) ReportUnrecognizedFlags();
-
-  if (common_flags()->help) parser.PrintFlagDescriptions();
-}
-
-}  // namespace __ubsan
-
-SANITIZER_INTERFACE_WEAK_DEF(const char *, __ubsan_default_options, void) {
-  return "";
-}
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_flags.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_flags.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_flags.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_flags.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_flags.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_flags.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_flags.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_flags.cc ----------------------------------------------------===//
+//===-- ubsan_flags.cpp ---------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (removed)
@@ -1,824 +0,0 @@
-//===-- ubsan_handlers.cc -------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Error logging entry points for the UBSan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_handlers.h"
-#include "ubsan_diag.h"
-#include "ubsan_flags.h"
-#include "ubsan_monitor.h"
-
-#include "sanitizer_common/sanitizer_common.h"
-
-using namespace __sanitizer;
-using namespace __ubsan;
-
-namespace __ubsan {
-bool ignoreReport(SourceLocation SLoc, ReportOptions Opts, ErrorType ET) {
-  // We are not allowed to skip error report: if we are in unrecoverable
-  // handler, we have to terminate the program right now, and therefore
-  // have to print some diagnostic.
-  //
-  // Even if source location is disabled, it doesn't mean that we have
-  // already report an error to the user: some concurrently running
-  // thread could have acquired it, but not yet printed the report.
-  if (Opts.FromUnrecoverableHandler)
-    return false;
-  return SLoc.isDisabled() || IsPCSuppressed(ET, Opts.pc, SLoc.getFilename());
-}
-
-const char *TypeCheckKinds[] = {
-    "load of", "store to", "reference binding to", "member access within",
-    "member call on", "constructor call on", "downcast of", "downcast of",
-    "upcast of", "cast to virtual base of", "_Nonnull binding to",
-    "dynamic operation on"};
-}
-
-static void handleTypeMismatchImpl(TypeMismatchData *Data, ValueHandle Pointer,
-                                   ReportOptions Opts) {
-  Location Loc = Data->Loc.acquire();
-
-  uptr Alignment = (uptr)1 << Data->LogAlignment;
-  ErrorType ET;
-  if (!Pointer)
-    ET = ErrorType::NullPointerUse;
-  else if (Pointer & (Alignment - 1))
-    ET = ErrorType::MisalignedPointerUse;
-  else
-    ET = ErrorType::InsufficientObjectSize;
-
-  // Use the SourceLocation from Data to track deduplication, even if it's
-  // invalid.
-  if (ignoreReport(Loc.getSourceLocation(), Opts, ET))
-    return;
-
-  SymbolizedStackHolder FallbackLoc;
-  if (Data->Loc.isInvalid()) {
-    FallbackLoc.reset(getCallerLocation(Opts.pc));
-    Loc = FallbackLoc;
-  }
-
-  ScopedReport R(Opts, Loc, ET);
-
-  switch (ET) {
-  case ErrorType::NullPointerUse:
-    Diag(Loc, DL_Error, ET, "%0 null pointer of type %1")
-        << TypeCheckKinds[Data->TypeCheckKind] << Data->Type;
-    break;
-  case ErrorType::MisalignedPointerUse:
-    Diag(Loc, DL_Error, ET, "%0 misaligned address %1 for type %3, "
-                        "which requires %2 byte alignment")
-        << TypeCheckKinds[Data->TypeCheckKind] << (void *)Pointer << Alignment
-        << Data->Type;
-    break;
-  case ErrorType::InsufficientObjectSize:
-    Diag(Loc, DL_Error, ET, "%0 address %1 with insufficient space "
-                        "for an object of type %2")
-        << TypeCheckKinds[Data->TypeCheckKind] << (void *)Pointer << Data->Type;
-    break;
-  default:
-    UNREACHABLE("unexpected error type!");
-  }
-
-  if (Pointer)
-    Diag(Pointer, DL_Note, ET, "pointer points here");
-}
-
-void __ubsan::__ubsan_handle_type_mismatch_v1(TypeMismatchData *Data,
-                                              ValueHandle Pointer) {
-  GET_REPORT_OPTIONS(false);
-  handleTypeMismatchImpl(Data, Pointer, Opts);
-}
-void __ubsan::__ubsan_handle_type_mismatch_v1_abort(TypeMismatchData *Data,
-                                                    ValueHandle Pointer) {
-  GET_REPORT_OPTIONS(true);
-  handleTypeMismatchImpl(Data, Pointer, Opts);
-  Die();
-}
-
-static void handleAlignmentAssumptionImpl(AlignmentAssumptionData *Data,
-                                          ValueHandle Pointer,
-                                          ValueHandle Alignment,
-                                          ValueHandle Offset,
-                                          ReportOptions Opts) {
-  Location Loc = Data->Loc.acquire();
-  SourceLocation AssumptionLoc = Data->AssumptionLoc.acquire();
-
-  ErrorType ET = ErrorType::AlignmentAssumption;
-
-  if (ignoreReport(Loc.getSourceLocation(), Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  uptr RealPointer = Pointer - Offset;
-  uptr LSB = LeastSignificantSetBitIndex(RealPointer);
-  uptr ActualAlignment = uptr(1) << LSB;
-
-  uptr Mask = Alignment - 1;
-  uptr MisAlignmentOffset = RealPointer & Mask;
-
-  if (!Offset) {
-    Diag(Loc, DL_Error, ET,
-         "assumption of %0 byte alignment for pointer of type %1 failed")
-        << Alignment << Data->Type;
-  } else {
-    Diag(Loc, DL_Error, ET,
-         "assumption of %0 byte alignment (with offset of %1 byte) for pointer "
-         "of type %2 failed")
-        << Alignment << Offset << Data->Type;
-  }
-
-  if (!AssumptionLoc.isInvalid())
-    Diag(AssumptionLoc, DL_Note, ET, "alignment assumption was specified here");
-
-  Diag(RealPointer, DL_Note, ET,
-       "%0address is %1 aligned, misalignment offset is %2 bytes")
-      << (Offset ? "offset " : "") << ActualAlignment << MisAlignmentOffset;
-}
-
-void __ubsan::__ubsan_handle_alignment_assumption(AlignmentAssumptionData *Data,
-                                                  ValueHandle Pointer,
-                                                  ValueHandle Alignment,
-                                                  ValueHandle Offset) {
-  GET_REPORT_OPTIONS(false);
-  handleAlignmentAssumptionImpl(Data, Pointer, Alignment, Offset, Opts);
-}
-void __ubsan::__ubsan_handle_alignment_assumption_abort(
-    AlignmentAssumptionData *Data, ValueHandle Pointer, ValueHandle Alignment,
-    ValueHandle Offset) {
-  GET_REPORT_OPTIONS(true);
-  handleAlignmentAssumptionImpl(Data, Pointer, Alignment, Offset, Opts);
-  Die();
-}
-
-/// \brief Common diagnostic emission for various forms of integer overflow.
-template <typename T>
-static void handleIntegerOverflowImpl(OverflowData *Data, ValueHandle LHS,
-                                      const char *Operator, T RHS,
-                                      ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  bool IsSigned = Data->Type.isSignedIntegerTy();
-  ErrorType ET = IsSigned ? ErrorType::SignedIntegerOverflow
-                          : ErrorType::UnsignedIntegerOverflow;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  // If this is an unsigned overflow in non-fatal mode, potentially ignore it.
-  if (!IsSigned && !Opts.FromUnrecoverableHandler &&
-      flags()->silence_unsigned_overflow)
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET, "%0 integer overflow: "
-                          "%1 %2 %3 cannot be represented in type %4")
-      << (IsSigned ? "signed" : "unsigned") << Value(Data->Type, LHS)
-      << Operator << RHS << Data->Type;
-}
-
-#define UBSAN_OVERFLOW_HANDLER(handler_name, op, unrecoverable)                \
-  void __ubsan::handler_name(OverflowData *Data, ValueHandle LHS,              \
-                             ValueHandle RHS) {                                \
-    GET_REPORT_OPTIONS(unrecoverable);                                         \
-    handleIntegerOverflowImpl(Data, LHS, op, Value(Data->Type, RHS), Opts);    \
-    if (unrecoverable)                                                         \
-      Die();                                                                   \
-  }
-
-UBSAN_OVERFLOW_HANDLER(__ubsan_handle_add_overflow, "+", false)
-UBSAN_OVERFLOW_HANDLER(__ubsan_handle_add_overflow_abort, "+", true)
-UBSAN_OVERFLOW_HANDLER(__ubsan_handle_sub_overflow, "-", false)
-UBSAN_OVERFLOW_HANDLER(__ubsan_handle_sub_overflow_abort, "-", true)
-UBSAN_OVERFLOW_HANDLER(__ubsan_handle_mul_overflow, "*", false)
-UBSAN_OVERFLOW_HANDLER(__ubsan_handle_mul_overflow_abort, "*", true)
-
-static void handleNegateOverflowImpl(OverflowData *Data, ValueHandle OldVal,
-                                     ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  bool IsSigned = Data->Type.isSignedIntegerTy();
-  ErrorType ET = IsSigned ? ErrorType::SignedIntegerOverflow
-                          : ErrorType::UnsignedIntegerOverflow;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  if (!IsSigned && flags()->silence_unsigned_overflow)
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  if (IsSigned)
-    Diag(Loc, DL_Error, ET,
-         "negation of %0 cannot be represented in type %1; "
-         "cast to an unsigned type to negate this value to itself")
-        << Value(Data->Type, OldVal) << Data->Type;
-  else
-    Diag(Loc, DL_Error, ET, "negation of %0 cannot be represented in type %1")
-        << Value(Data->Type, OldVal) << Data->Type;
-}
-
-void __ubsan::__ubsan_handle_negate_overflow(OverflowData *Data,
-                                             ValueHandle OldVal) {
-  GET_REPORT_OPTIONS(false);
-  handleNegateOverflowImpl(Data, OldVal, Opts);
-}
-void __ubsan::__ubsan_handle_negate_overflow_abort(OverflowData *Data,
-                                                    ValueHandle OldVal) {
-  GET_REPORT_OPTIONS(true);
-  handleNegateOverflowImpl(Data, OldVal, Opts);
-  Die();
-}
-
-static void handleDivremOverflowImpl(OverflowData *Data, ValueHandle LHS,
-                                     ValueHandle RHS, ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  Value LHSVal(Data->Type, LHS);
-  Value RHSVal(Data->Type, RHS);
-
-  ErrorType ET;
-  if (RHSVal.isMinusOne())
-    ET = ErrorType::SignedIntegerOverflow;
-  else if (Data->Type.isIntegerTy())
-    ET = ErrorType::IntegerDivideByZero;
-  else
-    ET = ErrorType::FloatDivideByZero;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  switch (ET) {
-  case ErrorType::SignedIntegerOverflow:
-    Diag(Loc, DL_Error, ET,
-         "division of %0 by -1 cannot be represented in type %1")
-        << LHSVal << Data->Type;
-    break;
-  default:
-    Diag(Loc, DL_Error, ET, "division by zero");
-    break;
-  }
-}
-
-void __ubsan::__ubsan_handle_divrem_overflow(OverflowData *Data,
-                                             ValueHandle LHS, ValueHandle RHS) {
-  GET_REPORT_OPTIONS(false);
-  handleDivremOverflowImpl(Data, LHS, RHS, Opts);
-}
-void __ubsan::__ubsan_handle_divrem_overflow_abort(OverflowData *Data,
-                                                    ValueHandle LHS,
-                                                    ValueHandle RHS) {
-  GET_REPORT_OPTIONS(true);
-  handleDivremOverflowImpl(Data, LHS, RHS, Opts);
-  Die();
-}
-
-static void handleShiftOutOfBoundsImpl(ShiftOutOfBoundsData *Data,
-                                       ValueHandle LHS, ValueHandle RHS,
-                                       ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  Value LHSVal(Data->LHSType, LHS);
-  Value RHSVal(Data->RHSType, RHS);
-
-  ErrorType ET;
-  if (RHSVal.isNegative() ||
-      RHSVal.getPositiveIntValue() >= Data->LHSType.getIntegerBitWidth())
-    ET = ErrorType::InvalidShiftExponent;
-  else
-    ET = ErrorType::InvalidShiftBase;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  if (ET == ErrorType::InvalidShiftExponent) {
-    if (RHSVal.isNegative())
-      Diag(Loc, DL_Error, ET, "shift exponent %0 is negative") << RHSVal;
-    else
-      Diag(Loc, DL_Error, ET,
-           "shift exponent %0 is too large for %1-bit type %2")
-          << RHSVal << Data->LHSType.getIntegerBitWidth() << Data->LHSType;
-  } else {
-    if (LHSVal.isNegative())
-      Diag(Loc, DL_Error, ET, "left shift of negative value %0") << LHSVal;
-    else
-      Diag(Loc, DL_Error, ET,
-           "left shift of %0 by %1 places cannot be represented in type %2")
-          << LHSVal << RHSVal << Data->LHSType;
-  }
-}
-
-void __ubsan::__ubsan_handle_shift_out_of_bounds(ShiftOutOfBoundsData *Data,
-                                                 ValueHandle LHS,
-                                                 ValueHandle RHS) {
-  GET_REPORT_OPTIONS(false);
-  handleShiftOutOfBoundsImpl(Data, LHS, RHS, Opts);
-}
-void __ubsan::__ubsan_handle_shift_out_of_bounds_abort(
-                                                     ShiftOutOfBoundsData *Data,
-                                                     ValueHandle LHS,
-                                                     ValueHandle RHS) {
-  GET_REPORT_OPTIONS(true);
-  handleShiftOutOfBoundsImpl(Data, LHS, RHS, Opts);
-  Die();
-}
-
-static void handleOutOfBoundsImpl(OutOfBoundsData *Data, ValueHandle Index,
-                                  ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::OutOfBoundsIndex;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Value IndexVal(Data->IndexType, Index);
-  Diag(Loc, DL_Error, ET, "index %0 out of bounds for type %1")
-    << IndexVal << Data->ArrayType;
-}
-
-void __ubsan::__ubsan_handle_out_of_bounds(OutOfBoundsData *Data,
-                                           ValueHandle Index) {
-  GET_REPORT_OPTIONS(false);
-  handleOutOfBoundsImpl(Data, Index, Opts);
-}
-void __ubsan::__ubsan_handle_out_of_bounds_abort(OutOfBoundsData *Data,
-                                                 ValueHandle Index) {
-  GET_REPORT_OPTIONS(true);
-  handleOutOfBoundsImpl(Data, Index, Opts);
-  Die();
-}
-
-static void handleBuiltinUnreachableImpl(UnreachableData *Data,
-                                         ReportOptions Opts) {
-  ErrorType ET = ErrorType::UnreachableCall;
-  ScopedReport R(Opts, Data->Loc, ET);
-  Diag(Data->Loc, DL_Error, ET,
-       "execution reached an unreachable program point");
-}
-
-void __ubsan::__ubsan_handle_builtin_unreachable(UnreachableData *Data) {
-  GET_REPORT_OPTIONS(true);
-  handleBuiltinUnreachableImpl(Data, Opts);
-  Die();
-}
-
-static void handleMissingReturnImpl(UnreachableData *Data, ReportOptions Opts) {
-  ErrorType ET = ErrorType::MissingReturn;
-  ScopedReport R(Opts, Data->Loc, ET);
-  Diag(Data->Loc, DL_Error, ET,
-       "execution reached the end of a value-returning function "
-       "without returning a value");
-}
-
-void __ubsan::__ubsan_handle_missing_return(UnreachableData *Data) {
-  GET_REPORT_OPTIONS(true);
-  handleMissingReturnImpl(Data, Opts);
-  Die();
-}
-
-static void handleVLABoundNotPositive(VLABoundData *Data, ValueHandle Bound,
-                                      ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::NonPositiveVLAIndex;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET, "variable length array bound evaluates to "
-                          "non-positive value %0")
-      << Value(Data->Type, Bound);
-}
-
-void __ubsan::__ubsan_handle_vla_bound_not_positive(VLABoundData *Data,
-                                                    ValueHandle Bound) {
-  GET_REPORT_OPTIONS(false);
-  handleVLABoundNotPositive(Data, Bound, Opts);
-}
-void __ubsan::__ubsan_handle_vla_bound_not_positive_abort(VLABoundData *Data,
-                                                          ValueHandle Bound) {
-  GET_REPORT_OPTIONS(true);
-  handleVLABoundNotPositive(Data, Bound, Opts);
-  Die();
-}
-
-static bool looksLikeFloatCastOverflowDataV1(void *Data) {
-  // First field is either a pointer to filename or a pointer to a
-  // TypeDescriptor.
-  u8 *FilenameOrTypeDescriptor;
-  internal_memcpy(&FilenameOrTypeDescriptor, Data,
-                  sizeof(FilenameOrTypeDescriptor));
-
-  // Heuristic: For float_cast_overflow, the TypeKind will be either TK_Integer
-  // (0x0), TK_Float (0x1) or TK_Unknown (0xff). If both types are known,
-  // adding both bytes will be 0 or 1 (for BE or LE). If it were a filename,
-  // adding two printable characters will not yield such a value. Otherwise,
-  // if one of them is 0xff, this is most likely TK_Unknown type descriptor.
-  u16 MaybeFromTypeKind =
-      FilenameOrTypeDescriptor[0] + FilenameOrTypeDescriptor[1];
-  return MaybeFromTypeKind < 2 || FilenameOrTypeDescriptor[0] == 0xff ||
-         FilenameOrTypeDescriptor[1] == 0xff;
-}
-
-static void handleFloatCastOverflow(void *DataPtr, ValueHandle From,
-                                    ReportOptions Opts) {
-  SymbolizedStackHolder CallerLoc;
-  Location Loc;
-  const TypeDescriptor *FromType, *ToType;
-  ErrorType ET = ErrorType::FloatCastOverflow;
-
-  if (looksLikeFloatCastOverflowDataV1(DataPtr)) {
-    auto Data = reinterpret_cast<FloatCastOverflowData *>(DataPtr);
-    CallerLoc.reset(getCallerLocation(Opts.pc));
-    Loc = CallerLoc;
-    FromType = &Data->FromType;
-    ToType = &Data->ToType;
-  } else {
-    auto Data = reinterpret_cast<FloatCastOverflowDataV2 *>(DataPtr);
-    SourceLocation SLoc = Data->Loc.acquire();
-    if (ignoreReport(SLoc, Opts, ET))
-      return;
-    Loc = SLoc;
-    FromType = &Data->FromType;
-    ToType = &Data->ToType;
-  }
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET,
-       "%0 is outside the range of representable values of type %2")
-      << Value(*FromType, From) << *FromType << *ToType;
-}
-
-void __ubsan::__ubsan_handle_float_cast_overflow(void *Data, ValueHandle From) {
-  GET_REPORT_OPTIONS(false);
-  handleFloatCastOverflow(Data, From, Opts);
-}
-void __ubsan::__ubsan_handle_float_cast_overflow_abort(void *Data,
-                                                       ValueHandle From) {
-  GET_REPORT_OPTIONS(true);
-  handleFloatCastOverflow(Data, From, Opts);
-  Die();
-}
-
-static void handleLoadInvalidValue(InvalidValueData *Data, ValueHandle Val,
-                                   ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  // This check could be more precise if we used different handlers for
-  // -fsanitize=bool and -fsanitize=enum.
-  bool IsBool = (0 == internal_strcmp(Data->Type.getTypeName(), "'bool'")) ||
-                (0 == internal_strncmp(Data->Type.getTypeName(), "'BOOL'", 6));
-  ErrorType ET =
-      IsBool ? ErrorType::InvalidBoolLoad : ErrorType::InvalidEnumLoad;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET,
-       "load of value %0, which is not a valid value for type %1")
-      << Value(Data->Type, Val) << Data->Type;
-}
-
-void __ubsan::__ubsan_handle_load_invalid_value(InvalidValueData *Data,
-                                                ValueHandle Val) {
-  GET_REPORT_OPTIONS(false);
-  handleLoadInvalidValue(Data, Val, Opts);
-}
-void __ubsan::__ubsan_handle_load_invalid_value_abort(InvalidValueData *Data,
-                                                      ValueHandle Val) {
-  GET_REPORT_OPTIONS(true);
-  handleLoadInvalidValue(Data, Val, Opts);
-  Die();
-}
-
-static void handleImplicitConversion(ImplicitConversionData *Data,
-                                     ReportOptions Opts, ValueHandle Src,
-                                     ValueHandle Dst) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::GenericUB;
-
-  const TypeDescriptor &SrcTy = Data->FromType;
-  const TypeDescriptor &DstTy = Data->ToType;
-
-  bool SrcSigned = SrcTy.isSignedIntegerTy();
-  bool DstSigned = DstTy.isSignedIntegerTy();
-
-  switch (Data->Kind) {
-  case ICCK_IntegerTruncation: { // Legacy, no longer used.
-    // Let's figure out what it should be as per the new types, and upgrade.
-    // If both types are unsigned, then it's an unsigned truncation.
-    // Else, it is a signed truncation.
-    if (!SrcSigned && !DstSigned) {
-      ET = ErrorType::ImplicitUnsignedIntegerTruncation;
-    } else {
-      ET = ErrorType::ImplicitSignedIntegerTruncation;
-    }
-    break;
-  }
-  case ICCK_UnsignedIntegerTruncation:
-    ET = ErrorType::ImplicitUnsignedIntegerTruncation;
-    break;
-  case ICCK_SignedIntegerTruncation:
-    ET = ErrorType::ImplicitSignedIntegerTruncation;
-    break;
-  case ICCK_IntegerSignChange:
-    ET = ErrorType::ImplicitIntegerSignChange;
-    break;
-  case ICCK_SignedIntegerTruncationOrSignChange:
-    ET = ErrorType::ImplicitSignedIntegerTruncationOrSignChange;
-    break;
-  }
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  // FIXME: is it possible to dump the values as hex with fixed width?
-
-  Diag(Loc, DL_Error, ET,
-       "implicit conversion from type %0 of value %1 (%2-bit, %3signed) to "
-       "type %4 changed the value to %5 (%6-bit, %7signed)")
-      << SrcTy << Value(SrcTy, Src) << SrcTy.getIntegerBitWidth()
-      << (SrcSigned ? "" : "un") << DstTy << Value(DstTy, Dst)
-      << DstTy.getIntegerBitWidth() << (DstSigned ? "" : "un");
-}
-
-void __ubsan::__ubsan_handle_implicit_conversion(ImplicitConversionData *Data,
-                                                 ValueHandle Src,
-                                                 ValueHandle Dst) {
-  GET_REPORT_OPTIONS(false);
-  handleImplicitConversion(Data, Opts, Src, Dst);
-}
-void __ubsan::__ubsan_handle_implicit_conversion_abort(
-    ImplicitConversionData *Data, ValueHandle Src, ValueHandle Dst) {
-  GET_REPORT_OPTIONS(true);
-  handleImplicitConversion(Data, Opts, Src, Dst);
-  Die();
-}
-
-static void handleInvalidBuiltin(InvalidBuiltinData *Data, ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::InvalidBuiltin;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET,
-       "passing zero to %0, which is not a valid argument")
-    << ((Data->Kind == BCK_CTZPassedZero) ? "ctz()" : "clz()");
-}
-
-void __ubsan::__ubsan_handle_invalid_builtin(InvalidBuiltinData *Data) {
-  GET_REPORT_OPTIONS(true);
-  handleInvalidBuiltin(Data, Opts);
-}
-void __ubsan::__ubsan_handle_invalid_builtin_abort(InvalidBuiltinData *Data) {
-  GET_REPORT_OPTIONS(true);
-  handleInvalidBuiltin(Data, Opts);
-  Die();
-}
-
-static void handleNonNullReturn(NonNullReturnData *Data, SourceLocation *LocPtr,
-                                ReportOptions Opts, bool IsAttr) {
-  if (!LocPtr)
-    UNREACHABLE("source location pointer is null!");
-
-  SourceLocation Loc = LocPtr->acquire();
-  ErrorType ET = ErrorType::InvalidNullReturn;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET,
-       "null pointer returned from function declared to never return null");
-  if (!Data->AttrLoc.isInvalid())
-    Diag(Data->AttrLoc, DL_Note, ET, "%0 specified here")
-        << (IsAttr ? "returns_nonnull attribute"
-                   : "_Nonnull return type annotation");
-}
-
-void __ubsan::__ubsan_handle_nonnull_return_v1(NonNullReturnData *Data,
-                                               SourceLocation *LocPtr) {
-  GET_REPORT_OPTIONS(false);
-  handleNonNullReturn(Data, LocPtr, Opts, true);
-}
-
-void __ubsan::__ubsan_handle_nonnull_return_v1_abort(NonNullReturnData *Data,
-                                                     SourceLocation *LocPtr) {
-  GET_REPORT_OPTIONS(true);
-  handleNonNullReturn(Data, LocPtr, Opts, true);
-  Die();
-}
-
-void __ubsan::__ubsan_handle_nullability_return_v1(NonNullReturnData *Data,
-                                                   SourceLocation *LocPtr) {
-  GET_REPORT_OPTIONS(false);
-  handleNonNullReturn(Data, LocPtr, Opts, false);
-}
-
-void __ubsan::__ubsan_handle_nullability_return_v1_abort(
-    NonNullReturnData *Data, SourceLocation *LocPtr) {
-  GET_REPORT_OPTIONS(true);
-  handleNonNullReturn(Data, LocPtr, Opts, false);
-  Die();
-}
-
-static void handleNonNullArg(NonNullArgData *Data, ReportOptions Opts,
-                             bool IsAttr) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::InvalidNullArgument;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET,
-       "null pointer passed as argument %0, which is declared to "
-       "never be null")
-      << Data->ArgIndex;
-  if (!Data->AttrLoc.isInvalid())
-    Diag(Data->AttrLoc, DL_Note, ET, "%0 specified here")
-        << (IsAttr ? "nonnull attribute" : "_Nonnull type annotation");
-}
-
-void __ubsan::__ubsan_handle_nonnull_arg(NonNullArgData *Data) {
-  GET_REPORT_OPTIONS(false);
-  handleNonNullArg(Data, Opts, true);
-}
-
-void __ubsan::__ubsan_handle_nonnull_arg_abort(NonNullArgData *Data) {
-  GET_REPORT_OPTIONS(true);
-  handleNonNullArg(Data, Opts, true);
-  Die();
-}
-
-void __ubsan::__ubsan_handle_nullability_arg(NonNullArgData *Data) {
-  GET_REPORT_OPTIONS(false);
-  handleNonNullArg(Data, Opts, false);
-}
-
-void __ubsan::__ubsan_handle_nullability_arg_abort(NonNullArgData *Data) {
-  GET_REPORT_OPTIONS(true);
-  handleNonNullArg(Data, Opts, false);
-  Die();
-}
-
-static void handlePointerOverflowImpl(PointerOverflowData *Data,
-                                      ValueHandle Base,
-                                      ValueHandle Result,
-                                      ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::PointerOverflow;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  if ((sptr(Base) >= 0) == (sptr(Result) >= 0)) {
-    if (Base > Result)
-      Diag(Loc, DL_Error, ET,
-           "addition of unsigned offset to %0 overflowed to %1")
-          << (void *)Base << (void *)Result;
-    else
-      Diag(Loc, DL_Error, ET,
-           "subtraction of unsigned offset from %0 overflowed to %1")
-          << (void *)Base << (void *)Result;
-  } else {
-    Diag(Loc, DL_Error, ET,
-         "pointer index expression with base %0 overflowed to %1")
-        << (void *)Base << (void *)Result;
-  }
-}
-
-void __ubsan::__ubsan_handle_pointer_overflow(PointerOverflowData *Data,
-                                              ValueHandle Base,
-                                              ValueHandle Result) {
-  GET_REPORT_OPTIONS(false);
-  handlePointerOverflowImpl(Data, Base, Result, Opts);
-}
-
-void __ubsan::__ubsan_handle_pointer_overflow_abort(PointerOverflowData *Data,
-                                                    ValueHandle Base,
-                                                    ValueHandle Result) {
-  GET_REPORT_OPTIONS(true);
-  handlePointerOverflowImpl(Data, Base, Result, Opts);
-  Die();
-}
-
-static void handleCFIBadIcall(CFICheckFailData *Data, ValueHandle Function,
-                              ReportOptions Opts) {
-  if (Data->CheckKind != CFITCK_ICall && Data->CheckKind != CFITCK_NVMFCall)
-    Die();
-
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::CFIBadType;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  const char *CheckKindStr = Data->CheckKind == CFITCK_NVMFCall
-                                 ? "non-virtual pointer to member function call"
-                                 : "indirect function call";
-  Diag(Loc, DL_Error, ET,
-       "control flow integrity check for type %0 failed during %1")
-      << Data->Type << CheckKindStr;
-
-  SymbolizedStackHolder FLoc(getSymbolizedLocation(Function));
-  const char *FName = FLoc.get()->info.function;
-  if (!FName)
-    FName = "(unknown)";
-  Diag(FLoc, DL_Note, ET, "%0 defined here") << FName;
-
-  // If the failure involved different DSOs for the check location and icall
-  // target, report the DSO names.
-  const char *DstModule = FLoc.get()->info.module;
-  if (!DstModule)
-    DstModule = "(unknown)";
-
-  const char *SrcModule = Symbolizer::GetOrInit()->GetModuleNameForPc(Opts.pc);
-  if (!SrcModule)
-    SrcModule = "(unknown)";
-
-  if (internal_strcmp(SrcModule, DstModule))
-    Diag(Loc, DL_Note, ET,
-         "check failed in %0, destination function located in %1")
-        << SrcModule << DstModule;
-}
-
-namespace __ubsan {
-
-#ifdef UBSAN_CAN_USE_CXXABI
-
-#ifdef _WIN32
-
-extern "C" void __ubsan_handle_cfi_bad_type_default(CFICheckFailData *Data,
-                                                    ValueHandle Vtable,
-                                                    bool ValidVtable,
-                                                    ReportOptions Opts) {
-  Die();
-}
-
-WIN_WEAK_ALIAS(__ubsan_handle_cfi_bad_type, __ubsan_handle_cfi_bad_type_default)
-#else
-SANITIZER_WEAK_ATTRIBUTE
-#endif
-void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
-                                 bool ValidVtable, ReportOptions Opts);
-
-#else
-void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
-                                 bool ValidVtable, ReportOptions Opts) {
-  Die();
-}
-#endif
-
-}  // namespace __ubsan
-
-void __ubsan::__ubsan_handle_cfi_check_fail(CFICheckFailData *Data,
-                                            ValueHandle Value,
-                                            uptr ValidVtable) {
-  GET_REPORT_OPTIONS(false);
-  if (Data->CheckKind == CFITCK_ICall || Data->CheckKind == CFITCK_NVMFCall)
-    handleCFIBadIcall(Data, Value, Opts);
-  else
-    __ubsan_handle_cfi_bad_type(Data, Value, ValidVtable, Opts);
-}
-
-void __ubsan::__ubsan_handle_cfi_check_fail_abort(CFICheckFailData *Data,
-                                                  ValueHandle Value,
-                                                  uptr ValidVtable) {
-  GET_REPORT_OPTIONS(true);
-  if (Data->CheckKind == CFITCK_ICall || Data->CheckKind == CFITCK_NVMFCall)
-    handleCFIBadIcall(Data, Value, Opts);
-  else
-    __ubsan_handle_cfi_bad_type(Data, Value, ValidVtable, Opts);
-  Die();
-}
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_handlers.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_handlers.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_handlers.cc -------------------------------------------------===//
+//===-- ubsan_handlers.cpp ------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc (removed)
@@ -1,205 +0,0 @@
-//===-- ubsan_handlers_cxx.cc ---------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Error logging entry points for the UBSan runtime, which are only used for C++
-// compilations. This file is permitted to use language features which require
-// linking against a C++ ABI library.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_handlers.h"
-#include "ubsan_handlers_cxx.h"
-#include "ubsan_diag.h"
-#include "ubsan_type_hash.h"
-
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_suppressions.h"
-
-using namespace __sanitizer;
-using namespace __ubsan;
-
-namespace __ubsan {
-  extern const char *TypeCheckKinds[];
-}
-
-// Returns true if UBSan has printed an error report.
-static bool HandleDynamicTypeCacheMiss(
-    DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash,
-    ReportOptions Opts) {
-  if (checkDynamicType((void*)Pointer, Data->TypeInfo, Hash))
-    // Just a cache miss. The type matches after all.
-    return false;
-
-  // Check if error report should be suppressed.
-  DynamicTypeInfo DTI = getDynamicTypeInfoFromObject((void*)Pointer);
-  if (DTI.isValid() && IsVptrCheckSuppressed(DTI.getMostDerivedTypeName()))
-    return false;
-
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::DynamicTypeMismatch;
-  if (ignoreReport(Loc, Opts, ET))
-    return false;
-
-  ScopedReport R(Opts, Loc, ET);
-
-  Diag(Loc, DL_Error, ET,
-       "%0 address %1 which does not point to an object of type %2")
-    << TypeCheckKinds[Data->TypeCheckKind] << (void*)Pointer << Data->Type;
-
-  // If possible, say what type it actually points to.
-  if (!DTI.isValid()) {
-    if (DTI.getOffset() < -VptrMaxOffsetToTop || DTI.getOffset() > VptrMaxOffsetToTop) {
-      Diag(Pointer, DL_Note, ET,
-           "object has a possibly invalid vptr: abs(offset to top) too big")
-          << TypeName(DTI.getMostDerivedTypeName())
-          << Range(Pointer, Pointer + sizeof(uptr), "possibly invalid vptr");
-    } else {
-      Diag(Pointer, DL_Note, ET, "object has invalid vptr")
-          << TypeName(DTI.getMostDerivedTypeName())
-          << Range(Pointer, Pointer + sizeof(uptr), "invalid vptr");
-    }
-  } else if (!DTI.getOffset())
-    Diag(Pointer, DL_Note, ET, "object is of type %0")
-        << TypeName(DTI.getMostDerivedTypeName())
-        << Range(Pointer, Pointer + sizeof(uptr), "vptr for %0");
-  else
-    // FIXME: Find the type at the specified offset, and include that
-    //        in the note.
-    Diag(Pointer - DTI.getOffset(), DL_Note, ET,
-         "object is base class subobject at offset %0 within object of type %1")
-        << DTI.getOffset() << TypeName(DTI.getMostDerivedTypeName())
-        << TypeName(DTI.getSubobjectTypeName())
-        << Range(Pointer, Pointer + sizeof(uptr),
-                 "vptr for %2 base class of %1");
-  return true;
-}
-
-void __ubsan::__ubsan_handle_dynamic_type_cache_miss(
-    DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
-  GET_REPORT_OPTIONS(false);
-  HandleDynamicTypeCacheMiss(Data, Pointer, Hash, Opts);
-}
-void __ubsan::__ubsan_handle_dynamic_type_cache_miss_abort(
-    DynamicTypeCacheMissData *Data, ValueHandle Pointer, ValueHandle Hash) {
-  // Note: -fsanitize=vptr is always recoverable.
-  GET_REPORT_OPTIONS(false);
-  if (HandleDynamicTypeCacheMiss(Data, Pointer, Hash, Opts))
-    Die();
-}
-
-namespace __ubsan {
-void __ubsan_handle_cfi_bad_type(CFICheckFailData *Data, ValueHandle Vtable,
-                                 bool ValidVtable, ReportOptions Opts) {
-  SourceLocation Loc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::CFIBadType;
-
-  if (ignoreReport(Loc, Opts, ET))
-    return;
-
-  ScopedReport R(Opts, Loc, ET);
-  DynamicTypeInfo DTI = ValidVtable
-                            ? getDynamicTypeInfoFromVtable((void *)Vtable)
-                            : DynamicTypeInfo(0, 0, 0);
-
-  const char *CheckKindStr;
-  switch (Data->CheckKind) {
-  case CFITCK_VCall:
-    CheckKindStr = "virtual call";
-    break;
-  case CFITCK_NVCall:
-    CheckKindStr = "non-virtual call";
-    break;
-  case CFITCK_DerivedCast:
-    CheckKindStr = "base-to-derived cast";
-    break;
-  case CFITCK_UnrelatedCast:
-    CheckKindStr = "cast to unrelated type";
-    break;
-  case CFITCK_VMFCall:
-    CheckKindStr = "virtual pointer to member function call";
-    break;
-  case CFITCK_ICall:
-  case CFITCK_NVMFCall:
-    Die();
-  }
-
-  Diag(Loc, DL_Error, ET,
-       "control flow integrity check for type %0 failed during "
-       "%1 (vtable address %2)")
-      << Data->Type << CheckKindStr << (void *)Vtable;
-
-  // If possible, say what type it actually points to.
-  if (!DTI.isValid())
-    Diag(Vtable, DL_Note, ET, "invalid vtable");
-  else
-    Diag(Vtable, DL_Note, ET, "vtable is of type %0")
-        << TypeName(DTI.getMostDerivedTypeName());
-
-  // If the failure involved different DSOs for the check location and vtable,
-  // report the DSO names.
-  const char *DstModule = Symbolizer::GetOrInit()->GetModuleNameForPc(Vtable);
-  if (!DstModule)
-    DstModule = "(unknown)";
-
-  const char *SrcModule = Symbolizer::GetOrInit()->GetModuleNameForPc(Opts.pc);
-  if (!SrcModule)
-    SrcModule = "(unknown)";
-
-  if (internal_strcmp(SrcModule, DstModule))
-    Diag(Loc, DL_Note, ET, "check failed in %0, vtable located in %1")
-        << SrcModule << DstModule;
-}
-
-static bool handleFunctionTypeMismatch(FunctionTypeMismatchData *Data,
-                                       ValueHandle Function,
-                                       ValueHandle calleeRTTI,
-                                       ValueHandle fnRTTI, ReportOptions Opts) {
-  if (checkTypeInfoEquality(reinterpret_cast<void *>(calleeRTTI),
-                            reinterpret_cast<void *>(fnRTTI)))
-    return false;
-
-  SourceLocation CallLoc = Data->Loc.acquire();
-  ErrorType ET = ErrorType::FunctionTypeMismatch;
-
-  if (ignoreReport(CallLoc, Opts, ET))
-    return true;
-
-  ScopedReport R(Opts, CallLoc, ET);
-
-  SymbolizedStackHolder FLoc(getSymbolizedLocation(Function));
-  const char *FName = FLoc.get()->info.function;
-  if (!FName)
-    FName = "(unknown)";
-
-  Diag(CallLoc, DL_Error, ET,
-       "call to function %0 through pointer to incorrect function type %1")
-      << FName << Data->Type;
-  Diag(FLoc, DL_Note, ET, "%0 defined here") << FName;
-  return true;
-}
-
-void __ubsan_handle_function_type_mismatch_v1(FunctionTypeMismatchData *Data,
-                                              ValueHandle Function,
-                                              ValueHandle calleeRTTI,
-                                              ValueHandle fnRTTI) {
-  GET_REPORT_OPTIONS(false);
-  handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts);
-}
-
-void __ubsan_handle_function_type_mismatch_v1_abort(
-    FunctionTypeMismatchData *Data, ValueHandle Function,
-    ValueHandle calleeRTTI, ValueHandle fnRTTI) {
-  GET_REPORT_OPTIONS(true);
-  if (handleFunctionTypeMismatch(Data, Function, calleeRTTI, fnRTTI, Opts))
-    Die();
-}
-}  // namespace __ubsan
-
-#endif // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_handlers_cxx.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_handlers_cxx.cc ---------------------------------------------===//
+//===-- ubsan_handlers_cxx.cpp --------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_init.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init.cc (removed)
@@ -1,64 +0,0 @@
-//===-- ubsan_init.cc -----------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Initialization of UBSan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_diag.h"
-#include "ubsan_init.h"
-#include "ubsan_flags.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_libc.h"
-#include "sanitizer_common/sanitizer_mutex.h"
-#include "sanitizer_common/sanitizer_symbolizer.h"
-
-using namespace __ubsan;
-
-const char *__ubsan::GetSanititizerToolName() {
-  return "UndefinedBehaviorSanitizer";
-}
-
-static bool ubsan_initialized;
-static StaticSpinMutex ubsan_init_mu;
-
-static void CommonInit() {
-  InitializeSuppressions();
-}
-
-static void CommonStandaloneInit() {
-  SanitizerToolName = GetSanititizerToolName();
-  CacheBinaryName();
-  InitializeFlags();
-  __sanitizer_set_report_path(common_flags()->log_path);
-  AndroidLogInit();
-  InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
-  CommonInit();
-}
-
-void __ubsan::InitAsStandalone() {
-  SpinMutexLock l(&ubsan_init_mu);
-  if (!ubsan_initialized) {
-    CommonStandaloneInit();
-    ubsan_initialized = true;
-  }
-}
-
-void __ubsan::InitAsStandaloneIfNecessary() { return InitAsStandalone(); }
-
-void __ubsan::InitAsPlugin() {
-  SpinMutexLock l(&ubsan_init_mu);
-  if (!ubsan_initialized) {
-    CommonInit();
-    ubsan_initialized = true;
-  }
-}
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_init.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_init.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_init.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_init.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_init.cc -----------------------------------------------------===//
+//===-- ubsan_init.cpp ----------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc (removed)
@@ -1,33 +0,0 @@
-//===-- ubsan_init_standalone.cc ------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Initialization of standalone UBSan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if !CAN_SANITIZE_UB
-# error "UBSan is not supported on this platform!"
-#endif
-
-#include "sanitizer_common/sanitizer_internal_defs.h"
-#include "ubsan_init.h"
-#include "ubsan_signals_standalone.h"
-
-namespace __ubsan {
-
-class UbsanStandaloneInitializer {
- public:
-  UbsanStandaloneInitializer() {
-    InitAsStandalone();
-    InitializeDeadlySignals();
-  }
-};
-static UbsanStandaloneInitializer ubsan_standalone_initializer;
-
-} // namespace __ubsan

Copied: compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init_standalone.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_init_standalone.cc ------------------------------------------===//
+//===-- ubsan_init_standalone.cpp -----------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc (removed)
@@ -1,35 +0,0 @@
-//===-- ubsan_init_standalone_preinit.cc ---------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Initialization of standalone UBSan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if !CAN_SANITIZE_UB
-#error "UBSan is not supported on this platform!"
-#endif
-
-#include "sanitizer_common/sanitizer_internal_defs.h"
-#include "ubsan_init.h"
-#include "ubsan_signals_standalone.h"
-
-#if SANITIZER_CAN_USE_PREINIT_ARRAY
-
-namespace __ubsan {
-
-static void PreInitAsStandalone() {
-  InitAsStandalone();
-  InitializeDeadlySignals();
-}
-
-} // namespace __ubsan
-
-__attribute__((section(".preinit_array"), used)) void (*__local_ubsan_preinit)(
-    void) = __ubsan::PreInitAsStandalone;
-#endif // SANITIZER_CAN_USE_PREINIT_ARRAY

Copied: compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_init_standalone_preinit.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_init_standalone_preinit.cc ---------------------------------===//
+//===-- ubsan_init_standalone_preinit.cpp --------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc (removed)
@@ -1,75 +0,0 @@
-//===-- ubsan_monitor.cc ----------------------------------------*- C++ -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Hooks which allow a monitor process to inspect UBSan's diagnostics.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_monitor.h"
-
-using namespace __ubsan;
-
-UndefinedBehaviorReport::UndefinedBehaviorReport(const char *IssueKind,
-                                                 Location &Loc,
-                                                 InternalScopedString &Msg)
-    : IssueKind(IssueKind), Loc(Loc), Buffer(Msg.length() + 1) {
-  // We have the common sanitizer reporting lock, so it's safe to register a
-  // new UB report.
-  RegisterUndefinedBehaviorReport(this);
-
-  // Make a copy of the diagnostic.
-  Buffer.append("%s", Msg.data());
-
-  // Let the monitor know that a report is available.
-  __ubsan_on_report();
-}
-
-static UndefinedBehaviorReport *CurrentUBR;
-
-void __ubsan::RegisterUndefinedBehaviorReport(UndefinedBehaviorReport *UBR) {
-  CurrentUBR = UBR;
-}
-
-SANITIZER_WEAK_DEFAULT_IMPL
-void __ubsan::__ubsan_on_report(void) {}
-
-void __ubsan::__ubsan_get_current_report_data(const char **OutIssueKind,
-                                              const char **OutMessage,
-                                              const char **OutFilename,
-                                              unsigned *OutLine,
-                                              unsigned *OutCol,
-                                              char **OutMemoryAddr) {
-  if (!OutIssueKind || !OutMessage || !OutFilename || !OutLine || !OutCol ||
-      !OutMemoryAddr)
-    UNREACHABLE("Invalid arguments passed to __ubsan_get_current_report_data");
-
-  InternalScopedString &Buf = CurrentUBR->Buffer;
-
-  // Ensure that the first character of the diagnostic text can't start with a
-  // lowercase letter.
-  char FirstChar = Buf.data()[0];
-  if (FirstChar >= 'a' && FirstChar <= 'z')
-    Buf.data()[0] = FirstChar - 'a' + 'A';
-
-  *OutIssueKind = CurrentUBR->IssueKind;
-  *OutMessage = Buf.data();
-  if (!CurrentUBR->Loc.isSourceLocation()) {
-    *OutFilename = "<unknown>";
-    *OutLine = *OutCol = 0;
-  } else {
-    SourceLocation SL = CurrentUBR->Loc.getSourceLocation();
-    *OutFilename = SL.getFilename();
-    *OutLine = SL.getLine();
-    *OutCol = SL.getColumn();
-  }
-
-  if (CurrentUBR->Loc.isMemoryLocation())
-    *OutMemoryAddr = (char *)CurrentUBR->Loc.getMemoryLocation();
-  else
-    *OutMemoryAddr = nullptr;
-}

Copied: compiler-rt/trunk/lib/ubsan/ubsan_monitor.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_monitor.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_monitor.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_monitor.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_monitor.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_monitor.cc ----------------------------------------*- C++ -*-===//
+//===-- ubsan_monitor.cpp ---------------------------------------*- C++ -*-===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc (removed)
@@ -1,71 +0,0 @@
-//=-- ubsan_signals_standalone.cc
-//------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Installs signal handlers and related interceptors for UBSan standalone.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#include "sanitizer_common/sanitizer_platform.h"
-#if CAN_SANITIZE_UB
-#include "interception/interception.h"
-#include "sanitizer_common/sanitizer_stacktrace.h"
-#include "ubsan_diag.h"
-#include "ubsan_init.h"
-
-// Interception of signals breaks too many things on Android.
-// * It requires that ubsan is the first dependency of the main executable for
-// the interceptors to work correctly. This complicates deployment, as it
-// prevents us from enabling ubsan on random platform modules independently.
-// * For this to work with ART VM, ubsan signal handler has to be set after the
-// debuggerd handler, but before the ART handler.
-// * Interceptors don't work at all when ubsan runtime is loaded late, ex. when
-// it is part of an APK that does not use wrap.sh method.
-#if SANITIZER_FUCHSIA || SANITIZER_ANDROID
-
-namespace __ubsan {
-void InitializeDeadlySignals() {}
-}
-
-#else
-
-#define COMMON_INTERCEPT_FUNCTION(name) INTERCEPT_FUNCTION(name)
-#include "sanitizer_common/sanitizer_signal_interceptors.inc"
-
-// TODO(yln): Temporary workaround. Will be removed.
-void ubsan_GetStackTrace(BufferedStackTrace *stack, uptr max_depth,
-                         uptr pc, uptr bp, void *context, bool fast);
-
-namespace __ubsan {
-
-static void OnStackUnwind(const SignalContext &sig, const void *,
-                          BufferedStackTrace *stack) {
-  ubsan_GetStackTrace(stack, kStackTraceMax, sig.pc, sig.bp, sig.context,
-                common_flags()->fast_unwind_on_fatal);
-}
-
-static void UBsanOnDeadlySignal(int signo, void *siginfo, void *context) {
-  HandleDeadlySignal(siginfo, context, GetTid(), &OnStackUnwind, nullptr);
-}
-
-static bool is_initialized = false;
-
-void InitializeDeadlySignals() {
-  if (is_initialized)
-    return;
-  is_initialized = true;
-  InitializeSignalInterceptors();
-  InstallDeadlySignalHandlers(&UBsanOnDeadlySignal);
-}
-
-} // namespace __ubsan
-
-#endif
-
-#endif // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_signals_standalone.cpp Wed Jul 31 10:51:05 2019
@@ -1,5 +1,4 @@
-//=-- ubsan_signals_standalone.cc
-//------------------------------------------------===//
+//=-- ubsan_signals_standalone.cpp ----------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc (removed)
@@ -1,33 +0,0 @@
-//===-- ubsan_type_hash.cc ------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Implementation of a hash table for fast checking of inheritance
-// relationships. This file is only linked into C++ compilations, and is
-// permitted to use language features which require a C++ ABI library.
-//
-// Most of the implementation lives in an ABI-specific source file
-// (ubsan_type_hash_{itanium,win}.cc).
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_type_hash.h"
-
-#include "sanitizer_common/sanitizer_common.h"
-
-/// A cache of recently-checked hashes. Mini hash table with "random" evictions.
-__ubsan::HashValue
-__ubsan::__ubsan_vptr_type_cache[__ubsan::VptrTypeCacheSize];
-
-__ubsan::DynamicTypeInfo __ubsan::getDynamicTypeInfoFromObject(void *Object) {
-  void *VtablePtr = *reinterpret_cast<void **>(Object);
-  return getDynamicTypeInfoFromVtable(VtablePtr);
-}
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_type_hash.cc ------------------------------------------------===//
+//===-- ubsan_type_hash.cpp -----------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc (removed)
@@ -1,268 +0,0 @@
-//===-- ubsan_type_hash_itanium.cc ----------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Implementation of type hashing/lookup for Itanium C++ ABI.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB && !SANITIZER_WINDOWS
-#include "ubsan_type_hash.h"
-
-#include "sanitizer_common/sanitizer_common.h"
-
-// The following are intended to be binary compatible with the definitions
-// given in the Itanium ABI. We make no attempt to be ODR-compatible with
-// those definitions, since existing ABI implementations aren't.
-
-namespace std {
-  class type_info {
-  public:
-    virtual ~type_info();
-
-    const char *__type_name;
-  };
-}
-
-namespace __cxxabiv1 {
-
-/// Type info for classes with no bases, and base class for type info for
-/// classes with bases.
-class __class_type_info : public std::type_info {
-  ~__class_type_info() override;
-};
-
-/// Type info for classes with simple single public inheritance.
-class __si_class_type_info : public __class_type_info {
-public:
-  ~__si_class_type_info() override;
-
-  const __class_type_info *__base_type;
-};
-
-class __base_class_type_info {
-public:
-  const __class_type_info *__base_type;
-  long __offset_flags;
-
-  enum __offset_flags_masks {
-    __virtual_mask = 0x1,
-    __public_mask = 0x2,
-    __offset_shift = 8
-  };
-};
-
-/// Type info for classes with multiple, virtual, or non-public inheritance.
-class __vmi_class_type_info : public __class_type_info {
-public:
-  ~__vmi_class_type_info() override;
-
-  unsigned int flags;
-  unsigned int base_count;
-  __base_class_type_info base_info[1];
-};
-
-}
-
-namespace abi = __cxxabiv1;
-
-using namespace __sanitizer;
-
-// We implement a simple two-level cache for type-checking results. For each
-// (vptr,type) pair, a hash is computed. This hash is assumed to be globally
-// unique; if it collides, we will get false negatives, but:
-//  * such a collision would have to occur on the *first* bad access,
-//  * the probability of such a collision is low (and for a 64-bit target, is
-//    negligible), and
-//  * the vptr, and thus the hash, can be affected by ASLR, so multiple runs
-//    give better coverage.
-//
-// The first caching layer is a small hash table with no chaining; buckets are
-// reused as needed. The second caching layer is a large hash table with open
-// chaining. We can freely evict from either layer since this is just a cache.
-//
-// FIXME: Make these hash table accesses thread-safe. The races here are benign:
-//        assuming the unsequenced loads and stores don't misbehave too badly,
-//        the worst case is false negatives or poor cache behavior, not false
-//        positives or crashes.
-
-/// Find a bucket to store the given hash value in.
-static __ubsan::HashValue *getTypeCacheHashTableBucket(__ubsan::HashValue V) {
-  static const unsigned HashTableSize = 65537;
-  static __ubsan::HashValue __ubsan_vptr_hash_set[HashTableSize];
-
-  unsigned First = (V & 65535) ^ 1;
-  unsigned Probe = First;
-  for (int Tries = 5; Tries; --Tries) {
-    if (!__ubsan_vptr_hash_set[Probe] || __ubsan_vptr_hash_set[Probe] == V)
-      return &__ubsan_vptr_hash_set[Probe];
-    Probe += ((V >> 16) & 65535) + 1;
-    if (Probe >= HashTableSize)
-      Probe -= HashTableSize;
-  }
-  // FIXME: Pick a random entry from the probe sequence to evict rather than
-  //        just taking the first.
-  return &__ubsan_vptr_hash_set[First];
-}
-
-/// \brief Determine whether \p Derived has a \p Base base class subobject at
-/// offset \p Offset.
-static bool isDerivedFromAtOffset(const abi::__class_type_info *Derived,
-                                  const abi::__class_type_info *Base,
-                                  sptr Offset) {
-  if (Derived->__type_name == Base->__type_name ||
-      __ubsan::checkTypeInfoEquality(Derived, Base))
-    return Offset == 0;
-
-  if (const abi::__si_class_type_info *SI =
-        dynamic_cast<const abi::__si_class_type_info*>(Derived))
-    return isDerivedFromAtOffset(SI->__base_type, Base, Offset);
-
-  const abi::__vmi_class_type_info *VTI =
-    dynamic_cast<const abi::__vmi_class_type_info*>(Derived);
-  if (!VTI)
-    // No base class subobjects.
-    return false;
-
-  // Look for a base class which is derived from \p Base at the right offset.
-  for (unsigned int base = 0; base != VTI->base_count; ++base) {
-    // FIXME: Curtail the recursion if this base can't possibly contain the
-    //        given offset.
-    sptr OffsetHere = VTI->base_info[base].__offset_flags >>
-                      abi::__base_class_type_info::__offset_shift;
-    if (VTI->base_info[base].__offset_flags &
-          abi::__base_class_type_info::__virtual_mask)
-      // For now, just punt on virtual bases and say 'yes'.
-      // FIXME: OffsetHere is the offset in the vtable of the virtual base
-      //        offset. Read the vbase offset out of the vtable and use it.
-      return true;
-    if (isDerivedFromAtOffset(VTI->base_info[base].__base_type,
-                              Base, Offset - OffsetHere))
-      return true;
-  }
-
-  return false;
-}
-
-/// \brief Find the derived-most dynamic base class of \p Derived at offset
-/// \p Offset.
-static const abi::__class_type_info *findBaseAtOffset(
-    const abi::__class_type_info *Derived, sptr Offset) {
-  if (!Offset)
-    return Derived;
-
-  if (const abi::__si_class_type_info *SI =
-        dynamic_cast<const abi::__si_class_type_info*>(Derived))
-    return findBaseAtOffset(SI->__base_type, Offset);
-
-  const abi::__vmi_class_type_info *VTI =
-    dynamic_cast<const abi::__vmi_class_type_info*>(Derived);
-  if (!VTI)
-    // No base class subobjects.
-    return nullptr;
-
-  for (unsigned int base = 0; base != VTI->base_count; ++base) {
-    sptr OffsetHere = VTI->base_info[base].__offset_flags >>
-                      abi::__base_class_type_info::__offset_shift;
-    if (VTI->base_info[base].__offset_flags &
-          abi::__base_class_type_info::__virtual_mask)
-      // FIXME: Can't handle virtual bases yet.
-      continue;
-    if (const abi::__class_type_info *Base =
-          findBaseAtOffset(VTI->base_info[base].__base_type,
-                           Offset - OffsetHere))
-      return Base;
-  }
-
-  return nullptr;
-}
-
-namespace {
-
-struct VtablePrefix {
-  /// The offset from the vptr to the start of the most-derived object.
-  /// This will only be greater than zero in some virtual base class vtables
-  /// used during object con-/destruction, and will usually be exactly zero.
-  sptr Offset;
-  /// The type_info object describing the most-derived class type.
-  std::type_info *TypeInfo;
-};
-VtablePrefix *getVtablePrefix(void *Vtable) {
-  VtablePrefix *Vptr = reinterpret_cast<VtablePrefix*>(Vtable);
-  VtablePrefix *Prefix = Vptr - 1;
-  if (!IsAccessibleMemoryRange((uptr)Prefix, sizeof(VtablePrefix)))
-    return nullptr;
-  if (!Prefix->TypeInfo)
-    // This can't possibly be a valid vtable.
-    return nullptr;
-  return Prefix;
-}
-
-}
-
-bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) {
-  // A crash anywhere within this function probably means the vptr is corrupted.
-  // FIXME: Perform these checks more cautiously.
-
-  // Check whether this is something we've evicted from the cache.
-  HashValue *Bucket = getTypeCacheHashTableBucket(Hash);
-  if (*Bucket == Hash) {
-    __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] = Hash;
-    return true;
-  }
-
-  void *VtablePtr = *reinterpret_cast<void **>(Object);
-  VtablePrefix *Vtable = getVtablePrefix(VtablePtr);
-  if (!Vtable)
-    return false;
-  if (Vtable->Offset < -VptrMaxOffsetToTop || Vtable->Offset > VptrMaxOffsetToTop) {
-    // Too large or too small offset are signs of Vtable corruption.
-    return false;
-  }
-
-  // Check that this is actually a type_info object for a class type.
-  abi::__class_type_info *Derived =
-    dynamic_cast<abi::__class_type_info*>(Vtable->TypeInfo);
-  if (!Derived)
-    return false;
-
-  abi::__class_type_info *Base = (abi::__class_type_info*)Type;
-  if (!isDerivedFromAtOffset(Derived, Base, -Vtable->Offset))
-    return false;
-
-  // Success. Cache this result.
-  __ubsan_vptr_type_cache[Hash % VptrTypeCacheSize] = Hash;
-  *Bucket = Hash;
-  return true;
-}
-
-__ubsan::DynamicTypeInfo
-__ubsan::getDynamicTypeInfoFromVtable(void *VtablePtr) {
-  VtablePrefix *Vtable = getVtablePrefix(VtablePtr);
-  if (!Vtable)
-    return DynamicTypeInfo(nullptr, 0, nullptr);
-  if (Vtable->Offset < -VptrMaxOffsetToTop || Vtable->Offset > VptrMaxOffsetToTop)
-    return DynamicTypeInfo(nullptr, Vtable->Offset, nullptr);
-  const abi::__class_type_info *ObjectType = findBaseAtOffset(
-    static_cast<const abi::__class_type_info*>(Vtable->TypeInfo),
-    -Vtable->Offset);
-  return DynamicTypeInfo(Vtable->TypeInfo->__type_name, -Vtable->Offset,
-                         ObjectType ? ObjectType->__type_name : "<unknown>");
-}
-
-bool __ubsan::checkTypeInfoEquality(const void *TypeInfo1,
-                                    const void *TypeInfo2) {
-  auto TI1 = static_cast<const std::type_info *>(TypeInfo1);
-  auto TI2 = static_cast<const std::type_info *>(TypeInfo2);
-  return SANITIZER_NON_UNIQUE_TYPEINFO && TI1->__type_name[0] != '*' &&
-         TI2->__type_name[0] != '*' &&
-         !internal_strcmp(TI1->__type_name, TI2->__type_name);
-}
-
-#endif  // CAN_SANITIZE_UB && !SANITIZER_WINDOWS

Copied: compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash_itanium.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_type_hash_itanium.cc ----------------------------------------===//
+//===-- ubsan_type_hash_itanium.cpp ---------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc (removed)
@@ -1,84 +0,0 @@
-//===-- ubsan_type_hash_win.cc --------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Implementation of type hashing/lookup for Microsoft C++ ABI.
-//
-//===----------------------------------------------------------------------===//
-
-#include "sanitizer_common/sanitizer_platform.h"
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB && SANITIZER_WINDOWS
-#include "ubsan_type_hash.h"
-
-#include "sanitizer_common/sanitizer_common.h"
-
-#include <typeinfo>
-
-struct CompleteObjectLocator {
-  int is_image_relative;
-  int offset_to_top;
-  int vfptr_offset;
-  int rtti_addr;
-  int chd_addr;
-  int obj_locator_addr;
-};
-
-struct CompleteObjectLocatorAbs {
-  int is_image_relative;
-  int offset_to_top;
-  int vfptr_offset;
-  std::type_info *rtti_addr;
-  void *chd_addr;
-  CompleteObjectLocator *obj_locator_addr;
-};
-
-bool __ubsan::checkDynamicType(void *Object, void *Type, HashValue Hash) {
-  // FIXME: Implement.
-  return false;
-}
-
-__ubsan::DynamicTypeInfo
-__ubsan::getDynamicTypeInfoFromVtable(void *VtablePtr) {
-  // The virtual table may not have a complete object locator if the object
-  // was compiled without RTTI (i.e. we might be reading from some other global
-  // laid out before the virtual table), so we need to carefully validate each
-  // pointer dereference and perform sanity checks.
-  CompleteObjectLocator **obj_locator_ptr =
-    ((CompleteObjectLocator**)VtablePtr)-1;
-  if (!IsAccessibleMemoryRange((uptr)obj_locator_ptr, sizeof(void*)))
-    return DynamicTypeInfo(0, 0, 0);
-
-  CompleteObjectLocator *obj_locator = *obj_locator_ptr;
-  if (!IsAccessibleMemoryRange((uptr)obj_locator,
-                               sizeof(CompleteObjectLocator)))
-    return DynamicTypeInfo(0, 0, 0);
-
-  std::type_info *tinfo;
-  if (obj_locator->is_image_relative == 1) {
-    char *image_base = ((char *)obj_locator) - obj_locator->obj_locator_addr;
-    tinfo = (std::type_info *)(image_base + obj_locator->rtti_addr);
-  } else if (obj_locator->is_image_relative == 0)
-    tinfo = ((CompleteObjectLocatorAbs *)obj_locator)->rtti_addr;
-  else
-    // Probably not a complete object locator.
-    return DynamicTypeInfo(0, 0, 0);
-
-  if (!IsAccessibleMemoryRange((uptr)tinfo, sizeof(std::type_info)))
-    return DynamicTypeInfo(0, 0, 0);
-
-  // Okay, this is probably a std::type_info. Request its name.
-  // FIXME: Implement a base class search like we do for Itanium.
-  return DynamicTypeInfo(tinfo->name(), obj_locator->offset_to_top,
-                         "<unknown>");
-}
-
-bool __ubsan::checkTypeInfoEquality(const void *, const void *) {
-  return false;
-}
-
-#endif  // CAN_SANITIZE_UB && SANITIZER_WINDOWS

Copied: compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_type_hash_win.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_type_hash_win.cc --------------------------------------------===//
+//===-- ubsan_type_hash_win.cpp -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_value.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_value.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_value.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_value.cc (removed)
@@ -1,112 +0,0 @@
-//===-- ubsan_value.cc ----------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// Representation of a runtime value, as marshaled from the generated code to
-// the ubsan runtime.
-//
-//===----------------------------------------------------------------------===//
-
-#include "ubsan_platform.h"
-#if CAN_SANITIZE_UB
-#include "ubsan_value.h"
-#include "sanitizer_common/sanitizer_common.h"
-#include "sanitizer_common/sanitizer_libc.h"
-
-using namespace __ubsan;
-
-SIntMax Value::getSIntValue() const {
-  CHECK(getType().isSignedIntegerTy());
-  if (isInlineInt()) {
-    // Val was zero-extended to ValueHandle. Sign-extend from original width
-    // to SIntMax.
-    const unsigned ExtraBits =
-      sizeof(SIntMax) * 8 - getType().getIntegerBitWidth();
-    return SIntMax(Val) << ExtraBits >> ExtraBits;
-  }
-  if (getType().getIntegerBitWidth() == 64)
-    return *reinterpret_cast<s64*>(Val);
-#if HAVE_INT128_T
-  if (getType().getIntegerBitWidth() == 128)
-    return *reinterpret_cast<s128*>(Val);
-#else
-  if (getType().getIntegerBitWidth() == 128)
-    UNREACHABLE("libclang_rt.ubsan was built without __int128 support");
-#endif
-  UNREACHABLE("unexpected bit width");
-}
-
-UIntMax Value::getUIntValue() const {
-  CHECK(getType().isUnsignedIntegerTy());
-  if (isInlineInt())
-    return Val;
-  if (getType().getIntegerBitWidth() == 64)
-    return *reinterpret_cast<u64*>(Val);
-#if HAVE_INT128_T
-  if (getType().getIntegerBitWidth() == 128)
-    return *reinterpret_cast<u128*>(Val);
-#else
-  if (getType().getIntegerBitWidth() == 128)
-    UNREACHABLE("libclang_rt.ubsan was built without __int128 support");
-#endif
-  UNREACHABLE("unexpected bit width");
-}
-
-UIntMax Value::getPositiveIntValue() const {
-  if (getType().isUnsignedIntegerTy())
-    return getUIntValue();
-  SIntMax Val = getSIntValue();
-  CHECK(Val >= 0);
-  return Val;
-}
-
-/// Get the floating-point value of this object, extended to a long double.
-/// These are always passed by address (our calling convention doesn't allow
-/// them to be passed in floating-point registers, so this has little cost).
-FloatMax Value::getFloatValue() const {
-  CHECK(getType().isFloatTy());
-  if (isInlineFloat()) {
-    switch (getType().getFloatBitWidth()) {
-#if 0
-      // FIXME: OpenCL / NEON 'half' type. LLVM can't lower the conversion
-      //        from '__fp16' to 'long double'.
-      case 16: {
-        __fp16 Value;
-        internal_memcpy(&Value, &Val, 4);
-        return Value;
-      }
-#endif
-      case 32: {
-        float Value;
-#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-       // For big endian the float value is in the last 4 bytes.
-       // On some targets we may only have 4 bytes so we count backwards from
-       // the end of Val to account for both the 32-bit and 64-bit cases.
-       internal_memcpy(&Value, ((const char*)(&Val + 1)) - 4, 4);
-#else
-       internal_memcpy(&Value, &Val, 4);
-#endif
-        return Value;
-      }
-      case 64: {
-        double Value;
-        internal_memcpy(&Value, &Val, 8);
-        return Value;
-      }
-    }
-  } else {
-    switch (getType().getFloatBitWidth()) {
-    case 64: return *reinterpret_cast<double*>(Val);
-    case 80: return *reinterpret_cast<long double*>(Val);
-    case 96: return *reinterpret_cast<long double*>(Val);
-    case 128: return *reinterpret_cast<long double*>(Val);
-    }
-  }
-  UNREACHABLE("unexpected floating point bit width");
-}
-
-#endif  // CAN_SANITIZE_UB

Copied: compiler-rt/trunk/lib/ubsan/ubsan_value.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_value.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_value.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_value.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_value.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_value.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_value.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_value.cc ----------------------------------------------------===//
+//===-- ubsan_value.cpp ---------------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc (removed)
@@ -1,20 +0,0 @@
-//===-- ubsan_win_dll_thunk.cc --------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines a family of thunks that should be statically linked into
-// the DLLs that have instrumentation in order to delegate the calls to the
-// shared runtime that lives in the main binary.
-// See https://github.com/google/sanitizers/issues/209 for the details.
-//===----------------------------------------------------------------------===//
-#ifdef SANITIZER_DLL_THUNK
-#include "sanitizer_common/sanitizer_win_dll_thunk.h"
-// Ubsan interface functions.
-#define INTERFACE_FUNCTION(Name) INTERCEPT_SANITIZER_FUNCTION(Name)
-#define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
-#include "ubsan_interface.inc"
-#endif // SANITIZER_DLL_THUNK

Copied: compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_win_dll_thunk.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_win_dll_thunk.cc --------------------------------------------===//
+//===-- ubsan_win_dll_thunk.cpp -------------------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc (removed)
@@ -1,20 +0,0 @@
-//===-- ubsan_win_dynamic_runtime_thunk.cc --------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file defines things that need to be present in the application modules
-// to interact with Ubsan, when it is included in a dll.
-//
-//===----------------------------------------------------------------------===//
-#ifdef SANITIZER_DYNAMIC_RUNTIME_THUNK
-#define SANITIZER_IMPORT_INTERFACE 1
-#include "sanitizer_common/sanitizer_win_defs.h"
-// Define weak alias for all weak functions imported from ubsan.
-#define INTERFACE_FUNCTION(Name)
-#define INTERFACE_WEAK_FUNCTION(Name) WIN_WEAK_IMPORT_DEF(Name)
-#include "ubsan_interface.inc"
-#endif // SANITIZER_DYNAMIC_RUNTIME_THUNK

Copied: compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_win_dynamic_runtime_thunk.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_win_dynamic_runtime_thunk.cc --------------------------------===//
+//===-- ubsan_win_dynamic_runtime_thunk.cpp -------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Removed: compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc?rev=367451&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc (removed)
@@ -1,23 +0,0 @@
-//===-- ubsan_win_weak_interception.cc ------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-// This module should be included in Ubsan when it is implemented as a shared
-// library on Windows (dll), in order to delegate the calls of weak functions to
-// the implementation in the main executable when a strong definition is
-// provided.
-//===----------------------------------------------------------------------===//
-#ifdef SANITIZER_DYNAMIC
-#include "sanitizer_common/sanitizer_win_weak_interception.h"
-#include "ubsan_flags.h"
-#include "ubsan_monitor.h"
-// Check if strong definitions for weak functions are present in the main
-// executable. If that is the case, override dll functions to point to strong
-// implementations.
-#define INTERFACE_FUNCTION(Name)
-#define INTERFACE_WEAK_FUNCTION(Name) INTERCEPT_SANITIZER_WEAK_FUNCTION(Name)
-#include "ubsan_interface.inc"
-#endif // SANITIZER_DYNAMIC

Copied: compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cpp (from r367451, compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc)
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cpp?p2=compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cpp&p1=compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc&r1=367451&r2=367452&rev=367452&view=diff
==============================================================================
--- compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cc (original)
+++ compiler-rt/trunk/lib/ubsan/ubsan_win_weak_interception.cpp Wed Jul 31 10:51:05 2019
@@ -1,4 +1,4 @@
-//===-- ubsan_win_weak_interception.cc ------------------------------------===//
+//===-- ubsan_win_weak_interception.cpp -----------------------------------===//
 //
 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
 // See https://llvm.org/LICENSE.txt for license information.

Modified: compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp?rev=367452&r1=367451&r2=367452&view=diff
==============================================================================
--- compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp (original)
+++ compiler-rt/trunk/test/ubsan/TestCases/TypeCheck/vptr-corrupted-vtable-itanium.cpp Wed Jul 31 10:51:05 2019
@@ -13,7 +13,7 @@ struct S {
   virtual int v() { return 0; }
 };
 
-// See the proper definition in ubsan_type_hash_itanium.cc
+// See the proper definition in ubsan_type_hash_itanium.cpp
 struct VtablePrefix {
   signed long Offset;
   std::type_info *TypeInfo;




More information about the llvm-commits mailing list