[clang] [libc] [libcxx] [llvm] [NVPTX] Make ctor/dtor lowering always enabled in NVPTX (PR #126544)

Artem Belevich via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 10 11:40:58 PST 2025


================
@@ -7484,6 +7484,17 @@ void Sema::ProcessDeclAttributeList(
     }
   }
 
+  // Do not permit 'constructor' or 'destructor' attributes on __device__ code.
+  if (getLangOpts().CUDAIsDevice && !getLangOpts().GPUAllowDeviceInit) {
+    if (D->hasAttr<ConstructorAttr>() && D->hasAttr<CUDADeviceAttr>()) {
----------------
Artem-B wrote:

`&& D->hasAttr<CUDADeviceAttr>()` could be hoisted into the top-level condition.

Nit: I'd probably go even further and make it a single linear chain of "and this... and that..."
```
  if (CUDAIsDevice 
      && D->hasAttr<CUDADeviceAttr>()
      && (D->hasAttr<ConstructorAttr>() || D->hasAttr<DestructorAttr>()) 
      && !getLangOpts().GPUAllowDeviceInit) {
      Diag(D->getLocation(), diag::err_cuda_ctor_dtor_attrs) << D->hasAttr<ConstructorAttr>() "constructors" : "destructors";
      D->setInvalidDecl();
}
```

https://github.com/llvm/llvm-project/pull/126544


More information about the cfe-commits mailing list