Skip to content

Commit 1dbb2d5

Browse files
committed
updated return pointer to always point to stack/private address space for buitins alloca variants.
1 parent cbe656f commit 1dbb2d5

File tree

3 files changed

+242
-54
lines changed

3 files changed

+242
-54
lines changed

clang/lib/Sema/SemaExpr.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6286,7 +6286,26 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context,
62866286
NeedsNewDecl = true;
62876287

62886288
QualType ReturnPtTy = ReturnTy->getPointeeType();
6289-
LangAS defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
6289+
unsigned BuiltinID = FDecl->getBuiltinID();
6290+
LangAS defClAS;
6291+
6292+
// __builtin_alloca* should always return pointer to stack/private
6293+
// Address Space, while for other builtins with return pointer type,
6294+
// it should depend on the OpenCL version.
6295+
switch (BuiltinID) {
6296+
case Builtin::BI__builtin_alloca_uninitialized:
6297+
case Builtin::BI__builtin_alloca:
6298+
case Builtin::BI__builtin_alloca_with_align_uninitialized:
6299+
case Builtin::BI__builtin_alloca_with_align: {
6300+
defClAS = LangAS::opencl_private;
6301+
break;
6302+
}
6303+
default: {
6304+
defClAS = Context.getDefaultOpenCLPointeeAddrSpace();
6305+
break;
6306+
}
6307+
}
6308+
62906309
ReturnPtTy = Context.getAddrSpaceQualType(ReturnPtTy, defClAS);
62916310
OverloadReturnTy = Context.getPointerType(ReturnPtTy);
62926311
}

0 commit comments

Comments
 (0)