Don't permit array bound constant folding in OpenCL.
authorRichard Smith <richard@metafoo.co.uk>
Fri, 16 Oct 2020 00:50:48 +0000 (17:50 -0700)
committerRichard Smith <richard@metafoo.co.uk>
Tue, 20 Oct 2020 23:52:28 +0000 (16:52 -0700)
commit6781fee085058913444e0c5937da9c0e7e928db5
tree25ca93c5f1bfe99b572400f0b9a7127a3c0509d2
parentf88785460ecf40a9176f58637d38fb785eb91ac4
Don't permit array bound constant folding in OpenCL.

Permitting non-standards-driven "do the best you can" constant-folding
of array bounds is permitted solely as a GNU compatibility feature. We
should not be doing it in any language mode that is attempting to be
conforming.

From https://reviews.llvm.org/D20090 it appears the intent here was to
permit `__constant int` globals to be used in array bounds, but the
change in that patch only added half of the functionality necessary to
support that in the constant evaluator. This patch adds the other half
of the functionality and turns off constant folding for array bounds in
OpenCL.

I couldn't find any spec justification for accepting the kinds of cases
that D20090 accepts, so a reference to where in the OpenCL specification
this is permitted would be useful.

Note that this change also affects the code generation in one test:
because after 'const int n = 0' we now treat 'n' as a constant
expression with value 0, it's now a null pointer, so '(local int *)n'
forms a null pointer rather than a zero pointer.

Reviewed By: Anastasia

Differential Revision: https://reviews.llvm.org/D89520
clang/lib/AST/Decl.cpp
clang/lib/AST/ExprConstant.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGenOpenCL/amdgpu-nullptr.cl
clang/test/SemaOpenCL/address-spaces.cl