[PATCH] D102689: [C++4OpenCL] Allow address space conversion in reinterpret_cast
Anastasia Stulova via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 20 08:02:26 PDT 2021
Anastasia added a comment.
Just to move the discussion from https://reviews.llvm.org/D101519 here. First of all I think this change should not be OpenCL specific i.e. there is not reason to do something different from C++ in general.
Embedded C doesn't regulate the conversions between non-pointer types with different address spaces but in OpenCL C we have allowed them apparently https://godbolt.org/z/9f75zxj7v. I am not sure whether this was done intentionally or not.
However, in C there are no references and other features that might create problems.
At the same time it seems C++ allows casting away const https://godbolt.org/z/fo3axbq3e
But it contradicts the comment in the code:
> // C++ 5.2.10p2 has a note that mentions that, subject to all other
> // restrictions, a cast to the same type is allowed so long as it does not
> // cast away constness. In C++98, the intent was not entirely clear here,
> // since all other paragraphs explicitly forbid casts to the same type.
> // C++11 clarifies this case with p2.
I would like to see if @rjmccall has any opinion on whether reinterpreting between non-pointer types with different address spaces is reasonable?
In general it makes sense to follow logic for other type qualifier here but I was thinking of whether we can allow something weird to be written by relaxing this for address spaces
local int i;
const global int & ii = reinterpret_cast<global int>(i);
I think this code is completely meaningless as it requires creating a temporary in global address space? I am not sure what we will even emit in IR?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D102689/new/
https://reviews.llvm.org/D102689
More information about the cfe-commits
mailing list