From: Dmitri Gribenko Date: Tue, 27 Aug 2019 22:13:31 +0000 (+0000) Subject: ArrayRef'ized CompilerInvocation::CreateFromArgs X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=610ec02d6d37fe332e142d131378545b41db879d;p=clang ArrayRef'ized CompilerInvocation::CreateFromArgs Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66797 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@370122 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Frontend/CompilerInvocation.h b/include/clang/Frontend/CompilerInvocation.h index f0280232af..f3253d5b40 100644 --- a/include/clang/Frontend/CompilerInvocation.h +++ b/include/clang/Frontend/CompilerInvocation.h @@ -21,6 +21,7 @@ #include "clang/Frontend/PreprocessorOutputOptions.h" #include "clang/StaticAnalyzer/Core/AnalyzerOptions.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/ArrayRef.h" #include #include @@ -153,12 +154,8 @@ public: /// one of the vaild-to-access (albeit arbitrary) states. /// /// \param [out] Res - The resulting invocation. - /// \param ArgBegin - The first element in the argument vector. - /// \param ArgEnd - The last element in the argument vector. - /// \param Diags - The diagnostic engine to use for errors. static bool CreateFromArgs(CompilerInvocation &Res, - const char* const *ArgBegin, - const char* const *ArgEnd, + ArrayRef CommandLineArgs, DiagnosticsEngine &Diags); /// Get the directory where the compiler headers diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 0e222b95dd..86c66f3a07 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -3370,8 +3370,7 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args, } bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, - const char *const *ArgBegin, - const char *const *ArgEnd, + ArrayRef CommandLineArgs, DiagnosticsEngine &Diags) { bool Success = true; @@ -3379,9 +3378,8 @@ bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res, std::unique_ptr Opts = createDriverOptTable(); const unsigned IncludedFlagsBitmask = options::CC1Option; unsigned MissingArgIndex, MissingArgCount; - InputArgList Args = - Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex, - MissingArgCount, IncludedFlagsBitmask); + InputArgList Args = Opts->ParseArgs(CommandLineArgs, MissingArgIndex, + MissingArgCount, IncludedFlagsBitmask); LangOptions &LangOpts = *Res.getLangOpts(); // Check for missing argument error. diff --git a/lib/Frontend/CreateInvocationFromCommandLine.cpp b/lib/Frontend/CreateInvocationFromCommandLine.cpp index ea7de7a411..ab62b633cd 100644 --- a/lib/Frontend/CreateInvocationFromCommandLine.cpp +++ b/lib/Frontend/CreateInvocationFromCommandLine.cpp @@ -90,9 +90,7 @@ std::unique_ptr clang::createInvocationFromCommandLine( const ArgStringList &CCArgs = Cmd.getArguments(); auto CI = std::make_unique(); - if (!CompilerInvocation::CreateFromArgs( - *CI, const_cast(CCArgs.data()), - const_cast(CCArgs.data()) + CCArgs.size(), *Diags) && + if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) && !ShouldRecoverOnErorrs) return nullptr; return CI; diff --git a/lib/Tooling/Tooling.cpp b/lib/Tooling/Tooling.cpp index 291df0ae33..b21fc33ac3 100644 --- a/lib/Tooling/Tooling.cpp +++ b/lib/Tooling/Tooling.cpp @@ -118,9 +118,7 @@ CompilerInvocation *newInvocation( DiagnosticsEngine *Diagnostics, const llvm::opt::ArgStringList &CC1Args) { assert(!CC1Args.empty() && "Must at least contain the program name!"); CompilerInvocation *Invocation = new CompilerInvocation; - CompilerInvocation::CreateFromArgs( - *Invocation, CC1Args.data() + 1, CC1Args.data() + CC1Args.size(), - *Diagnostics); + CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, *Diagnostics); Invocation->getFrontendOpts().DisableFree = false; Invocation->getCodeGenOpts().DisableFree = false; return Invocation; diff --git a/tools/arcmt-test/arcmt-test.cpp b/tools/arcmt-test/arcmt-test.cpp index 5f075f860f..c4ba12d4f7 100644 --- a/tools/arcmt-test/arcmt-test.cpp +++ b/tools/arcmt-test/arcmt-test.cpp @@ -121,7 +121,7 @@ static bool checkForMigration(StringRef resourcesPath, } CompilerInvocation CI; - if (!CompilerInvocation::CreateFromArgs(CI, Args.begin(), Args.end(), *Diags)) + if (!CompilerInvocation::CreateFromArgs(CI, Args, *Diags)) return true; if (CI.getFrontendOpts().Inputs.empty()) { @@ -160,8 +160,7 @@ static bool performTransformations(StringRef resourcesPath, new DiagnosticsEngine(DiagID, &*DiagOpts, &*DiagClient)); CompilerInvocation origCI; - if (!CompilerInvocation::CreateFromArgs(origCI, Args.begin(), Args.end(), - *TopDiags)) + if (!CompilerInvocation::CreateFromArgs(origCI, Args, *TopDiags)) return true; if (origCI.getFrontendOpts().Inputs.empty()) { diff --git a/tools/clang-import-test/clang-import-test.cpp b/tools/clang-import-test/clang-import-test.cpp index a4d3e11c98..e8124d6242 100644 --- a/tools/clang-import-test/clang-import-test.cpp +++ b/tools/clang-import-test/clang-import-test.cpp @@ -168,9 +168,7 @@ std::unique_ptr BuildCompilerInstance() { std::vector ClangArgv(ClangArgs.size()); std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), [](const std::string &s) -> const char * { return s.data(); }); - CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(), - &ClangArgv.data()[ClangArgv.size()], - Ins->getDiagnostics()); + CompilerInvocation::CreateFromArgs(*Inv, ClangArgv, Ins->getDiagnostics()); { using namespace driver::types; diff --git a/tools/driver/cc1_main.cpp b/tools/driver/cc1_main.cpp index d160b64f97..29767b880b 100644 --- a/tools/driver/cc1_main.cpp +++ b/tools/driver/cc1_main.cpp @@ -213,8 +213,8 @@ int cc1_main(ArrayRef Argv, const char *Argv0, void *MainAddr) { IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer; DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer); - bool Success = CompilerInvocation::CreateFromArgs( - Clang->getInvocation(), Argv.begin(), Argv.end(), Diags); + bool Success = + CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Argv, Diags); if (Clang->getFrontendOpts().TimeTrace) { llvm::timeTraceProfilerInitialize( diff --git a/unittests/AST/ExternalASTSourceTest.cpp b/unittests/AST/ExternalASTSourceTest.cpp index ba8a8cd376..8b70be664e 100644 --- a/unittests/AST/ExternalASTSourceTest.cpp +++ b/unittests/AST/ExternalASTSourceTest.cpp @@ -53,7 +53,6 @@ bool testExternalASTSource(ExternalASTSource *Source, "test.cc", MemoryBuffer::getMemBuffer(FileContents).release()); const char *Args[] = { "test.cc" }; CompilerInvocation::CreateFromArgs(*Invocation, Args, - Args + array_lengthof(Args), Compiler.getDiagnostics()); Compiler.setInvocation(std::move(Invocation));