[Clang] Avoid crashing when generating crash diagnostics when '#pragma clang __debug...
authorAlexandre Ganea <alexandre.ganea@ubisoft.com>
Thu, 6 Feb 2020 20:47:42 +0000 (15:47 -0500)
committerAlexandre Ganea <alexandre.ganea@ubisoft.com>
Thu, 6 Feb 2020 20:48:51 +0000 (15:48 -0500)
commit5fedc2b410853a6aef05e8edf19ebfc4e071e28f
tree78a06b99fb7fe1975f6bac87b21772fa2bc76c03
parent733923a97dff2d2c6096d6b17c3987421be69ab6
[Clang] Avoid crashing when generating crash diagnostics when '#pragma clang __debug [assert|crash|parser_crash|llvm_fatal_error|llvm_unreachable|overflow_stack]' are used

Previously, when the above '#pragma clang __debug' were used, Driver::generateCompilationDiagnostics() wouldn't work as expected.
The 'clang -E' process created for diagnostics would crash, because it would reach again the intended crash in Pragma.cpp, PragmaDebugHandler::HandlePragma() while preprocessing.

When generating crash diagnostics, we now disable the intended crashing behavior with a new cc1 flag -disable-pragma-debug-crash.

Notes:
- #pragma clang __debug llvm_report_fatal isn't currently tested by crash-report.c, because it needs exit() to be handled differently in -fintegrated-cc1 mode. See https://reviews.llvm.org/D73742 for an upcoming fix.
- This is also needed to further validate that -MF is removed from the 'clang -E ' crash diagnostic cmd-line (currently not the case). See https://reviews.llvm.org/D74076 for an upcoming fix.

Differential Revision: https://reviews.llvm.org/D74070
clang/include/clang/Driver/CC1Options.td
clang/include/clang/Lex/PreprocessorOptions.h
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Frontend/CompilerInvocation.cpp
clang/lib/Lex/Pragma.cpp
clang/test/Driver/crash-report.c
clang/test/Driver/output-file-cleanup.c