Revert "[Clang][Driver] Remove -M group options ..." and "[Clang] Avoid crashing...
authorJordan Rupprecht <rupprecht@google.com>
Fri, 7 Feb 2020 01:48:06 +0000 (17:48 -0800)
committerJordan Rupprecht <rupprecht@google.com>
Fri, 7 Feb 2020 01:59:15 +0000 (17:59 -0800)
This reverts commits f41ec709d9d388dc43469e6ac7f51b6313f7e4af and 5fedc2b410853a6aef05e8edf19ebfc4e071e28f. On some buildbots, Clang :: Driver/crash-report.c is broken with:

```
Command Output (stderr):
--
/home/buildslave/ps4-buildslave1/clang-with-thin-lto-ubuntu/llvm-project/clang/test/Driver/crash-report.c:48:11: error: CHECK: expected string not found in input
// CHECK: Preprocessed source(s) and associated run script(s) are located at:
          ^
<stdin>:1:1: note: scanning from here
/home/buildslave/ps4-buildslave1/clang-with-thin-lto-ubuntu/llvm-project/clang/test/Driver/crash-report.c:50:1: error: unknown type name 'BAZ'
```

Example: http://lab.llvm.org:8011/builders/clang-with-thin-lto-ubuntu/builds/21321/steps/test-stage1-compiler/logs/stdio

clang/include/clang/Driver/CC1Options.td
clang/include/clang/Lex/PreprocessorOptions.h
clang/lib/Driver/Compilation.cpp
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

index 733a108..0d0b05f 100644 (file)
@@ -866,8 +866,6 @@ def detailed_preprocessing_record : Flag<["-"], "detailed-preprocessing-record">
   HelpText<"include a detailed record of preprocessing actions">;
 def setup_static_analyzer : Flag<["-"], "setup-static-analyzer">,
   HelpText<"Set up preprocessor for static analyzer (done automatically when static analyzer is run).">;
-def disable_pragma_debug_crash : Flag<["-"], "disable-pragma-debug-crash">,
-  HelpText<"Disable any #pragma clang __debug that can lead to crashing behavior. This is meant for testing.">;
 
 //===----------------------------------------------------------------------===//
 // OpenCL Options
index c551f87..c281cd5 100644 (file)
@@ -189,9 +189,6 @@ public:
   /// Set up preprocessor for RunAnalysis action.
   bool SetUpStaticAnalyzer = false;
 
-  /// Prevents intended crashes when using #pragma clang __debug. For testing.
-  bool DisablePragmaDebugCrash = false;
-
 public:
   PreprocessorOptions() : PrecompiledPreambleBytes(0, false) {}
 
index 5247757..25aec36 100644 (file)
@@ -258,23 +258,14 @@ void Compilation::initCompilationForDiagnostics() {
 
   // Remove any user specified output.  Claim any unclaimed arguments, so as
   // to avoid emitting warnings about unused args.
-  OptSpecifier OutputOpts[] = {
-      options::OPT_o,  options::OPT_MD, options::OPT_MMD, options::OPT_M,
-      options::OPT_MM, options::OPT_MF, options::OPT_MG,  options::OPT_MJ,
-      options::OPT_MQ, options::OPT_MT, options::OPT_MV};
+  OptSpecifier OutputOpts[] = { options::OPT_o, options::OPT_MD,
+                                options::OPT_MMD };
   for (unsigned i = 0, e = llvm::array_lengthof(OutputOpts); i != e; ++i) {
     if (TranslatedArgs->hasArg(OutputOpts[i]))
       TranslatedArgs->eraseArg(OutputOpts[i]);
   }
   TranslatedArgs->ClaimAllArgs();
 
-  // Force re-creation of the toolchain Args, otherwise our modifications just
-  // above will have no effect.
-  for (auto Arg : TCArgs)
-    if (Arg.second != TranslatedArgs)
-      delete Arg.second;
-  TCArgs.clear();
-
   // Redirect stdout/stderr to /dev/null.
   Redirects = {None, {""}, {""}};
 
index 9e2279e..65039ac 100644 (file)
@@ -4750,11 +4750,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
                                                  : "-");
   }
 
-  // Give the gen diagnostics more chances to succeed, by avoiding intentional
-  // crashes.
-  if (D.CCGenDiagnostics)
-    CmdArgs.push_back("-disable-pragma-debug-crash");
-
   bool UseSeparateSections = isUseSeparateSections(Triple);
 
   if (Args.hasFlag(options::OPT_ffunction_sections,
index f95e8b4..2fd66b6 100644 (file)
@@ -3470,7 +3470,6 @@ static void ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
     Opts.LexEditorPlaceholders = false;
 
   Opts.SetUpStaticAnalyzer = Args.hasArg(OPT_setup_static_analyzer);
-  Opts.DisablePragmaDebugCrash = Args.hasArg(OPT_disable_pragma_debug_crash);
 }
 
 static void ParsePreprocessorOutputArgs(PreprocessorOutputOptions &Opts,
index a8cd18b..c881bca 100644 (file)
@@ -30,7 +30,6 @@
 #include "clang/Lex/PPCallbacks.h"
 #include "clang/Lex/Preprocessor.h"
 #include "clang/Lex/PreprocessorLexer.h"
-#include "clang/Lex/PreprocessorOptions.h"
 #include "clang/Lex/Token.h"
 #include "clang/Lex/TokenLexer.h"
 #include "llvm/ADT/ArrayRef.h"
@@ -1035,19 +1034,15 @@ struct PragmaDebugHandler : public PragmaHandler {
     IdentifierInfo *II = Tok.getIdentifierInfo();
 
     if (II->isStr("assert")) {
-      if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
-        llvm_unreachable("This is an assertion!");
+      llvm_unreachable("This is an assertion!");
     } else if (II->isStr("crash")) {
-      if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
-        LLVM_BUILTIN_TRAP;
+      LLVM_BUILTIN_TRAP;
     } else if (II->isStr("parser_crash")) {
-      if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash) {
-        Token Crasher;
-        Crasher.startToken();
-        Crasher.setKind(tok::annot_pragma_parser_crash);
-        Crasher.setAnnotationRange(SourceRange(Tok.getLocation()));
-        PP.EnterToken(Crasher, /*IsReinject*/ false);
-      }
+      Token Crasher;
+      Crasher.startToken();
+      Crasher.setKind(tok::annot_pragma_parser_crash);
+      Crasher.setAnnotationRange(SourceRange(Tok.getLocation()));
+      PP.EnterToken(Crasher, /*IsReinject*/false);
     } else if (II->isStr("dump")) {
       Token Identifier;
       PP.LexUnexpandedToken(Identifier);
@@ -1079,11 +1074,9 @@ struct PragmaDebugHandler : public PragmaHandler {
             << II->getName();
       }
     } else if (II->isStr("llvm_fatal_error")) {
-      if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
-        llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
+      llvm::report_fatal_error("#pragma clang __debug llvm_fatal_error");
     } else if (II->isStr("llvm_unreachable")) {
-      if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
-        llvm_unreachable("#pragma clang __debug llvm_unreachable");
+      llvm_unreachable("#pragma clang __debug llvm_unreachable");
     } else if (II->isStr("macro")) {
       Token MacroName;
       PP.LexUnexpandedToken(MacroName);
@@ -1110,8 +1103,7 @@ struct PragmaDebugHandler : public PragmaHandler {
       }
       M->dump();
     } else if (II->isStr("overflow_stack")) {
-      if (!PP.getPreprocessorOpts().DisablePragmaDebugCrash)
-        DebugOverflowStack();
+      DebugOverflowStack();
     } else if (II->isStr("captured")) {
       HandleCaptured(PP);
     } else {
index 641850d..711b04e 100644 (file)
@@ -1,56 +1,25 @@
 // RUN: rm -rf %t
 // RUN: mkdir %t
-
-// RUN: echo '-fsyntax-only                                              \
+// RUN: env TMPDIR=%t TEMP=%t TMP=%t RC_DEBUG_OPTIONS=1                  \
+// RUN:  CC_PRINT_HEADERS=1 CC_LOG_DIAGNOSTICS=1                         \
+// RUN:  not %clang -fsyntax-only %s                                     \
 // RUN:  -F/tmp/ -I /tmp/ -idirafter /tmp/ -iquote /tmp/ -isystem /tmp/  \
 // RUN:  -iprefix /the/prefix -iwithprefix /tmp -iwithprefixbefore /tmp/ \
 // RUN:  -Xclang -internal-isystem -Xclang /tmp/                         \
 // RUN:  -Xclang -internal-externc-isystem -Xclang /tmp/                 \
 // RUN:  -Xclang -main-file-name -Xclang foo.c                           \
-// RUN:  -DFOO=BAR -DBAR="BAZ QUX"' > %t.rsp
-
-// 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 -DPARSER 2>&1 | FileCheck %s
+// RUN:  -DFOO=BAR -DBAR="BAZ QUX" 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
-
-// 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 -DCRASH 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
-
-// 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 -DASSERT 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
-
-// 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 -DUNREACHABLE 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 ASSERT
-#pragma clang __debug assert
-#elif UNREACHABLE
-#pragma clang __debug llvm_unreachable
-#endif
-
 // CHECK: Preprocessed source(s) and associated run script(s) are located at:
 // CHECK-NEXT: note: diagnostic msg: {{.*}}crash-report-{{.*}}.c
 FOO
 // CHECKSRC: FOO
 // CHECKSH: # Crash reproducer
-// CHECKSH-NEXT: # Driver args: {{.*}}"-fsyntax-only"
+// CHECKSH-NEXT: # Driver args: "-fsyntax-only"
 // CHECKSH-SAME: "-D" "FOO=BAR"
 // CHECKSH-SAME: "-D" "BAR=BAZ QUX"
 // CHECKSH-NEXT: # Original command: {{.*$}}
index c572b25..a5ca3e5 100644 (file)
@@ -1,4 +1,3 @@
-
 // RUN: rm -f "%t.d" "%t1.s" "%t2.s" "%t3.s" "%t4.s" "%t5.s"
 //
 // RUN: touch %t.s