diff options
author | Bob Wilson <bob.wilson@apple.com> | 2014-11-04 22:28:48 +0000 |
---|---|---|
committer | Bob Wilson <bob.wilson@apple.com> | 2014-11-04 22:28:48 +0000 |
commit | d5aad2a1e07ce20b789a92d8d95bc4b8d9a2d0b6 (patch) | |
tree | 7df990441ce0b50496c4fe20f2ee637cb83651df /clang/lib/Driver/Tools.cpp | |
parent | f9660f0712b8b020ac414a3dc405a6c4f0dd78ad (diff) | |
download | llvm-d5aad2a1e07ce20b789a92d8d95bc4b8d9a2d0b6.zip llvm-d5aad2a1e07ce20b789a92d8d95bc4b8d9a2d0b6.tar.gz llvm-d5aad2a1e07ce20b789a92d8d95bc4b8d9a2d0b6.tar.bz2 |
Use backslashes to escape spaces and other backslashes in -dwarf-debug-flags.
The command line options are specified in a space-separated list that is an
argument to -dwarf-debug-flags, so that breaks if there are spaces in the
options. This feature came from Apple's internal version of GCC, so I went back
to check how llvm-gcc handled this and matched that behavior.
rdar://problem/18775420
llvm-svn: 221309
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r-- | clang/lib/Driver/Tools.cpp | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index d11fa4e..174df12 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -83,6 +83,23 @@ static void CheckCodeGenerationOptions(const Driver &D, const ArgList &Args) { << A->getAsString(Args) << "-static"; } +// Add backslashes to escape spaces and other backslashes. +// This is used for the space-separated argument list specified with +// the -dwarf-debug-flags option. +static void EscapeSpacesAndBackslashes(const char *Arg, + SmallVectorImpl<char> &Res) { + for ( ; *Arg; ++Arg) { + switch (*Arg) { + default: break; + case ' ': + case '\\': + Res.push_back('\\'); + break; + } + Res.push_back(*Arg); + } +} + // Quote target names for inclusion in GNU Make dependency files. // Only the characters '$', '#', ' ', '\t' are quoted. static void QuoteTarget(StringRef Target, @@ -4465,8 +4482,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, SmallString<256> Flags; Flags += Exec; for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { + SmallString<128> EscapedArg; + EscapeSpacesAndBackslashes(OriginalArgs[i], EscapedArg); Flags += " "; - Flags += OriginalArgs[i]; + Flags += EscapedArg; } CmdArgs.push_back("-dwarf-debug-flags"); CmdArgs.push_back(Args.MakeArgString(Flags.str())); @@ -4896,8 +4915,10 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, const char *Exec = getToolChain().getDriver().getClangProgramPath(); Flags += Exec; for (unsigned i = 0, e = OriginalArgs.size(); i != e; ++i) { + SmallString<128> EscapedArg; + EscapeSpacesAndBackslashes(OriginalArgs[i], EscapedArg); Flags += " "; - Flags += OriginalArgs[i]; + Flags += EscapedArg; } CmdArgs.push_back("-dwarf-debug-flags"); CmdArgs.push_back(Args.MakeArgString(Flags.str())); |