[clang] e22677b - Reapply "[clang][cli] Report result of ParseLangArgs"

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 8 04:15:13 PST 2021


Author: Jan Svoboda
Date: 2021-02-08T13:14:43+01:00
New Revision: e22677bbdbdc725463feaa1aa50f179964ce442b

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

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

This reverts commit 6039f821 and reapplies bff6d9bb.

Clang's Index/implicit-attrs.m test invokes c-index-test with -fobjc-arc. This flag is not compatible with -fobjc-runtime=gcc, which gets implied on Linux.

The original commit uncovered this by correctly reporting issues when parsing -cc1 command line.

This commit fixes the test to explicitly provide ObjectiveC runtime compatible with ARC.

Added: 
    

Modified: 
    clang/include/clang/Basic/Diagnostic.h
    clang/include/clang/Frontend/CompilerInvocation.h
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/test/Index/implicit-attrs.m

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 f4104a35c0fd..e131804b11d1 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()) {

diff  --git a/clang/test/Index/implicit-attrs.m b/clang/test/Index/implicit-attrs.m
index ca651cdb791f..bd5192d150b3 100644
--- a/clang/test/Index/implicit-attrs.m
+++ b/clang/test/Index/implicit-attrs.m
@@ -2,5 +2,5 @@ @interface Foo
 -(instancetype)init;
 @end
 
-// RUN: env CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES=1 c-index-test -test-print-decl-attributes %s -fobjc-arc | FileCheck %s
+// RUN: env CINDEXTEST_VISIT_IMPLICIT_ATTRIBUTES=1 c-index-test -test-print-decl-attributes %s -fobjc-runtime=macosx-10.7 -fobjc-arc | FileCheck %s
 // CHECK: ObjCInstanceMethodDecl=init:2:16 attribute(ns_consumes_self)= attribute(ns_returns_retained)=


        


More information about the cfe-commits mailing list