Skip to content

Commit 1fac68b

Browse files
committed
ArrayRef'ized CompilerInvocation::CreateFromArgs
Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66797 llvm-svn: 370122
1 parent d313666 commit 1fac68b

File tree

8 files changed

+12
-25
lines changed

8 files changed

+12
-25
lines changed

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "clang/Frontend/PreprocessorOutputOptions.h"
2222
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
2323
#include "llvm/ADT/IntrusiveRefCntPtr.h"
24+
#include "llvm/ADT/ArrayRef.h"
2425
#include <memory>
2526
#include <string>
2627

@@ -153,12 +154,8 @@ class CompilerInvocation : public CompilerInvocationBase {
153154
/// one of the vaild-to-access (albeit arbitrary) states.
154155
///
155156
/// \param [out] Res - The resulting invocation.
156-
/// \param ArgBegin - The first element in the argument vector.
157-
/// \param ArgEnd - The last element in the argument vector.
158-
/// \param Diags - The diagnostic engine to use for errors.
159157
static bool CreateFromArgs(CompilerInvocation &Res,
160-
const char* const *ArgBegin,
161-
const char* const *ArgEnd,
158+
ArrayRef<const char *> CommandLineArgs,
162159
DiagnosticsEngine &Diags);
163160

164161
/// Get the directory where the compiler headers

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,18 +3370,16 @@ static void ParseTargetArgs(TargetOptions &Opts, ArgList &Args,
33703370
}
33713371

33723372
bool CompilerInvocation::CreateFromArgs(CompilerInvocation &Res,
3373-
const char *const *ArgBegin,
3374-
const char *const *ArgEnd,
3373+
ArrayRef<const char *> CommandLineArgs,
33753374
DiagnosticsEngine &Diags) {
33763375
bool Success = true;
33773376

33783377
// Parse the arguments.
33793378
std::unique_ptr<OptTable> Opts = createDriverOptTable();
33803379
const unsigned IncludedFlagsBitmask = options::CC1Option;
33813380
unsigned MissingArgIndex, MissingArgCount;
3382-
InputArgList Args =
3383-
Opts->ParseArgs(llvm::makeArrayRef(ArgBegin, ArgEnd), MissingArgIndex,
3384-
MissingArgCount, IncludedFlagsBitmask);
3381+
InputArgList Args = Opts->ParseArgs(CommandLineArgs, MissingArgIndex,
3382+
MissingArgCount, IncludedFlagsBitmask);
33853383
LangOptions &LangOpts = *Res.getLangOpts();
33863384

33873385
// Check for missing argument error.

clang/lib/Frontend/CreateInvocationFromCommandLine.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ std::unique_ptr<CompilerInvocation> clang::createInvocationFromCommandLine(
9090

9191
const ArgStringList &CCArgs = Cmd.getArguments();
9292
auto CI = std::make_unique<CompilerInvocation>();
93-
if (!CompilerInvocation::CreateFromArgs(
94-
*CI, const_cast<const char **>(CCArgs.data()),
95-
const_cast<const char **>(CCArgs.data()) + CCArgs.size(), *Diags) &&
93+
if (!CompilerInvocation::CreateFromArgs(*CI, CCArgs, *Diags) &&
9694
!ShouldRecoverOnErorrs)
9795
return nullptr;
9896
return CI;

clang/lib/Tooling/Tooling.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,7 @@ CompilerInvocation *newInvocation(
118118
DiagnosticsEngine *Diagnostics, const llvm::opt::ArgStringList &CC1Args) {
119119
assert(!CC1Args.empty() && "Must at least contain the program name!");
120120
CompilerInvocation *Invocation = new CompilerInvocation;
121-
CompilerInvocation::CreateFromArgs(
122-
*Invocation, CC1Args.data() + 1, CC1Args.data() + CC1Args.size(),
123-
*Diagnostics);
121+
CompilerInvocation::CreateFromArgs(*Invocation, CC1Args, *Diagnostics);
124122
Invocation->getFrontendOpts().DisableFree = false;
125123
Invocation->getCodeGenOpts().DisableFree = false;
126124
return Invocation;

clang/tools/arcmt-test/arcmt-test.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ static bool checkForMigration(StringRef resourcesPath,
121121
}
122122

123123
CompilerInvocation CI;
124-
if (!CompilerInvocation::CreateFromArgs(CI, Args.begin(), Args.end(), *Diags))
124+
if (!CompilerInvocation::CreateFromArgs(CI, Args, *Diags))
125125
return true;
126126

127127
if (CI.getFrontendOpts().Inputs.empty()) {
@@ -160,8 +160,7 @@ static bool performTransformations(StringRef resourcesPath,
160160
new DiagnosticsEngine(DiagID, &*DiagOpts, &*DiagClient));
161161

162162
CompilerInvocation origCI;
163-
if (!CompilerInvocation::CreateFromArgs(origCI, Args.begin(), Args.end(),
164-
*TopDiags))
163+
if (!CompilerInvocation::CreateFromArgs(origCI, Args, *TopDiags))
165164
return true;
166165

167166
if (origCI.getFrontendOpts().Inputs.empty()) {

clang/tools/clang-import-test/clang-import-test.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
168168
std::vector<const char *> ClangArgv(ClangArgs.size());
169169
std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(),
170170
[](const std::string &s) -> const char * { return s.data(); });
171-
CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(),
172-
&ClangArgv.data()[ClangArgv.size()],
173-
Ins->getDiagnostics());
171+
CompilerInvocation::CreateFromArgs(*Inv, ClangArgv, Ins->getDiagnostics());
174172

175173
{
176174
using namespace driver::types;

clang/tools/driver/cc1_main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ int cc1_main(ArrayRef<const char *> Argv, const char *Argv0, void *MainAddr) {
213213
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
214214
TextDiagnosticBuffer *DiagsBuffer = new TextDiagnosticBuffer;
215215
DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagsBuffer);
216-
bool Success = CompilerInvocation::CreateFromArgs(
217-
Clang->getInvocation(), Argv.begin(), Argv.end(), Diags);
216+
bool Success =
217+
CompilerInvocation::CreateFromArgs(Clang->getInvocation(), Argv, Diags);
218218

219219
if (Clang->getFrontendOpts().TimeTrace) {
220220
llvm::timeTraceProfilerInitialize(

clang/unittests/AST/ExternalASTSourceTest.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ bool testExternalASTSource(ExternalASTSource *Source,
5353
"test.cc", MemoryBuffer::getMemBuffer(FileContents).release());
5454
const char *Args[] = { "test.cc" };
5555
CompilerInvocation::CreateFromArgs(*Invocation, Args,
56-
Args + array_lengthof(Args),
5756
Compiler.getDiagnostics());
5857
Compiler.setInvocation(std::move(Invocation));
5958

0 commit comments

Comments
 (0)