[cfe-commits] r171888 - in /cfe/trunk: lib/Sema/Sema.cpp lib/Sema/SemaExpr.cpp test/SemaCXX/warn-func-not-needed.cpp

Dmitri Gribenko gribozavr at gmail.com
Tue Jan 8 11:53:49 PST 2013


On Tue, Jan 8, 2013 at 9:43 PM, Rafael Espindola
<rafael.espindola at gmail.com> wrote:
> Author: rafael
> Date: Tue Jan  8 13:43:34 2013
> New Revision: 171888
>
> URL: http://llvm.org/viewvc/llvm-project?rev=171888&view=rev
> Log:
> Mark all subsequent decls used.
>
> In the source
>
>   static void f();
>   static void f();
>   template<typename T>
>   static void g() {
>     f();
>   }
>   static void f() {
>   }
>   void h() {
>     g<int>();
>   }
>
> the call to f refers to the second decl, but it is only marked used at the end
> of the translation unit during instantiation, after the third f decl has been
> linked in.
>
> With this patch we mark all subsequent decls used, so that it is easy to check
> if a symbol is used or not.
>
> Modified:
>     cfe/trunk/lib/Sema/Sema.cpp
>     cfe/trunk/lib/Sema/SemaExpr.cpp
>     cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
>
> Modified: cfe/trunk/lib/Sema/Sema.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=171888&r1=171887&r2=171888&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/Sema.cpp (original)
> +++ cfe/trunk/lib/Sema/Sema.cpp Tue Jan  8 13:43:34 2013
> @@ -328,11 +328,7 @@
>
>  /// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector.
>  static bool ShouldRemoveFromUnused(Sema *SemaRef, const DeclaratorDecl *D) {
> -  // Template instantiation can happen at the end of the translation unit
> -  // and it sets the canonical (first) decl to used. Normal uses set the last
> -  // decl at the time to used and subsequent decl inherit the flag. The net
> -  // result is that we need to check both ends of the decl chain.
> -  if (D->isUsed() || D->getMostRecentDecl()->isUsed())
> +  if (D->getMostRecentDecl()->isUsed())
>      return true;
>
>    if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=171888&r1=171887&r2=171888&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Tue Jan  8 13:43:34 2013
> @@ -10495,7 +10495,18 @@
>      if (old.isInvalid()) old = Loc;
>    }
>
> -  Func->setUsed(true);
> +  // Normally the must current decl is marked used while processing the use and
> +  // any subsequent decls are marked used by decl merging. This fails with
> +  // template instantiation since marking can happen at the end of the file
> +  // and, because of the two phase lookup, this function is called with at
> +  // decl in the middle of a decl chain. We loop to maintain the invariant
> +  // that once a decl is used, all decls after it are also used.
> +  for (FunctionDecl *F = Func->getMostRecentDecl();;) {
> +    F->setUsed(true);
> +    if (F == Func)
> +      break;
> +    F = F->getPreviousDecl();

Maybe move that line to 'for(;;<here>)' ?

Dmitri

> +  }
>  }
>
>  static void
>
> Modified: cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp?rev=171888&r1=171887&r2=171888&view=diff
> ==============================================================================
> --- cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp (original)
> +++ cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp Tue Jan  8 13:43:34 2013
> @@ -28,3 +28,17 @@
>      g<int>();
>    }
>  }
> +
> +namespace test4 {
> +  static void f();
> +  static void f();
> +  template<typename T>
> +  static void g() {
> +    f();
> +  }
> +  static void f() {
> +  }
> +  void h() {
> +    g<int>();
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits



-- 
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/



More information about the cfe-commits mailing list