Commit fd04cb43 authored by Alexandre Ganea's avatar Alexandre Ganea Committed by Hans Wennborg
Browse files

[Clang][Driver] After default -fintegrated-cc1, make...

[Clang][Driver] After default -fintegrated-cc1, make llvm::report_fatal_error() generate preprocessed source + reproducer.sh again.

Added a test for #pragma clang __debug llvm_fatal_error to test for the original issue.
Added llvm::sys::Process::Exit() and replaced ::exit() in places where it was appropriate. This new function would call the current CrashRecoveryContext if one is running on the same thread; or call ::exit() otherwise.

Fixes PR44705.

Differential Revision: https://reviews.llvm.org/D73742

(cherry picked from commit faace365)
parent aeba7ba9
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -21,12 +21,20 @@
// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s

// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1                  \
// RUN:  CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1                         \
// RUN:  not %clang %s @%t.rsp -DFATAL 2>&1 | FileCheck %s
// RUN: cat %t/crash-report-*.c | FileCheck --check-prefix=CHECKSRC %s
// RUN: cat %t/crash-report-*.sh | FileCheck --check-prefix=CHECKSH %s

// REQUIRES: crash-recovery

#ifdef PARSER
#pragma clang __debug parser_crash
#elif CRASH
#pragma clang __debug crash
#elif FATAL
#pragma clang __debug llvm_fatal_error
#endif

// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+2 −1
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
@@ -69,7 +70,7 @@ static void LLVMErrorHandler(void *UserData, const std::string &Message,
  // We cannot recover from llvm errors.  When reporting a fatal error, exit
  // with status 70 to generate crash diagnostics.  For BSD systems this is
  // defined as an internal software error.  Otherwise, exit with status 1.
  exit(GenCrashDiag ? 70 : 1);
  llvm::sys::Process::Exit(GenCrashDiag ? 70 : 1);
}

#ifdef CLANG_HAVE_RLIMITS
+2 −1
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@
#include "llvm/Support/Host.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/TargetRegistry.h"
@@ -547,7 +548,7 @@ static void LLVMErrorHandler(void *UserData, const std::string &Message,
  Diags.Report(diag::err_fe_error_backend) << Message;

  // We cannot recover from llvm errors.
  exit(1);
  sys::Process::Exit(1);
}

int cc1as_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
+5 −0
Original line number Diff line number Diff line
@@ -97,6 +97,11 @@ public:
    return RunSafelyOnThread([&]() { Fn(UserData); }, RequestedStackSize);
  }

  /// Explicitly trigger a crash recovery in the current process, and
  /// return failure from RunSafely(). This function does not return.
  LLVM_ATTRIBUTE_NORETURN
  void HandleExit(int RetCode);

  /// In case of a crash, this is the crash identifier.
  int RetCode = 0;

+6 −0
Original line number Diff line number Diff line
@@ -201,6 +201,12 @@ public:
  /// Get the result of a process wide random number generator. The
  /// generator will be automatically seeded in non-deterministic fashion.
  static unsigned GetRandomNumber();

  /// Equivalent to ::exit(), except when running inside a CrashRecoveryContext.
  /// In that case, the control flow will resume after RunSafely(), like for a
  /// crash, rather than exiting the current process.
  LLVM_ATTRIBUTE_NORETURN
  static void Exit(int RetCode);
};

}
Loading