Implement support for the -undef command line option, patch by
Roman Divacky! PR5363 llvm-svn: 85932
This commit is contained in:
parent
4f10559ba8
commit
e9d7d78ab3
@ -63,7 +63,8 @@ public:
|
||||
/// 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
|
||||
|
||||
|
||||
@ -1015,6 +1015,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
|
||||
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));
|
||||
|
||||
@ -443,7 +443,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
|
||||
/// 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";
|
||||
@ -451,8 +452,9 @@ bool clang::InitializePreprocessor(Preprocessor &PP,
|
||||
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.
|
||||
|
||||
4
clang/test/Preprocessor/macro_undef.c
Normal file
4
clang/test/Preprocessor/macro_undef.c
Normal file
@ -0,0 +1,4 @@
|
||||
// RUN: clang-cc -dM -undef -Dfoo=1 -E %s | FileCheck %s
|
||||
|
||||
// CHECK-NOT: #define __clang__
|
||||
// CHECK: #define foo 1
|
||||
@ -932,6 +932,9 @@ static bool InitializeSourceManager(Preprocessor &PP,
|
||||
// -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"));
|
||||
@ -1243,7 +1246,7 @@ public:
|
||||
|
||||
PreprocessorInitOptions InitOpts;
|
||||
InitializePreprocessorInitOptions(InitOpts);
|
||||
if (InitializePreprocessor(*PP, InitOpts))
|
||||
if (InitializePreprocessor(*PP, InitOpts, undef_macros))
|
||||
return 0;
|
||||
|
||||
return PP.take();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user