[PATCH] D79526: [CUDA][HIP] Workaround for resolving host device function against wrong-sided function
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri May 22 10:43:32 PDT 2020
yaxunl added a comment.
In D79526#2042680 <https://reviews.llvm.org/D79526#2042680>, @tra wrote:
> Reduced test case:
>
> struct a {
> __attribute__((device)) a(short);
> __attribute__((device)) operator unsigned() const;
> __attribute__((device)) operator int() const;
> };
> struct b {
> a d;
> };
> void f(b g) { b e = g; }
>
>
> Failure:
>
> $ bin/clang++ -x cuda aten.cc -fsyntax-only --cuda-path=$HOME/local/cuda-10.1 --cuda-device-only --cuda-gpu-arch=sm_60 -stdlib=libc++ -std=c++17 -ferror-limit=1
>
> aten.cc:6:8: error: conversion from 'const a' to 'short' is ambiguous
> struct b {
> ^
> aten.cc:9:21: note: in implicit copy constructor for 'b' first required here
> void f(b g) { b e = g; }
> ^
> aten.cc:3:27: note: candidate function
> __attribute__((device)) operator unsigned() const;
> ^
> aten.cc:4:27: note: candidate function
> __attribute__((device)) operator int() const;
> ^
> aten.cc:2:34: note: passing argument to parameter here
> __attribute__((device)) a(short);
> ^
> 1 error generated when compiling for sm_60.
>
>
> The same code compiles fine in C++ and I would expect it to work on device side the same way.
a and b both have an implicit HD copy ctor. In device compilation, copy ctor of b is calling copy ctor of a. There are two candidates: implicit HD copy ctor of a, and device ctor a(short).
In my previous fix, I made H and implicit HD candidate equal, however I forgot about the relation between D candidate and HD candidate. I incorrectly made D favored over HD and H. This caused inferior device candidate a(short) chosen over copy ctor of a.
I have a fix for this https://reviews.llvm.org/D80450
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D79526/new/
https://reviews.llvm.org/D79526
More information about the cfe-commits
mailing list