Skip to content

Commit

Permalink
[clang] - Simplify tools::SplitDebugName.
Browse files Browse the repository at this point in the history
This is an updated version of the D54576, which was reverted.

Problem was that SplitDebugName calls the InputInfo::getFilename
which asserts if InputInfo given is not of type Filename:

const char *getFilename() const {
  assert(isFilename() && "Invalid accessor.");
  return Data.Filename;
}
At the same time at that point, it can be of type Nothing and
we need to use getBaseInput(), like original code did.

Differential revision: https://reviews.llvm.org/D55006

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@348352 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
George Rimar committed Dec 5, 2018
1 parent 0635952 commit f0f0244
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3949,7 +3949,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
const char *SplitDWARFOut;
if (SplitDWARF) {
CmdArgs.push_back("-split-dwarf-file");
SplitDWARFOut = SplitDebugName(Args, Input, Output);
SplitDWARFOut = SplitDebugName(Args, Output);
CmdArgs.push_back(SplitDWARFOut);
}

Expand Down Expand Up @@ -5916,7 +5916,7 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
if ((getDebugFissionKind(D, Args, A) == DwarfFissionKind::Split) &&
(T.isOSLinux() || T.isOSFuchsia())) {
CmdArgs.push_back("-split-dwarf-file");
CmdArgs.push_back(SplitDebugName(Args, Input, Output));
CmdArgs.push_back(SplitDebugName(Args, Output));
}

assert(Input.isFilename() && "Invalid input.");
Expand Down
24 changes: 8 additions & 16 deletions lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,26 +808,18 @@ bool tools::areOptimizationsEnabled(const ArgList &Args) {
return false;
}

const char *tools::SplitDebugName(const ArgList &Args, const InputInfo &Input,
const char *tools::SplitDebugName(const ArgList &Args,
const InputInfo &Output) {
SmallString<128> F(Output.isFilename()
? Output.getFilename()
: llvm::sys::path::stem(Output.getBaseInput()));

if (Arg *A = Args.getLastArg(options::OPT_gsplit_dwarf_EQ))
if (StringRef(A->getValue()) == "single")
return Args.MakeArgString(Output.getFilename());
return Args.MakeArgString(F);

Arg *FinalOutput = Args.getLastArg(options::OPT_o);
if (FinalOutput && Args.hasArg(options::OPT_c)) {
SmallString<128> T(FinalOutput->getValue());
llvm::sys::path::replace_extension(T, "dwo");
return Args.MakeArgString(T);
} else {
// Use the compilation dir.
SmallString<128> T(
Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput()));
llvm::sys::path::replace_extension(F, "dwo");
T += F;
return Args.MakeArgString(F);
}
llvm::sys::path::replace_extension(F, "dwo");
return Args.MakeArgString(F);
}

void tools::SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/ToolChains/CommonArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void AddHIPLinkerScript(const ToolChain &TC, Compilation &C,
const Tool &T);

const char *SplitDebugName(const llvm::opt::ArgList &Args,
const InputInfo &Input, const InputInfo &Output);
const InputInfo &Output);

void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
const JobAction &JA, const llvm::opt::ArgList &Args,
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ void tools::gnutools::Assembler::ConstructJob(Compilation &C,
if (Args.hasArg(options::OPT_gsplit_dwarf) &&
getToolChain().getTriple().isOSLinux())
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
SplitDebugName(Args, Inputs[0], Output));
SplitDebugName(Args, Output));
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void tools::MinGW::Assembler::ConstructJob(Compilation &C, const JobAction &JA,

if (Args.hasArg(options::OPT_gsplit_dwarf))
SplitDebugInfo(getToolChain(), C, *this, JA, Args, Output,
SplitDebugName(Args, Inputs[0], Output));
SplitDebugName(Args, Output));
}

void tools::MinGW::Linker::AddLibGCC(const ArgList &Args,
Expand Down
4 changes: 4 additions & 0 deletions test/Tooling/clang-check-extra-arg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@

// CHECK: unknown warning option '-Wunimplemented-warning-before'
// CHECK: unknown warning option '-Wunimplemented-warning'

// Check we do not crash with -extra-arg=-gsplit-dwarf (we did, under linux).
// RUN: clang-check "%s" -extra-arg=-gsplit-dwarf -- -c

void a(){}

0 comments on commit f0f0244

Please sign in to comment.