diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 8c24b0333e1f4762bb219a7de599232c9b4e179b..e14330cf60e78774abd7c421b3b917216483260a 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -2745,7 +2745,10 @@ static CompleteObject findCompleteObject(EvalInfo &Info, const Expr *E, } else if (VD->isConstexpr()) { // OK, we can read this variable. } else if (BaseType->isIntegralOrEnumerationType()) { - if (!BaseType.isConstQualified()) { + // In OpenCL if a variable is in constant address space it is a const value. + if (!(BaseType.isConstQualified() || + (Info.getLangOpts().OpenCL && + BaseType.getAddressSpace() == LangAS::opencl_constant))) { if (Info.getLangOpts().CPlusPlus) { Info.Diag(E, diag::note_constexpr_ltor_non_const_int, 1) << VD; Info.Note(VD->getLocation(), diag::note_declared_at); diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 9786f7fb4f8ae0b7cc59cc1af38b17fea6e86a96..ddcdef843100e550ced993c7f66b4a106bdd876d 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -2063,7 +2063,8 @@ static bool isArraySizeVLA(Sema &S, Expr *ArraySize, llvm::APSInt &SizeVal) { } Diagnoser; return S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser, - S.LangOpts.GNUMode).isInvalid(); + S.LangOpts.GNUMode || + S.LangOpts.OpenCL).isInvalid(); } /// \brief Build an array type. diff --git a/test/CodeGenOpenCL/vla.cl b/test/CodeGenOpenCL/vla.cl new file mode 100644 index 0000000000000000000000000000000000000000..cbf98445ce0007ede9739c07060bced018273f07 --- /dev/null +++ b/test/CodeGenOpenCL/vla.cl @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -emit-llvm -triple "spir-unknown-unknown" -O0 -cl-std=CL2.0 -o - %s | FileCheck %s + +constant int sz0 = 5; +// CHECK: @sz0 = addrspace(2) constant i32 5 +const global int sz1 = 16; +// CHECK: @sz1 = addrspace(1) constant i32 16 +const constant int sz2 = 8; +// CHECK: @sz2 = addrspace(2) constant i32 8 +// CHECK: @testvla.vla2 = internal addrspace(3) global [8 x i16] undef + +kernel void testvla() +{ + int vla0[sz0]; +// CHECK: %vla0 = alloca [5 x i32] + char vla1[sz1]; +// CHECK: %vla1 = alloca [16 x i8] + local short vla2[sz2]; +}