[clang] [Clang] [WIP] Added builtin_alloca support for OpenCL1.2 and below (PR #95750)

Anastasia Stulova via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 2 06:58:28 PDT 2024


================
@@ -6275,13 +6278,46 @@ static FunctionDecl *rewriteBuiltinFunctionDecl(Sema *Sema, ASTContext &Context,
     OverloadParams.push_back(Context.getPointerType(PointeeType));
   }
 
+  QualType ReturnTy = FT->getReturnType();
+  QualType OverloadReturnTy = ReturnTy;
+  if (ReturnTy->isPointerType() &&
+      !ReturnTy->getPointeeType().hasAddressSpace()) {
+    if (Sema->getLangOpts().OpenCL) {
+      NeedsNewDecl = true;
+
+      QualType ReturnPtTy = ReturnTy->getPointeeType();
+      unsigned BuiltinID = FDecl->getBuiltinID();
+      LangAS defClAS;
+
+      // __builtin_alloca* should always return pointer to stack/private
+      // Address Space, while for other builtins with return pointer type,
+      // it should depend on the OpenCL version.
+      switch (BuiltinID) {
----------------
AnastasiaStulova wrote:

Seems a bit unfortunate to have such specialised code in a generic function. Could we not create the function prototype with the right address space directly in the return type inside `SemaChecking.cpp` instead?

https://github.com/llvm/llvm-project/pull/95750


More information about the cfe-commits mailing list