Index: src/SymTab/Autogen.h
===================================================================
--- src/SymTab/Autogen.h	(revision 4d2434a3b1b9692aecc5c41cc41df0d3c37fbefb)
+++ src/SymTab/Autogen.h	(revision f9cebb5b27ac03463e4eca5c0e87d48d548e9502)
@@ -37,9 +37,10 @@
 	/// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
 	template< typename OutputIterator >
-	void genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
+	Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
 
 	/// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.
+	/// optionally returns a statement which must be inserted prior to the containing loop, if there is one
 	template< typename OutputIterator >
-	void genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
+	Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false ) {
 		// want to be able to generate assignment, ctor, and dtor generically,
 		// so fname is either ?=?, ?{}, or ^?{}
@@ -63,15 +64,14 @@
 		fExpr->get_args().push_back( dstParam );
 
-    Statement * listInit = srcParam.buildListInit( fExpr );
-    if ( listInit ) {
-      *out++ = listInit;
-    }
+		Statement * listInit = srcParam.buildListInit( fExpr );
 
-    std::list< Expression * > args = *++srcParam;
-    fExpr->get_args().splice( fExpr->get_args().end(), args );
+		std::list< Expression * > args = *++srcParam;
+		fExpr->get_args().splice( fExpr->get_args().end(), args );
 
 		*out++ = new ExprStmt( noLabels, fExpr );
 
-    srcParam.clearArrayIndices();
+		srcParam.clearArrayIndices();
+
+		return listInit;
 	}
 
@@ -125,14 +125,7 @@
 		srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
 
-		// if ( srcParam ) {
-		// 	UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
-		// 	srcIndex->get_args().push_back( srcParam );
-		// 	srcIndex->get_args().push_back( new VariableExpr( index ) );
-		// 	srcParam = srcIndex;
-		// }
-
 		// for stmt's body, eventually containing call
 		CompoundStmt * body = new CompoundStmt( noLabels );
-		genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
+		Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
 
 		// block containing for stmt and index variable
@@ -140,4 +133,5 @@
 		CompoundStmt * block = new CompoundStmt( noLabels );
 		block->get_kids().push_back( new DeclStmt( noLabels, index ) );
+		if ( listInit ) block->get_kids().push_back( listInit );
 		block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, body ) );
 
@@ -146,9 +140,10 @@
 
 	template< typename OutputIterator >
-	void genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
+	Statement * genCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
 		if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
 			genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
+			return 0;
 		} else {
-			genScalarCall( srcParam, dstParam, fname, out, type, addCast );
+			return genScalarCall( srcParam, dstParam, fname, out, type, addCast );
 		}
 	}
@@ -171,15 +166,15 @@
 		// currently genCall should produce at most one element, but if that changes then the next line needs to be updated to grab the statement which contains the call
 		assert( stmts.size() <= 1 );
-    if ( stmts.size() == 1 ) {
-  		Statement * callStmt = stmts.front();
-  		if ( addCast ) {
-  			// implicitly generated ctor/dtor calls should be wrapped
-  			// so that later passes are aware they were generated.
-  			// xxx - don't mark as an implicit ctor/dtor if obj is a bitfield,
-  			// because this causes the address to be taken at codegen, which is illegal in C.
-  			callStmt = new ImplicitCtorDtorStmt( callStmt );
-  		}
-  		*out++ = callStmt;
-    }
+		if ( stmts.size() == 1 ) {
+			Statement * callStmt = stmts.front();
+			if ( addCast ) {
+				// implicitly generated ctor/dtor calls should be wrapped
+				// so that later passes are aware they were generated.
+				// xxx - don't mark as an implicit ctor/dtor if obj is a bitfield,
+				// because this causes the address to be taken at codegen, which is illegal in C.
+				callStmt = new ImplicitCtorDtorStmt( callStmt );
+			}
+			*out++ = callStmt;
+		}
 	}
 } // namespace SymTab
