Skip to content

Commit

Permalink
ArrayRef'ized CompilerInvocation::CreateFromArgs
Browse files Browse the repository at this point in the history
Subscribers: cfe-commits

Tags: #clang

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

llvm-svn: 370122
  • Loading branch information
gribozavr committed Aug 27, 2019
1 parent d313666 commit 1fac68b
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 25 deletions.
7 changes: 2 additions & 5 deletions clang/include/clang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <memory>
#include <string>

Expand Down Expand Up @@ -153,12 +154,8 @@ class CompilerInvocation : public CompilerInvocationBase {
/// 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<const char *> CommandLineArgs,
DiagnosticsEngine &Diags);

/// Get the directory where the compiler headers
Expand Down
8 changes: 3 additions & 5 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3370,18 +3370,16 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
}

bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
const char *const *ArgBegin,
const char *const *ArgEnd,
ArrayRef<const char *> CommandLineArgs,
DiagnosticsEngine &Diags) {
bool Success = true;

// Parse the arguments.
std::unique_ptr<OptTable> 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.
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Frontend/CreateInvocationFromCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine(

const ArgStringList &CCArgs = Cmd.getArguments();
auto CI = std::make_unique<CompilerInvocation>();
if (!CompilerInvocation::CreateFromArgs(
*CI, const_cast<const char **>(CCArgs.data()),
const_cast<const char **>(CCArgs.data()) + CCArgs.size(), *Diags) &&
if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) &&
!ShouldRecoverOnErorrs)
return nullptr;
return CI;
Expand Down
4 changes: 1 addition & 3 deletions clang/lib/Tooling/Tooling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions clang/tools/arcmt-test/arcmt-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 1 addition & 3 deletions clang/tools/clang-import-test/clang-import-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
std::vector<const char *> 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;
Expand Down
4 changes: 2 additions & 2 deletions clang/tools/driver/cc1_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
IntrusiveRefCntPtr<DiagnosticOptions> 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(
Expand Down
1 change: 0 additions & 1 deletion clang/unittests/AST/ExternalASTSourceTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down

0 comments on commit 1fac68b

Please sign in to comment.