<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/72261>72261</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [CUDA][HIP] file-scope device variable not allowed with trivial ctor
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yxsamliu
      </td>
    </tr>
</table>

<pre>
    `struct A {
  A() {}
  ~A() {}
  int x;
};

__device__ A x;`

the above code is allowed with nvcc but not cuda-clang.

https://godbolt.org/z/jjMG3zTd3

https://godbolt.org/z/74Ed1WvGn

nvcc allows it not because it makes the ctor A::A() implicitly host device (this can be seen by defining A x in device function), but because it does not check host/device availability for file-scope device var.

I think it makes sense to make trivial ctor/dtor implicitly host device.

@Artem-B 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUUz1z2zAM_TXUgrNPor6sQYMc12mG3nVor6OPH7CFhCZ9IqXEGfrbe5Tjxull6SKRAAG89wAI7-lgEVtWrlm5ScQYeje05xcvjobGRDp9blmV-jCMKkAHrF6zdMPSDqBjfMV4M5vqzdX6-3Mz2QAvLH8Ljo6_5_m722mcSOFuB93lYZXe-kOPIKSbEJTTCORBGOOeUcMzhR7spBTIMYB1AdSoxUIZYQ_L2xR9CCfP8o7xLePbg9PSmbB0w4Hx7Svj28fHb_f56w-d_09QXXzR2a_p3t4GzWhmfB7ogkmiEqPHeD2KJ_QQCangBuhi9ry7ykbHkyFFwZyhdz7ARRZgfBV68qCEBYngES3IM2jckyV7iKIB2evr_WhVIGcZbxi_m4W5AaAd-otQPaqnuQzj27dQMQkyQpKhcIa9G2BPBhdeuRNes09i-CDsA4Se7NM7N4_WIwQ3XyEMNJEwM9tYJ5L-nOWHrKxIuyHgcbGGRLe5bvJGJNhmVdM0dc5XZdK3udKoK95UTSOERJVWRZ1hua_2UtaqVgm1POV5lmVFVhSrtFzyoipXZZalKIQsmpwVKR4FmaUx0zH2NSHvR2xrzqssMUKi8fNycG7xGWYn4zzuytDGmIUcD54VqSEf_HuWQMHMW3X3c9OxcsPK9deH76zcfK4nCWlw7smHsb6VLhkH0_4zjhT6US6VOzK-jaXffovT4B5Rxa7OgH0c1EjoTwAAAP__MAg7eg">