/// environment ready to process a single file. This returns true on error.
///
bool InitializePreprocessor(Preprocessor &PP,
- const PreprocessorInitOptions& InitOptions);
+ const PreprocessorInitOptions& InitOptions,
+ bool undef_macros);
} // end namespace clang
II.getInputArg().renderAsInput(Args, CmdArgs);
}
+ Args.AddAllArgs(CmdArgs, options::OPT_undef);
+
const char *Exec =
Args.MakeArgString(getToolChain().GetProgramPath(C, "clang-cc"));
Dest.addCommand(new Command(JA, Exec, CmdArgs));
/// environment ready to process a single file. This returns true on error.
///
bool clang::InitializePreprocessor(Preprocessor &PP,
- const PreprocessorInitOptions &InitOpts) {
+ const PreprocessorInitOptions &InitOpts,
+ bool undef_macros) {
std::vector<char> PredefineBuffer;
const char *LineDirective = "# 1 \"<built-in>\" 3\n";
LineDirective, LineDirective+strlen(LineDirective));
// Install things like __POWERPC__, __GNUC__, etc into the macro table.
- InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
- PredefineBuffer);
+ if (!undef_macros)
+ InitializePredefinedMacros(PP.getTargetInfo(), PP.getLangOptions(),
+ PredefineBuffer);
// Add on the predefines from the driver. Wrap in a #line directive to report
// that they come from the command line.
--- /dev/null
+// RUN: clang-cc -dM -undef -Dfoo=1 -E %s | FileCheck %s
+
+// CHECK-NOT: #define __clang__
+// CHECK: #define foo 1
// -A... - Play with #assertions
// -undef - Undefine all predefined macros
+static llvm::cl::opt<bool>
+undef_macros("undef", llvm::cl::value_desc("macro"), llvm::cl::desc("undef all system defines"));
+
static llvm::cl::list<std::string>
D_macros("D", llvm::cl::value_desc("macro"), llvm::cl::Prefix,
llvm::cl::desc("Predefine the specified macro"));
PreprocessorInitOptions InitOpts;
InitializePreprocessorInitOptions(InitOpts);
- if (InitializePreprocessor(*PP, InitOpts))
+ if (InitializePreprocessor(*PP, InitOpts, undef_macros))
return 0;
return PP.take();