[PATCH] D67509: [CUDA][HIP] Fix hostness of defaulted constructor

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 19 12:15:19 PDT 2019


tra added inline comments.


================
Comment at: lib/Sema/SemaCUDA.cpp:387
+  // each inference gets same result and not to add duplicate attributes.
+  auto addBothAttr = [=]() {
+    assert(MemberDecl->hasAttr<CUDAHostAttr>() ==
----------------
`addHDAttrIfNeeded` ? We may not even need it. See below.


================
Comment at: lib/Sema/SemaCUDA.cpp:388-409
+    assert(MemberDecl->hasAttr<CUDAHostAttr>() ==
+           MemberDecl->hasAttr<CUDADeviceAttr>());
+    if (!MemberDecl->hasAttr<CUDADeviceAttr>())
+      MemberDecl->addAttr(CUDADeviceAttr::CreateImplicit(Context));
+    if (!MemberDecl->hasAttr<CUDAHostAttr>())
+      MemberDecl->addAttr(CUDAHostAttr::CreateImplicit(Context));
+  };
----------------
Perhaps we can rearrange things a bit to make it easier to follow.

```
bool needsH = true, needsD=true;
if (has Value) {
   if (CFT_Device)
      needsH = false;
   if (CFT_Host)
      needsD = false;
}

// We either setting attributes first time, or the inferred ones must match previously set ones.
assert(!(hasAttr(D) || hasAttr(H)) 
    || (needsD == hasAttr(D) && (needsH == hasAttr(H)))
if (needsD && !hasAttr(D))
   addAttr(D);
if (needsH && ! hasAttr(H))
   addAttr(H);
```


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

https://reviews.llvm.org/D67509





More information about the cfe-commits mailing list