[PATCH] D71241: [OpenMP][WIP] Use overload centric declare variants

Johannes Doerfert via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 16 16:07:04 PST 2019


jdoerfert added a comment.

In D71241#1786530 <https://reviews.llvm.org/D71241#1786530>, @ABataev wrote:

> Most probably, we can use this solution without adding a new expression. `DeclRefExpr` class can contain 2 decls: FoundDecl and the Decl being used. You can use FoundDecl to point to the original function and used decl to point to the function being called in this context. But at first, we need to be sure that we can handle all corner cases correctly.


What new expression are you talking about? This solution already does point to both declarations, as shown here: https://reviews.llvm.org/D71241#1782504

> For example, can it handle such cases as:
>  t1.c:
> 
>   int hst();
>   #pragma omp declare variant(hst) match(device={kind(host)})
>   int base();
> 
> 
> t2.c:
> 
>   int main() {
>     return base();
>   }
> 
> 
> This is the correct C code, I assume. At least, clang compiles it.
> 
> Another problem:
>  t1.c:
> 
>   int hst();
>   #pragma omp declare varint(hst) match(device={kind(host)})
>   int base();
> 
> 
> t2.c:
> 
>   int base() { return 0; }
>   int main() {
>     return base();
>   }
> 
> 
> According to the standard, this is valid code and `hst` function must be called (though it is not correct since in C/C++ each definition is a declaration and all restriction applied to the declaration must be applied to the definition too).

The second example is valid code and it doens't matter if the first example is.
The argument I used here https://reviews.llvm.org/D71241#1783711 holds again and the `hst` function *must not be called* in either case. 
The standard is clear on that and that is one of the reason the alias solution *does not work*.

> Another one possible problem might be with the templates:
> 
>   template <typename T> T base() { return T(); }
>   int hst() { return 1; }
>   
>   int main() {
>     return base<int>();
>   }
>   
>   #pragma omp declare variant(hst) match(device={kind(gpu)})
>   template<typename T>
>   T base();
>   
>   int foo() {
>     return base<int>();
>   }

It would be helpful if you explain the problem that might or might not arise. In the above code there is no `target` so it is unclear if foo would be emitted for the gpu or not (main is not emitted for the gpu for sure). Only when foo is emitted for the gpu, the call would be to `hst`, otherwise always to `base`.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D71241





More information about the cfe-commits mailing list