Fix PR5982, a refacto in checking for '=' in a -D argument.

llvm-svn: 93088
This commit is contained in:
Daniel Dunbar 2010-01-10 00:46:21 +00:00
parent 620327d66b
commit d281a7146a
2 changed files with 9 additions and 8 deletions

View File

@ -27,19 +27,16 @@ using namespace clang;
// 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=".
static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro, static void DefineBuiltinMacro(MacroBuilder &Builder, llvm::StringRef Macro,
Diagnostic *Diags = 0) { Diagnostic &Diags) {
std::pair<llvm::StringRef, llvm::StringRef> MacroPair = Macro.split('='); std::pair<llvm::StringRef, llvm::StringRef> MacroPair = Macro.split('=');
llvm::StringRef MacroName = MacroPair.first; llvm::StringRef MacroName = MacroPair.first;
llvm::StringRef MacroBody = MacroPair.second; llvm::StringRef MacroBody = MacroPair.second;
if (!MacroBody.empty()) { if (MacroName.size() != Macro.size()) {
// Per GCC -D semantics, the macro ends at \n if it exists. // Per GCC -D semantics, the macro ends at \n if it exists.
llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r"); llvm::StringRef::size_type End = MacroBody.find_first_of("\n\r");
if (End != llvm::StringRef::npos) { if (End != llvm::StringRef::npos)
assert(Diags && "Unexpected macro with embedded newline!"); 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)); Builder.defineMacro(MacroName, MacroBody.substr(0, End));
} else { } else {
// Push "macroname 1". // Push "macroname 1".
@ -490,7 +487,7 @@ void clang::InitializePreprocessor(Preprocessor &PP,
Builder.undefineMacro(InitOpts.Macros[i].first); Builder.undefineMacro(InitOpts.Macros[i].first);
else else
DefineBuiltinMacro(Builder, InitOpts.Macros[i].first, DefineBuiltinMacro(Builder, InitOpts.Macros[i].first,
&PP.getDiagnostics()); PP.getDiagnostics());
} }
// If -imacros are specified, include them now. These are processed before // If -imacros are specified, include them now. These are processed before

View File

@ -0,0 +1,4 @@
// RUN: %clang_cc1 -DA= -DB=1 -verify -fsyntax-only %s
int a[(B A) == 1 ? 1 : -1];