[PATCH] D49931: [CUDA][HIP] Allow function-scope static const variable
Artem Belevich via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 27 14:31:35 PDT 2018
tra added a comment.
Looks OK overall except for the huge `if` below.
================
Comment at: lib/Sema/SemaDecl.cpp:11923-11930
+ if (getLangOpts().CUDA &&
+ !(VD->hasAttr<CUDASharedAttr>() ||
+ (VD->getType().isConstQualified() &&
+ !VD->hasAttr<CUDADeviceAttr>() &&
+ !VD->hasAttr<CUDAConstantAttr>())) &&
CUDADiagIfDeviceCode(VD->getLocation(),
diag::err_device_static_local_var)
----------------
This is rather convoluted. It would make it somewhat more readable if we could split CUDADiagIfDeviceCode into its own if().
Or, maybe use a lambda + early exit or, perhaps even goto to break down this huge if:
```
[&](){
if (VD->hasAttr<CUDASharedAttr>()) return;
if (VD->getType().isConstQualified()
&& !(VD->hasAttr<CUDADeviceAttr>()||VD->hasAttr<CUDAConstantAttr>())
return;
if (CUDADiagIfDeviceCode(VD->getLocation(), diag::err_device_static_local_var)
<< CurrentCUDATarget()))
VD->setInvalidDecl();
}()
```
https://reviews.llvm.org/D49931
More information about the cfe-commits
mailing list