[cfe-commits] r85073 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaExpr.cpp lib/Sema/SemaType.cpp test/Sema/attr-deprecated.c

Douglas Gregor dgregor at apple.com
Mon Oct 26 07:37:56 PDT 2009


Comment below...

Sent from my iPhone

On Oct 25, 2009, at 3:31 PM, Chris Lattner <sabre at nondot.org> wrote:

> Author: lattner
> Date: Sun Oct 25 17:31:57 2009
> New Revision: 85073
>
> URL: http://llvm.org/viewvc/llvm-project?rev=85073&view=rev
> Log:
> Implement rdar://6756623 - use of deprecated type in deprecated  
> typedef should not warn
>
> Modified:
>    cfe/trunk/lib/Sema/Sema.h
>    cfe/trunk/lib/Sema/SemaExpr.cpp
>    cfe/trunk/lib/Sema/SemaType.cpp
>    cfe/trunk/test/Sema/attr-deprecated.c
>
> Modified: cfe/trunk/lib/Sema/Sema.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=85073&r1=85072&r2=85073&view=diff
>
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/lib/Sema/Sema.h (original)
> +++ cfe/trunk/lib/Sema/Sema.h Sun Oct 25 17:31:57 2009
> @@ -1583,7 +1583,8 @@
>   // 
> === 
> -------------------------------------------------------------------- 
> ===//
>   // Expression Parsing Callbacks: SemaExpr.cpp.
>
> -  bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc);
> +  bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
> +                         bool IgnoreDeprecated = false);
>   bool DiagnosePropertyAccessorMismatch(ObjCPropertyDecl *PD,
>                                         ObjCMethodDecl *Getter,
>                                         SourceLocation Loc);
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=85073&r1=85072&r2=85073&view=diff
>
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Oct 25 17:31:57 2009
> @@ -37,20 +37,24 @@
> /// used, or produce an error (and return true) if a C++0x deleted
> /// function is being used.
> ///
> +/// If IgnoreDeprecated is set to true, this should not want about  
> deprecated
> +/// decls.
> +///
> /// \returns true if there was an error (this declaration cannot be
> /// referenced), false otherwise.
> -bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc) {
> +///
> +bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
> +                             bool IgnoreDeprecated) {
>   // See if the decl is deprecated.
>   if (D->getAttr<DeprecatedAttr>()) {
>     // Implementing deprecated stuff requires referencing deprecated
> -    // stuff. Don't warn if we are implementing a deprecated
> -    // construct.
> -    bool isSilenced = false;
> +    // stuff. Don't warn if we are implementing a deprecated  
> construct.
> +    bool isSilenced = IgnoreDeprecated;
>
>     if (NamedDecl *ND = getCurFunctionOrMethodDecl()) {
>       // If this reference happens *in* a deprecated function or  
> method, don't
>       // warn.
> -      isSilenced = ND->getAttr<DeprecatedAttr>();
> +      isSilenced |= ND->getAttr<DeprecatedAttr>() != 0;
>
>       // If this is an Objective-C method implementation, check to  
> see if the
>       // method was deprecated on the declaration, not the definition.
>
> Modified: cfe/trunk/lib/Sema/SemaType.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=85073&r1=85072&r2=85073&view=diff
>
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/lib/Sema/SemaType.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaType.cpp Sun Oct 25 17:31:57 2009
> @@ -67,6 +67,16 @@
>   return false;
> }
>
> +/// isDeclaratorDeprecated - Return true if the declarator is  
> deprecated.
> +/// We do not want to warn about use of deprecated types (e.g.  
> typedefs) when
> +/// defining a declaration that is itself deprecated.
> +static bool isDeclaratorDeprecated(const Declarator &D) {
> +  for (const AttributeList *AL = D.getAttributes(); AL; AL = AL- 
> >getNext())
> +    if (AL->getKind() == AttributeList::AT_deprecated)
> +      return true;
> +  return false;
> +}
> +

This won't always work, because the deprecated attribute could be  
merged from a previous function declaration (so it never gets attached  
to this declarator).

There are other tricky cases involving template-ids and 'typename'  
types that this also won't handle. I think John was planning to tackle  
these cases as soon as he finishes the TypeLoc work (which is needed  
to get this completely right).

> /// \brief Convert the specified declspec to the appropriate type
> /// object.
> /// \param D  the declarator containing the declaration specifier.
> @@ -237,7 +247,8 @@
>     }
>
>     // If the type is deprecated or unavailable, diagnose it.
> -    TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc());
> +    TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc(),
> +                              isDeclaratorDeprecated(TheDeclarator));
>
>     assert(DS.getTypeSpecWidth() == 0 && DS.getTypeSpecComplex() ==  
> 0 &&
>            DS.getTypeSpecSign() == 0 && "No qualifiers on tag  
> names!");
> @@ -298,15 +309,18 @@
>         TheDeclarator.setInvalidType(true);
>
>       // If the type is deprecated or unavailable, diagnose it.
> -      TheSema.DiagnoseUseOfDecl(TDT->getDecl(),  
> DS.getTypeSpecTypeLoc());
> +      TheSema.DiagnoseUseOfDecl(TDT->getDecl(),  
> DS.getTypeSpecTypeLoc(),
> +                                isDeclaratorDeprecated 
> (TheDeclarator));
>     } else if (ObjCInterfaceType *OIT = dyn_cast<ObjCInterfaceType> 
> (Result)) {
>       // If the type is deprecated or unavailable, diagnose it.
> -      TheSema.DiagnoseUseOfDecl(OIT->getDecl(),  
> DS.getTypeSpecTypeLoc());
> +      TheSema.DiagnoseUseOfDecl(OIT->getDecl(),  
> DS.getTypeSpecTypeLoc(),
> +                                isDeclaratorDeprecated 
> (TheDeclarator));
>     } else if (ObjCObjectPointerType *DPT =
>                  dyn_cast<ObjCObjectPointerType>(Result)) {
>       // If the type is deprecated or unavailable, diagnose it.
>       if (ObjCInterfaceDecl *D = DPT->getInterfaceDecl())
> -        TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc());
> +        TheSema.DiagnoseUseOfDecl(D, DS.getTypeSpecTypeLoc(),
> +                                  isDeclaratorDeprecated 
> (TheDeclarator));
>     }
>
>
>
> Modified: cfe/trunk/test/Sema/attr-deprecated.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated.c?rev=85073&r1=85072&r2=85073&view=diff
>
> === 
> === 
> === 
> =====================================================================
> --- cfe/trunk/test/Sema/attr-deprecated.c (original)
> +++ cfe/trunk/test/Sema/attr-deprecated.c Sun Oct 25 17:31:57 2009
> @@ -49,3 +49,9 @@
>
> struct bar_dep *test3;   // expected-warning {{'bar_dep' is  
> deprecated}}
>
> +
> +// These should not warn because the actually declaration itself is  
> deprecated.
> +// rdar://6756623
> +foo_dep *test4 __attribute__((deprecated));
> +struct bar_dep *test5 __attribute__((deprecated));
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list