[OpenCL] Suppress -Wreturn-stack-address for function-scope local variable (#181602)
OpenCL local variable has lifetime of work-group, not function call stack.
This commit is contained in:
parent
2e989bd595
commit
ede47a3b13
@ -1337,6 +1337,9 @@ checkExprLifetimeImpl(Sema &SemaRef, const InitializedEntity *InitEntity,
|
||||
// expression.
|
||||
if (LK == LK_StmtExprResult)
|
||||
return false;
|
||||
if (auto *VD = dyn_cast<VarDecl>(DRE->getDecl()))
|
||||
if (VD->getType().getAddressSpace() == LangAS::opencl_local)
|
||||
return false;
|
||||
SemaRef.Diag(DiagLoc, diag::warn_ret_stack_addr_ref)
|
||||
<< InitEntity->getType()->isReferenceType() << DRE->getDecl()
|
||||
<< isa<ParmVarDecl>(DRE->getDecl()) << (LK == LK_MustTail)
|
||||
|
||||
13
clang/test/SemaOpenCL/function-scope-local-return.cl
Normal file
13
clang/test/SemaOpenCL/function-scope-local-return.cl
Normal file
@ -0,0 +1,13 @@
|
||||
// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL3.0
|
||||
|
||||
// Check that returning a pointer to a local address space variable does not
|
||||
// trigger -Wreturn-stack-address.
|
||||
|
||||
// expected-no-diagnostics
|
||||
|
||||
#pragma OPENCL EXTENSION __cl_clang_function_scope_local_variables : enable
|
||||
|
||||
local int* get_group_scratch() {
|
||||
local int data[64];
|
||||
return data;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user