diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index f33cf59f48874..4b6f2c5ffebd3 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -266,8 +266,7 @@ llvm::Constant *CodeGenModule::getOrCreateStaticVarDecl( // OpenCL/SYCL variables in local address space and CUDA shared // variables cannot have an initializer. llvm::Constant *Init = nullptr; - if (Ty.getAddressSpace() == LangAS::opencl_local || - Ty.getAddressSpace() == LangAS::sycl_local || + if (AS == LangAS::opencl_local || AS == LangAS::sycl_local || D.hasAttr() || D.hasAttr()) Init = llvm::UndefValue::get(LTy); else diff --git a/clang/test/CodeGenSYCL/wg_init.cpp b/clang/test/CodeGenSYCL/wg_init.cpp new file mode 100644 index 0000000000000..b61c2bb970762 --- /dev/null +++ b/clang/test/CodeGenSYCL/wg_init.cpp @@ -0,0 +1,22 @@ +// RUN: %clang_cc1 -fsycl-is-device -triple spir64-unknown-unknown -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s + +// This test checks that a local variable initialized within a +// parallel_for_work_group scope is initialized as an UndefValue in addrspace(3) +// in LLVM IR. + +#include "Inputs/sycl.hpp" + +using namespace sycl; + +int main() { + queue q; + q.submit([&](handler &h) { + h.parallel_for_work_group( + range<1>{1}, range<1>{1}, [=](group<1> G) { + int WG_VAR = 10; + }); + }); + return 0; +} + +// CHECK: @{{.*}}WG_VAR = internal addrspace(3) global {{.*}} undef, {{.*}}