Skip to content

Commit

Permalink
Merge commit '83452650490e' from llvm.org/main into next
Browse files Browse the repository at this point in the history
 Conflicts:
	clang/lib/Frontend/CompilerInvocation.cpp
  • Loading branch information
jansvoboda11 committed Aug 4, 2023
2 parents 77085d4 + 8345265 commit 23433a9
Show file tree
Hide file tree
Showing 2 changed files with 367 additions and 376 deletions.
40 changes: 31 additions & 9 deletions clang/include/clang/Frontend/CompilerInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class CompilerInvocation : public CompilerInvocationRefBase,
/// identifying the conditions under which the module was built.
std::string getModuleHash(DiagnosticsEngine &Diags) const;

using StringAllocator = llvm::function_ref<const char *(const llvm::Twine &)>;
using StringAllocator = llvm::function_ref<const char *(const Twine &)>;
/// Generate cc1-compatible command line arguments from this instance.
///
/// \param [out] Args - The generated arguments. Note that the caller is
Expand All @@ -252,7 +252,21 @@ class CompilerInvocation : public CompilerInvocationRefBase,
/// command line argument and return a pointer to the newly allocated string.
/// The returned pointer is what gets appended to Args.
void generateCC1CommandLine(llvm::SmallVectorImpl<const char *> &Args,
StringAllocator SA) const;
StringAllocator SA) const {
generateCC1CommandLine([&](const Twine &Arg) {
// No need to allocate static string literals.
Args.push_back(Arg.isSingleStringLiteral()
? Arg.getSingleStringRef().data()
: SA(Arg));
});
}

using ArgumentConsumer = llvm::function_ref<void(const Twine &)>;
/// Generate cc1-compatible command line arguments from this instance.
///
/// \param Consumer - Callback that gets invoked for every single generated
/// command line argument.
void generateCC1CommandLine(ArgumentConsumer Consumer) const;

/// Generate cc1-compatible command line arguments from this instance,
/// wrapping the result as a std::vector<std::string>.
Expand Down Expand Up @@ -284,9 +298,18 @@ class CompilerInvocation : public CompilerInvocationRefBase,
DiagnosticsEngine &Diags);

/// Generate command line options from CASOptions.
static void GenerateCASArgs(const CASOptions &Opts,
ArgumentConsumer Consumer);
static void GenerateCASArgs(const CASOptions &Opts,
SmallVectorImpl<const char *> &Args,
CompilerInvocation::StringAllocator SA);
CompilerInvocation::StringAllocator SA) {
GenerateCASArgs(Opts, [&](const Twine &Arg) {
// No need to allocate static string literals.
Args.push_back(Arg.isSingleStringLiteral()
? Arg.getSingleStringRef().data()
: SA(Arg));
});
}

private:
static bool CreateFromArgsImpl(CompilerInvocation &Res,
Expand All @@ -295,8 +318,8 @@ class CompilerInvocation : public CompilerInvocationRefBase,

/// Generate command line options from DiagnosticOptions.
static void GenerateDiagnosticArgs(const DiagnosticOptions &Opts,
SmallVectorImpl<const char *> &Args,
StringAllocator SA, bool DefaultDiagColor);
ArgumentConsumer Consumer,
bool DefaultDiagColor);

/// Parse command line options that map to LangOptions.
static bool ParseLangArgs(LangOptions &Opts, llvm::opt::ArgList &Args,
Expand All @@ -307,8 +330,7 @@ class CompilerInvocation : public CompilerInvocationRefBase,
public:
/// Generate command line options from LangOptions.
static void GenerateLangArgs(const LangOptions &Opts,
SmallVectorImpl<const char *> &Args,
StringAllocator SA, const llvm::Triple &T,
ArgumentConsumer Consumer, const llvm::Triple &T,
InputKind IK);

private:
Expand All @@ -324,8 +346,8 @@ class CompilerInvocation : public CompilerInvocationRefBase,

// Generate command line options from CodeGenOptions.
static void GenerateCodeGenArgs(const CodeGenOptions &Opts,
SmallVectorImpl<const char *> &Args,
StringAllocator SA, const llvm::Triple &T,
ArgumentConsumer Consumer,
const llvm::Triple &T,
const std::string &OutputFile,
const LangOptions *LangOpts);
};
Expand Down

0 comments on commit 23433a9

Please sign in to comment.