@@ -58,6 +58,24 @@ static RValue emitBuiltinBitOp(CIRGenFunction &cgf, const CallExpr *e,
5858 return RValue::get (result);
5959}
6060
61+ // Initialize the alloca with the given size and alignment according to the lang
62+ // opts. Supporting only the trivial non-initialization for now.
63+ static void initializeAlloca (CIRGenFunction &CGF,
64+ [[maybe_unused]] mlir::Value AllocaAddr,
65+ [[maybe_unused]] mlir::Value Size,
66+ [[maybe_unused]] CharUnits AlignmentInBytes) {
67+
68+ switch (CGF.getLangOpts ().getTrivialAutoVarInit ()) {
69+ case LangOptions::TrivialAutoVarInitKind::Uninitialized:
70+ // Nothing to initialize.
71+ return ;
72+ case LangOptions::TrivialAutoVarInitKind::Zero:
73+ case LangOptions::TrivialAutoVarInitKind::Pattern:
74+ assert (false && " unexpected trivial auto var init kind NYI" );
75+ return ;
76+ }
77+ }
78+
6179RValue CIRGenFunction::emitRotate (const CallExpr *e, bool isRotateLeft) {
6280 mlir::Value input = emitScalarExpr (e->getArg (0 ));
6381 mlir::Value amount = emitScalarExpr (e->getArg (1 ));
@@ -172,28 +190,21 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
172190 builder.getUInt8Ty (), " bi_alloca" , suitableAlignmentInBytes, size);
173191
174192 // Initialize the allocated buffer if required.
175- if (builtinID != Builtin::BI__builtin_alloca_uninitialized) {
176- // Initialize the alloca with the given size and alignment according to
177- // the lang opts. Only the trivial non-initialization is supported for
178- // now.
179-
180- switch (getLangOpts ().getTrivialAutoVarInit ()) {
181- case LangOptions::TrivialAutoVarInitKind::Uninitialized:
182- // Nothing to initialize.
183- break ;
184- case LangOptions::TrivialAutoVarInitKind::Zero:
185- case LangOptions::TrivialAutoVarInitKind::Pattern:
186- cgm.errorNYI (" trivial auto var init" );
187- break ;
188- }
189- }
193+ if (builtinID != Builtin::BI__builtin_alloca_uninitialized)
194+ initializeAlloca (*this , allocaAddr, size, suitableAlignmentInBytes);
190195
191196 // An alloca will always return a pointer to the alloca (stack) address
192197 // space. This address space need not be the same as the AST / Language
193198 // default (e.g. in C / C++ auto vars are in the generic address space). At
194199 // the AST level this is handled within CreateTempAlloca et al., but for the
195200 // builtin / dynamic alloca we have to handle it here.
196201 assert (!cir::MissingFeatures::addressSpace ());
202+ cir::AddressSpace aas = getCIRAllocaAddressSpace ();
203+ cir::AddressSpace eas = cir::toCIRAddressSpace (
204+ e->getType ()->getPointeeType ().getAddressSpace ());
205+ if (eas != aas) {
206+ assert (false && " Non-default address space for alloca NYI" );
207+ }
197208
198209 // Bitcast the alloca to the expected type.
199210 return RValue::get (
0 commit comments