[clang] bff6d9b - [clang][cli] Report result of ParseLangArgs

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 8 00:56:40 PST 2021


Author: Jan Svoboda
Date: 2021-02-08T09:56:33+01:00
New Revision: bff6d9bb0f6d382d1d1826e997a6104bbe5ade73

URL: https://github.com/llvm/llvm-project/commit/bff6d9bb0f6d382d1d1826e997a6104bbe5ade73
DIFF: https://github.com/llvm/llvm-project/commit/bff6d9bb0f6d382d1d1826e997a6104bbe5ade73.diff

LOG: [clang][cli] Report result of ParseLangArgs

This patch correctly reports success/failure of `ParseLangArgs`. Besides being consistent with  other `Parse` functions, this is required to make round-tripping of `LangOptions` work.

Reviewed By: dexonsmith

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

Added: 
    

Modified: 
    clang/include/clang/Basic/Diagnostic.h
    clang/include/clang/Frontend/CompilerInvocation.h
    clang/lib/Frontend/CompilerInvocation.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Basic/Diagnostic.h b/clang/include/clang/Basic/Diagnostic.h
index 3499c551cfdf..a3cc3af5a74a 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -806,6 +806,7 @@ class DiagnosticsEngine : public RefCountedBase<DiagnosticsEngine> {
     return FatalErrorOccurred || UnrecoverableErrorOccurred;
   }
 
+  unsigned getNumErrors() const { return NumErrors; }
   unsigned getNumWarnings() const { return NumWarnings; }
 
   void setNumWarnings(unsigned NumWarnings) {

diff  --git a/clang/include/clang/Frontend/CompilerInvocation.h b/clang/include/clang/Frontend/CompilerInvocation.h
index 233569aa727b..e880713b71aa 100644
--- a/clang/include/clang/Frontend/CompilerInvocation.h
+++ b/clang/include/clang/Frontend/CompilerInvocation.h
@@ -249,7 +249,7 @@ class CompilerInvocation : public CompilerInvocationBase {
                        DiagnosticsEngine &Diags);
 
   /// Parse command line options that map to LangOptions.
-  static void ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
+  static bool ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
                             InputKind IK, const llvm::Triple &T,
                             std::vector<std::string> &Includes,
                             DiagnosticsEngine &Diags);

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index 8743da2b80ca..3f8748f83ec0 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -2642,10 +2642,12 @@ static void GenerateLangArgs(const LangOptions &Opts,
     GenerateArg(Args, OPT_fdeclare_opencl_builtins, SA);
 }
 
-void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
+bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
                                        InputKind IK, const llvm::Triple &T,
                                        std::vector<std::string> &Includes,
                                        DiagnosticsEngine &Diags) {
+  unsigned NumErrorsBefore = Diags.getNumErrors();
+
   // FIXME: Cleanup per-file based stuff.
   LangStandard::Kind LangStd = LangStandard::lang_unspecified;
   if (const Arg *A = Args.getLastArg(OPT_std_EQ)) {
@@ -3076,6 +3078,8 @@ void CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
       }
     }
   }
+
+  return Success && Diags.getNumErrors() == NumErrorsBefore;
 }
 
 static bool isStrictlyPreprocessorAction(frontend::ActionKind Action) {
@@ -3416,8 +3420,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
   } else {
     // Other LangOpts are only initialized when the input is not AST or LLVM IR.
     // FIXME: Should we really be calling this for an Language::Asm input?
-    ParseLangArgs(LangOpts, Args, DashX, T, Res.getPreprocessorOpts().Includes,
-                  Diags);
+    Success &= ParseLangArgs(LangOpts, Args, DashX, T,
+                             Res.getPreprocessorOpts().Includes, Diags);
     if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
       LangOpts.ObjCExceptions = 1;
     if (T.isOSDarwin() && DashX.isPreprocessed()) {


        


More information about the cfe-commits mailing list