[PATCH] D88345: [CUDA] Allow local `static const {__constant__, __device__}` variables.
Justin Lebar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 12:03:14 PDT 2020
jlebar added a comment.
OK, now I'm starting to I understand this change..
Before, in function scope, we allow static const/non-const `__shared__`, and allow static const so long as it's not `__device__` or `__constant__`.
- `static` -> error? (I understood us saying above that it is, but now that I read the code, isn't it saying it's an error?)
- `static const` -> allowed
- `static __device__` -> error
- `static const __device__` -> error
- `static __constant__` -> error
- `static const __constant__` -> error
After, in function scope, the rule is, allow static const/non-const `__shared__` or anything that's `static const`.
- `static` -> error, must be const
- `static const` -> allowed
- `static __device__` -> error, must be const
- `static const __device__` -> allowed
- `static __constant__` -> error, must be const
- `static const __constant__` -> allowed
I guess my question when I write out this table is, why shouldn't it be like this?
- `static` -> allowed
- `static const` -> allowed
- `static __device__` -> allowed
- `const static __device__` -> allowed
- `static __constant__` -> error, must be const
- `const static __constant__` -> allowed
This makes some sense to me because we're saying, "`__constant__` must be const", otherwise, anything goes.
Or here's another way of thinking about it. You're saying that `static` and `static __device__` in function scope are the same as a `__device__` variable in block scope. And a `__device__` variable in block scope doesn't have to be const (right?). So why the extra restriction on function-scope static?
================
Comment at: clang/lib/Sema/SemaDecl.cpp:13161
// without device memory qualifier is implemented, therefore only static
// const variable without device memory qualifier is allowed.
[&]() {
----------------
Update comment?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D88345/new/
https://reviews.llvm.org/D88345
More information about the cfe-commits
mailing list