Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 3a48e283f52a273668725dbaba2755c0ab637ed1)
+++ src/GenPoly/Box.cc	(revision a0ad7dc9c1fb88ba2a6f635f0b103f2eb1380169)
@@ -34,4 +34,5 @@
 #include "Parser/ParseNode.h"
 
+#include "SynTree/Attribute.h"
 #include "SynTree/Constant.h"
 #include "SynTree/Declaration.h"
@@ -165,4 +166,6 @@
 			using Parent::mutate;
 
+			PolyGenericCalculator();
+
 			template< typename DeclClass >
 			DeclClass *handleDecl( DeclClass *decl, Type *type );
@@ -198,4 +201,5 @@
 			ScopedSet< std::string > knownLayouts;          ///< Set of generic type layouts known in the current scope, indexed by sizeofName
 			ScopedSet< std::string > knownOffsets;          ///< Set of non-generic types for which the offset array exists in the current scope, indexed by offsetofName
+			UniqueName bufNamer;                           ///< Namer for VLA buffers
 		};
 
@@ -1452,4 +1456,7 @@
 ////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
 
+		PolyGenericCalculator::PolyGenericCalculator()
+			: Parent(), knownLayouts(), knownOffsets(), bufNamer( "_buf" ) {}
+
 		void PolyGenericCalculator::beginTypeScope( Type *ty ) {
 			scopeTyVars.beginScope();
@@ -1528,14 +1535,16 @@
 			if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
 				if ( findGeneric( objectDecl->get_type() ) ) {
-					// change initialization of a polymorphic value object
-					// to allocate storage with alloca
+					// change initialization of a polymorphic value object to allocate via a VLA
+					// (alloca was previously used, but can't be safely used in loops)
 					Type *declType = objectDecl->get_type();
-					UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) );
-					alloc->get_args().push_back( new NameExpr( sizeofName( mangleType( declType ) ) ) );
+					std::string bufName = bufNamer.newName();
+					ObjectDecl *newBuf = new ObjectDecl( bufName, Type::StorageClasses(), LinkageSpec::C, 0, 
+						new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 
+						true, false, std::list<Attribute*>{ new Attribute( std::string{"aligned"}, std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 );
+					stmtsToAdd.push_back( new DeclStmt( noLabels, newBuf ) );
 
 					delete objectDecl->get_init();
 
-					std::list<Expression*> designators;
-					objectDecl->set_init( new SingleInit( alloc, designators, false ) ); // not constructed
+					objectDecl->set_init( new SingleInit( new NameExpr( bufName ) ) );
 				}
 			}
