[clang] [CIR] Add support for __builtin_alloca (PR #157116)
Morris Hafner via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 8 06:00:25 PDT 2025
================
@@ -149,6 +149,57 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
emitVAEnd(emitVAListRef(e->getArg(0)).getPointer());
return {};
+ case Builtin::BIalloca:
+ case Builtin::BI_alloca:
+ case Builtin::BI__builtin_alloca_uninitialized:
+ case Builtin::BI__builtin_alloca: {
+ // Get alloca size input
+ mlir::Value size = emitScalarExpr(e->getArg(0));
+
+ // The alignment of the alloca should correspond to __BIGGEST_ALIGNMENT__.
+ const TargetInfo &TI = getContext().getTargetInfo();
+ const CharUnits SuitableAlignmentInBytes =
+ getContext().toCharUnitsFromBits(TI.getSuitableAlign());
+
+ // Emit the alloca op with type `u8 *` to match the semantics of
+ // `llvm.alloca`. We later bitcast the type to `void *` to match the
+ // semantics of C/C++
+ // FIXME(cir): It may make sense to allow AllocaOp of type `u8` to return a
+ // pointer of type `void *`. This will require a change to the allocaOp
+ // verifier.
+ auto allocaAddr = builder.createAlloca(
----------------
mmha wrote:
Disambiguating between a `Value` and an `Attribute` makes sense to me. I removed the auto.
https://github.com/llvm/llvm-project/pull/157116
More information about the cfe-commits
mailing list