[PATCH] D49931: [CUDA][HIP] Allow function-scope static const variable
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jul 27 14:38:41 PDT 2018
yaxunl marked an inline comment as done.
yaxunl added inline comments.
================
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)
----------------
tra wrote:
> 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();
> }()
> ```
The lambda looks good. Will use it. Thanks!
https://reviews.llvm.org/D49931
More information about the cfe-commits
mailing list