AlexVlx wrote:

@yxsamliu beat me to it. The problem here is that the example illustrates 
language level const on a variable with internal linkage (which is mandatory 
for `__constant__` variables in non-RDC compilation AFAICT from 17.5.24.1) and 
we don't set externally_initialized on that, which matches C/C++ expected 
semantics, I believe (there's an oblique mention as to the reasoning, which is 
that the loader should be allowed to place these in `.rodata` if they 
materialise at all). Regarding the lit test, I can definitely add another one, 
but I will note we already have 
`Transforms/GlobalOpt/externally-initialized.ll`, which probably can be 
extended?

Please note that this is something that wouldn't work (as apparently expected) 
today either. The user can write the code  @Artem-B wrote (put const on a 
`__constant__`, add an initialiser because otherwise things would be broken), 
and they'd get exactly the potentially unexpected behaviour. The very fact that 
the godbolt example exists points that out (the example also helpfully points 
out that NVCC has the same behaviour). Unfortunately the CUDA spec does not 
appear to talk about this (a `const` qualified `__constant__` variable) 
directly, but working back from 17.5.23.2 we can conclude that they're fine as 
long as the host compiler is not VC++.

https://github.com/llvm/llvm-project/pull/110182
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to