hliao added a comment.

In D79344#2026349 <https://reviews.llvm.org/D79344#2026349>, @tra wrote:

> Here's a slightly smaller variant which may be a good clue for tracking down 
> the root cause. This one fails with:
>
>   var.cc:6:14: error: no matching function for call to 'copysign'
>     double g = copysign(0, g);
>                ^~~~~~~~
>   var.cc:5:56: note: candidate template ignored: substitution failure [with e 
> = int, f = double]: reference to __host__ variable 'b' in __device__ function
>   __attribute__((device)) typename c<a<f>::b, double>::d copysign(e, f) {
>                                            ~             ^
>   1 error generated when compiling for sm_60.
>
>
> I suspect that it's handling of non-type template parameter that may be 
> breaking things in both cases.
>
>   template <typename> struct a { static const bool b = true; };
>   template <bool, class> struct c;
>   template <class h> struct c<true, h> { typedef h d; };
>   template <typename e, typename f>
>   __attribute__((device)) typename c<a<f>::b, double>::d copysign(e, f) {
>     double g = copysign(0, g);
>   }
>


My bad. We need a similar logic in the call check to skip the template not 
instantiated yet, i.e.

  diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
  index 583e588e4bd..467136f4579 100644
  --- a/clang/lib/Sema/SemaCUDA.cpp
  +++ b/clang/lib/Sema/SemaCUDA.cpp
  @@ -910,6 +910,10 @@ bool Sema::CheckCUDAAccess(SourceLocation Loc, 
FunctionDecl *Caller,
     assert(getLangOpts().CUDA && "Should only be called during CUDA 
compilation");
     assert(VD && isNonLocalVariable(VD) && "Variable must be a non-local 
one.");
   
  +  auto &ExprEvalCtx = ExprEvalContexts.back();
  +  if (ExprEvalCtx.isUnevaluated() || ExprEvalCtx.isConstantEvaluated())
  +    return true;
  +
     // FIXME: Is bailing out early correct here?  Should we instead assume that
     // the caller is a global initializer?
     if (!Caller)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79344/new/

https://reviews.llvm.org/D79344



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to