aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2011-04-23 09:27:53 +0000
committerChandler Carruth <chandlerc@gmail.com>2011-04-23 09:27:53 +0000
commit1cfe3c305c0d5393fd94167808b8f5d96cd65227 (patch)
treea32085eeef5578ac9d7268ec06b5ad170a679f26 /lib
parentf1cc1d0efddc40a76ab70b074792dcd7e5ca4315 (diff)
Fix Clang's __DEPRECATED define to be controled by -Wdeprecated. This
matches GCC behavior which libstdc++ uses to limit #warning-based messages about deprecation. The machinery involves threading this through a new '-fdeprecated-macro' flag for CC1. The flag defaults to "on", similarly to -Wdeprecated. We turn the flag off in the driver when the warning is turned off (modulo matching some GCC bugs). We record this as a language option, and key the preprocessor on the option when introducing the define. A separate flag rather than a '-D' flag allows us to properly represent the difference between C and C++ builds (only C++ receives the define), and it allows the specific behavior of following -Wdeprecated without potentially impacting the set of user-provided macro flags. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130055 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Driver/Tools.cpp11
-rw-r--r--lib/Frontend/CompilerInvocation.cpp7
-rw-r--r--lib/Frontend/InitPreprocessor.cpp3
3 files changed, 20 insertions, 1 deletions
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 436a2a42a4..f5dacfa6cf 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1362,6 +1362,17 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-fconst-strings");
}
+ // GCC provides a macro definition '__DEPRECATED' when -Wdeprecated is active
+ // during C++ compilation. CC1 uses '-fdeprecated-macro' to control this.
+ // Both '-Wdeprecated' and '-fdeprecated-macro' default to on, so the flag
+ // logic here is inverted.
+ if (Args.hasFlag(options::OPT_Wno_deprecated, options::OPT_Wdeprecated,
+ false)) {
+ // GCC keeps this define even in the presence of '-w', match this behavior
+ // bug-for-bug.
+ CmdArgs.push_back("-fno-deprecated-macro");
+ }
+
// Translate GCC's misnamer '-fasm' arguments to '-fgnu-keywords'.
if (Arg *Asm = Args.getLastArg(options::OPT_fasm, options::OPT_fno_asm)) {
if (Asm->getOption().matches(options::OPT_fasm))
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 0dd2093b7a..daaaad0c2c 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -694,6 +694,8 @@ static void LangOptsToArgs(const LangOptions &Opts,
Res.push_back("-funknown-anytype");
if (Opts.DelayedTemplateParsing)
Res.push_back("-fdelayed-template-parsing");
+ if (!Opts.Deprecated)
+ Res.push_back("-fno-deprecated-macro");
}
static void PreprocessorOptsToArgs(const PreprocessorOptions &Opts,
@@ -1528,6 +1530,11 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Opts.FakeAddressSpaceMap = Args.hasArg(OPT_ffake_address_space_map);
Opts.ParseUnknownAnytype = Args.hasArg(OPT_funknown_anytype);
+ // Record whether the __DEPRECATED define was requested.
+ Opts.Deprecated = Args.hasFlag(OPT_fdeprecated_macro,
+ OPT_fno_deprecated_macro,
+ Opts.Deprecated);
+
// FIXME: Eliminate this dependency.
unsigned Opt = getOptimizationLevel(Args, IK, Diags);
Opts.Optimize = Opt != 0;
diff --git a/lib/Frontend/InitPreprocessor.cpp b/lib/Frontend/InitPreprocessor.cpp
index ff3cf4b9cd..802d66ff0e 100644
--- a/lib/Frontend/InitPreprocessor.cpp
+++ b/lib/Frontend/InitPreprocessor.cpp
@@ -319,7 +319,8 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
Builder.defineMacro("__USING_SJLJ_EXCEPTIONS__");
if (LangOpts.CPlusPlus) {
- Builder.defineMacro("__DEPRECATED");
+ if (LangOpts.Deprecated)
+ Builder.defineMacro("__DEPRECATED");
Builder.defineMacro("__GNUG__", "4");
Builder.defineMacro("__GXX_WEAK__");
if (LangOpts.GNUMode)