[cfe-commits] r130055 - in /cfe/trunk: include/clang/Basic/LangOptions.h include/clang/Driver/CC1Options.td include/clang/Driver/Options.td lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp lib/Frontend/InitPreprocessor.cpp test/Driver/cla

Chandler Carruth chandlerc at gmail.com
Sat Apr 23 13:11:49 PDT 2011


On Sat, Apr 23, 2011 at 8:08 AM, Douglas Gregor <dgregor at apple.com> wrote:

>
> On Apr 23, 2011, at 2:27 AM, Chandler Carruth wrote:
>
> > Author: chandlerc
> > Date: Sat Apr 23 04:27:53 2011
> > New Revision: 130055
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=130055&view=rev
> > Log:
> > 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.
> >
> > Modified:
> >    cfe/trunk/include/clang/Basic/LangOptions.h
> >    cfe/trunk/include/clang/Driver/CC1Options.td
> >    cfe/trunk/include/clang/Driver/Options.td
> >    cfe/trunk/lib/Driver/Tools.cpp
> >    cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> >    cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> >    cfe/trunk/test/Driver/clang_f_opts.c
> >
> > Modified: cfe/trunk/include/clang/Basic/LangOptions.h
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/LangOptions.h?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/Basic/LangOptions.h (original)
> > +++ cfe/trunk/include/clang/Basic/LangOptions.h Sat Apr 23 04:27:53 2011
> > @@ -89,6 +89,8 @@
> >                                   // used (instead of C99 semantics).
> >   unsigned NoInline          : 1; // Should __NO_INLINE__ be defined.
> >
> > +  unsigned Deprecated        : 1; // Should __DEPRECATED be defined.
> > +
> >   unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap
> layout
> >                                   // for __weak/__strong ivars.
> >
> > @@ -213,6 +215,8 @@
> >     GNUInline = 0;
> >     NoInline = 0;
> >
> > +    Deprecated = 1;  // -Wdeprecated defaults to "on".
> > +
> >     CharIsSigned = 1;
> >     ShortWChar = 0;
> >     ShortEnums = 0;
>
> The Deprecated bit needs to be read/written by the ASTReader/ASTWriter.
>

Doh, forgot about that. Fixed in r130071.


>
> > Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> > +++ cfe/trunk/include/clang/Driver/CC1Options.td Sat Apr 23 04:27:53 2011
> > @@ -539,6 +539,10 @@
> >            "translation unit ">;
> > def funknown_anytype : Flag<"-funknown-anytype">,
> >   HelpText<"Enable parser support for the __unknown_anytype type; for
> testing purposes only">;
> > +def fdeprecated_macro : Flag<"-fdeprecated-macro">,
> > +  HelpText<"Defines the __DEPRECATED macro in C++ compilations">;
> > +def fno_deprecated_macro : Flag<"-fno-deprecated-macro">,
> > +  HelpText<"Undefines the __DEPRECATED macro in C++ compilations">;
>
> It seems like -fdeprecated-macro should always define __DEPRECATED, and
> it's the driver that should do the language-based decision of whether to add
> it.
>

Sure, hoisted this logic up into the driver in r130066. I had thought it
would make the logic ugly, but its actually pretty clean. Thanks for the
suggestion.


>
> >
> //===----------------------------------------------------------------------===//
> > // Header Search Options
> >
> > Modified: cfe/trunk/include/clang/Driver/Options.td
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/include/clang/Driver/Options.td (original)
> > +++ cfe/trunk/include/clang/Driver/Options.td Sat Apr 23 04:27:53 2011
> > @@ -166,6 +166,8 @@
> >   HelpText<"Pass the comma separated arguments in <arg> to the
> assembler">,
> >   MetaVarName<"<arg>">;
> > def Wall : Flag<"-Wall">, Group<W_Group>;
> > +def Wdeprecated : Flag<"-Wdeprecated">, Group<W_Group>;
> > +def Wno_deprecated : Flag<"-Wno-deprecated">, Group<W_Group>;
> > def Wextra : Flag<"-Wextra">, Group<W_Group>;
> > def Wl_COMMA : CommaJoined<"-Wl,">, Flags<[LinkerInput, RenderAsInput]>,
> >   HelpText<"Pass the comma separated arguments in <arg> to the linker">,
> >
> > Modified: cfe/trunk/lib/Driver/Tools.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Driver/Tools.cpp (original)
> > +++ cfe/trunk/lib/Driver/Tools.cpp Sat Apr 23 04:27:53 2011
> > @@ -1362,6 +1362,17 @@
> >     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))
> >
> > Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> > +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Sat Apr 23 04:27:53
> 2011
> > @@ -694,6 +694,8 @@
> >     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 @@
> >   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;
> >
> > Modified: cfe/trunk/lib/Frontend/InitPreprocessor.cpp
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/InitPreprocessor.cpp?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/lib/Frontend/InitPreprocessor.cpp (original)
> > +++ cfe/trunk/lib/Frontend/InitPreprocessor.cpp Sat Apr 23 04:27:53 2011
> > @@ -319,7 +319,8 @@
> >     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)
> >
> > Modified: cfe/trunk/test/Driver/clang_f_opts.c
> > URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang_f_opts.c?rev=130055&r1=130054&r2=130055&view=diff
> >
> ==============================================================================
> > --- cfe/trunk/test/Driver/clang_f_opts.c (original)
> > +++ cfe/trunk/test/Driver/clang_f_opts.c Sat Apr 23 04:27:53 2011
> > @@ -19,3 +19,11 @@
> > // WRITE-STRINGS2-NOT: -fconst-strings
> > // RUN: %clang -### -S -Wwrite-strings -w %s 2>&1 | FileCheck
> -check-prefix=WRITE-STRINGS3 %s
> > // WRITE-STRINGS3: -fconst-strings
> > +
> > +// RUN: %clang -### -c %s 2>&1 | FileCheck
> -check-prefix=DEPRECATED-ON-CHECK %s
> > +// RUN: %clang -### -c -Wdeprecated %s 2>&1 | FileCheck
> -check-prefix=DEPRECATED-ON-CHECK %s
> > +// RUN: %clang -### -c -Wno-deprecated %s 2>&1 | FileCheck
> -check-prefix=DEPRECATED-OFF-CHECK %s
> > +// RUN: %clang -### -c -Wno-deprecated -Wdeprecated %s 2>&1 | FileCheck
> -check-prefix=DEPRECATED-ON-CHECK %s
> > +// RUN: %clang -### -c -w %s 2>&1 | FileCheck
> -check-prefix=DEPRECATED-ON-CHECK %s
> > +// DEPRECATED-OFF-CHECK: -fno-deprecated-macro
> > +// DEPRECATED-ON-CHECK-NOT: -fno-deprecated-macro
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20110423/c8010eb8/attachment.html>


More information about the cfe-commits mailing list