Add support for passing the main file name down to the assembler

for location information.

Part of PR14624

llvm-svn: 170391
This commit is contained in:
Eric Christopher 2012-12-18 00:31:10 +00:00
parent 906da23229
commit 45f2e71571
5 changed files with 39 additions and 14 deletions

View File

@ -37,6 +37,8 @@ def L : Flag<["-"], "L">,
HelpText<"Save temporary labels in the symbol table. "
"Note this may change .s semantics, it should almost never be used "
"on compiler generated code!">;
def main_file_name : Separate<["-"], "main-file-name">,
HelpText<"Main file name to use for debug info">;
//===----------------------------------------------------------------------===//
// Frontend Options

View File

@ -3278,6 +3278,11 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-filetype");
CmdArgs.push_back("obj");
// Set the main file name, so that debug info works even with
// -save-temps or preprocessed assembly.
CmdArgs.push_back("-main-file-name");
CmdArgs.push_back(Clang::getBaseInputName(Args, Inputs));
if (UseRelaxAll(C, Args))
CmdArgs.push_back("-relax-all");

View File

@ -30,6 +30,7 @@ namespace tools {
/// \brief Clang compiler tool.
class LLVM_LIBRARY_VISIBILITY Clang : public Tool {
public:
static const char *getBaseInputName(const ArgList &Args,
const InputInfoList &Inputs);
static const char *getBaseInputStem(const ArgList &Args,
@ -37,6 +38,7 @@ namespace tools {
static const char *getDependencyFileName(const ArgList &Args,
const InputInfoList &Inputs);
private:
void AddPreprocessingOptions(Compilation &C,
const Driver &D,
const ArgList &Args,

View File

@ -0,0 +1,12 @@
// REQUIRES: clang-driver
// RUN: %clang -### -c -save-temps -integrated-as -g %s 2>&1 \
// RUN: | FileCheck %s
// CHECK: main-file-name
#ifdef(1)
foo:
nop
nop
nop
#endif

View File

@ -84,6 +84,7 @@ struct AssemblerInvocation {
unsigned GenDwarfForAssembly : 1;
std::string DwarfDebugFlags;
std::string DebugCompilationDir;
std::string MainFileName;
/// @}
/// @name Frontend Options
@ -183,6 +184,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
Opts.GenDwarfForAssembly = Args->hasArg(OPT_g);
Opts.DwarfDebugFlags = Args->getLastArgValue(OPT_dwarf_debug_flags);
Opts.DebugCompilationDir = Args->getLastArgValue(OPT_fdebug_compilation_dir);
Opts.MainFileName = Args->getLastArgValue(OPT_main_file_name);
// Frontend Options
if (Args->hasArg(OPT_INPUT)) {
@ -309,6 +311,8 @@ static bool ExecuteAssembler(AssemblerInvocation &Opts,
Ctx.setDwarfDebugFlags(StringRef(Opts.DwarfDebugFlags));
if (!Opts.DebugCompilationDir.empty())
Ctx.setCompilationDir(Opts.DebugCompilationDir);
if (!Opts.MainFileName.empty())
Ctx.setMainFileName(StringRef(Opts.MainFileName));
// Build up the feature string from the target feature list.
std::string FS;