[PATCH] D56411: [CUDA][HIP][Sema] Fix template kernel with function as template parameter

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 24 12:25:55 PST 2019


yaxunl added a comment.

In D56411#1365745 <https://reviews.llvm.org/D56411#1365745>, @rjmccall wrote:

> In D56411#1365727 <https://reviews.llvm.org/D56411#1365727>, @yaxunl wrote:
>
> > In D56411#1360010 <https://reviews.llvm.org/D56411#1360010>, @rjmccall wrote:
> >
> > > I think the diagnostic should come during instantiation when you find an evaluated use of a host function within a device function.
> >
> >
> > It seems the body of function template is checked only during parsing of the definition of the template itself. When a function
> >  template is instantiated, the body of the instantiated function is not checked again.
>
>
> No, that's not correct.  However, it's checked somewhat differently, and it's possible that the existing diagnostic is not set up to fire along all common paths.  Try moving the diagnostic to `MarkFunctionReferenced`, and note that `OdrUse` will be `false` in all the unevaluated contexts.


I got regression in the folowing test when checking CheckCUDACall in MarkFunctionReferenced:

  typedef struct {
    template <unsigned n> void *foo() { return 0; }
  
    void foo() {
      foo<0>();
    }
  } A;

Basically clang does not allow getting linkage of foo<0> before ActOnTypedefDeclarator, quoting SemaDecl.cpp line 4171

  // If we've already computed linkage for the anonymous tag, then
  // adding a typedef name for the anonymous decl can change that
  // linkage, which might be a serious problem.  Diagnose this as
  // unsupported and ignore the typedef name.  TODO: we should
  // pursue this as a language defect and establish a formal rule
  // for how to handle it.
  if (TagFromDeclSpec->hasLinkageBeenComputed()) {
    Diag(NewTD->getLocation(), diag::err_typedef_changes_linkage);

However, CheckCUDACall needs to call GetGVALinkageForFunction on the callee to know if it will be emitted,
which causes the linkage of the anonymous struct to be cached and triggers err_typedef_changes_linkage.


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

https://reviews.llvm.org/D56411





More information about the cfe-commits mailing list