mirror of https://github.com/microsoft/clang.git
Handle -D arguments ending in a backslash.
We translate these into #define directives; to preserve gcc-compatible semantics (where the expanded macro includes the backslash), we add an extra "\\\n" to the end of the synthesized "#define". <rdar://problem/14810220> git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189511 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3f93d4ce2b
commit
62c90e1889
|
@ -29,6 +29,12 @@
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
using namespace clang;
|
using namespace clang;
|
||||||
|
|
||||||
|
static bool MacroBodyEndsInBackslash(StringRef MacroBody) {
|
||||||
|
while (!MacroBody.empty() && isWhitespace(MacroBody.back()))
|
||||||
|
MacroBody = MacroBody.drop_back();
|
||||||
|
return !MacroBody.empty() && MacroBody.back() == '\\';
|
||||||
|
}
|
||||||
|
|
||||||
// Append a #define line to Buf for Macro. Macro should be of the form XXX,
|
// Append a #define line to Buf for Macro. Macro should be of the form XXX,
|
||||||
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
|
// in which case we emit "#define XXX 1" or "XXX=Y z W" in which case we emit
|
||||||
// "#define XXX Y z W". To get a #define with no value, use "XXX=".
|
// "#define XXX Y z W". To get a #define with no value, use "XXX=".
|
||||||
|
@ -43,7 +49,14 @@ static void DefineBuiltinMacro(MacroBuilder &Builder, StringRef Macro,
|
||||||
if (End != StringRef::npos)
|
if (End != StringRef::npos)
|
||||||
Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
|
Diags.Report(diag::warn_fe_macro_contains_embedded_newline)
|
||||||
<< MacroName;
|
<< MacroName;
|
||||||
Builder.defineMacro(MacroName, MacroBody.substr(0, End));
|
MacroBody = MacroBody.substr(0, End);
|
||||||
|
// We handle macro bodies which end in a backslash by appending an extra
|
||||||
|
// backslash+newline. This makes sure we don't accidentally treat the
|
||||||
|
// backslash as a line continuation marker.
|
||||||
|
if (MacroBodyEndsInBackslash(MacroBody))
|
||||||
|
Builder.defineMacro(MacroName, Twine(MacroBody) + "\\\n");
|
||||||
|
else
|
||||||
|
Builder.defineMacro(MacroName, MacroBody);
|
||||||
} else {
|
} else {
|
||||||
// Push "macroname 1".
|
// Push "macroname 1".
|
||||||
Builder.defineMacro(Macro);
|
Builder.defineMacro(Macro);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
// RUN: %clang_cc1 -E %s -Dfoo='bar\' | FileCheck %s
|
||||||
|
// CHECK: TTA bar\ TTB
|
||||||
|
TTA foo TTB
|
Loading…
Reference in New Issue