Index: doc/aaron_comp_II/comp_II.tex
===================================================================
--- doc/aaron_comp_II/comp_II.tex	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ doc/aaron_comp_II/comp_II.tex	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -84,16 +84,22 @@
 \section{Introduction}
 
-\CFA\footnote{Pronounced ``C-for-all'', and written \CFA, CFA, or \CFL.} is an evolutionary modernization of the C programming language currently being designed and built at the University of Waterloo by a team led by Peter Buhr. 
-\CFA adds multiple features to C, including name overloading, user-defined operators, parametric-polymorphic routines, and type constructors and destructors, among others. 
-These features make \CFA significantly more powerful and expressive than C, but impose a significant compile-time cost to support, particularly in the expression resolver, which must evaluate the typing rules of a much more complex type system. 
-The primary goal of this proposed research project is to develop a sufficiently performant expression resolution algorithm, experimentally validate its performance, and integrate it into \Index*{CFA-CC}, the \CFA reference compiler.
-Secondary goals of this project include the development of various new language features for \CFA; parametric-polymorphic (``generic'') types have already been designed and implemented, and reference types and user-defined conversions are under design consideration. 
-The experimental performance-testing architecture for resolution algorithms will also be used to determine the compile-time cost of adding such new features to the \CFA type system. 
-More broadly, this research should provide valuable data for implementers of compilers for other programming languages with similarly powerful static type systems.
+\CFA\footnote{Pronounced ``C-for-all'', and written \CFA or \CFL.} is an evolutionary modernization of the C programming language currently being designed and built at the University of Waterloo by a team led by Peter Buhr. 
+\CFA both fixes existing design problems and adds multiple new features to C, including name overloading, user-defined operators, parametric-polymorphic routines, and type constructors and destructors, among others. 
+The new features make \CFA significantly more powerful and expressive than C, but impose a significant compile-time cost, particularly in the expression resolver, which must evaluate the typing rules of a much more complex type-system.
+
+The primary goal of this research project is to develop a sufficiently performant expression resolution algorithm, experimentally validate its performance, and integrate it into CFA, the \CFA reference compiler.
+Secondary goals of this project include the development of various new language features for \CFA: parametric-polymorphic (``generic'') types have already been designed and implemented, and reference types and user-defined conversions are under design consideration. 
+An experimental performance-testing architecture for resolution algorithms is under development to determine the relative performance of different expression resolution algorithms, as well as the compile-time cost of adding various new features to the \CFA type-system. 
+More broadly, this research should provide valuable data for implementers of compilers for other programming languages with similarly powerful static type-systems.
 
 \section{\CFA}
 
-To make the scope of the proposed expression resolution problem more explicit, it is necessary to define the features of both C and \CFA (both current and proposed) which affect this algorithm. 
-In some cases the interactions of multiple features make expression resolution a significantly more complex problem than any individual feature would; in others a feature which does not by itself add any complexity to expression resolution will trigger previously rare edge cases much more frequently.
+To make the scope of the proposed expression resolution problem more explicit, it is necessary to define the features of both C and \CFA (both current and proposed) that affect this algorithm. 
+In some cases the interactions of multiple features make expression resolution a significantly more complex problem than any individual feature would; in other cases a feature that does not by itself add any complexity to expression resolution triggers previously rare edge cases more frequently.
+
+It is important to note that \CFA is not an object-oriented language.
+\CFA does have a system of (possibly implicit) type conversions derived from C's type conversions; while these conversions may be thought of as something like an inheritance hierarchy the underlying semantics are significantly different and such an analogy is loose at best. 
+Particularly, \CFA has no concept of ``subclass'', and thus no need to integrate an inheritance-based form of polymorphism with its parametric and overloading-based polymorphism. 
+The graph structure of the \CFA type conversions is also markedly different than an inheritance graph; it has neither a top nor a bottom type, and does not satisfy the lattice properties typical of inheritance graphs.
 
 \subsection{Polymorphic Functions}
@@ -101,5 +107,5 @@
 Such functions are written using a ©forall© clause (which gives the language its name):
 \begin{lstlisting}
-forall(otype T)
+®forall(otype T)®
 T identity(T x) {
     return x;
@@ -110,9 +116,9 @@
 The ©identity© function above can be applied to any complete object type (or ``©otype©''). 
 The type variable ©T© is transformed into a set of additional implicit parameters to ©identity© which encode sufficient information about ©T© to create and return a variable of that type. 
-The current \CFA implementation passes the size and alignment of the type represented by an ©otype© parameter, as well as an assignment operator, constructor, copy constructor \& destructor.
+The current \CFA implementation passes the size and alignment of the type represented by an ©otype© parameter, as well as an assignment operator, constructor, copy constructor and destructor.
 
 Since bare polymorphic types do not provide a great range of available operations, \CFA also provides a \emph{type assertion} mechanism to provide further information about a type:
 \begin{lstlisting}
-forall(otype T | { T twice(T); })
+forall(otype T ®| { T twice(T); }®)
 T four_times(T x) {
     return twice( twice(x) );
@@ -137,6 +143,32 @@
 Finding appropriate functions to satisfy type assertions is essentially a recursive case of expression resolution, as it takes a name (that of the type assertion) and attempts to match it to a suitable declaration in the current scope. 
 If a polymorphic function can be used to satisfy one of its own type assertions, this recursion may not terminate, as it is possible that function will be examined as a candidate for its own type assertion unboundedly repeatedly. 
-To avoid infinite loops, the current \Index*{CFA-CC} compiler imposes a fixed limit on the possible depth of recursion, similar to that employed by most \Index*[C++]{\CC} compilers for template expansion; this restriction means that there are some semantically well-typed expressions which cannot be resolved by {CFA-CC}. 
+To avoid infinite loops, the current CFA compiler imposes a fixed limit on the possible depth of recursion, similar to that employed by most \CC compilers for template expansion; this restriction means that there are some semantically well-typed expressions which cannot be resolved by CFA. 
 One area of potential improvement this project proposes to investigate is the possibility of using the compiler's knowledge of the current set of declarations to more precicely determine when further type assertion satisfaction recursion will not produce a well-typed expression.
+
+\subsubsection{Traits}
+\CFA provides \emph{traits} as a means to name a group of type assertions, as in the example below:
+\begin{lstlisting}
+trait has_magnitude(otype T) {
+    bool ?<?(T, T);        // comparison operator for T
+    T -?(T);               // negation operator for T
+    void ?{}(T*, zero_t);  // constructor from 0 literal
+};
+
+forall(otype M | has_magnitude(M))
+M abs( M m ) {
+    M zero = 0;  // uses zero_t constructor from trait
+    return m < zero ? -m : m;
+}
+
+forall(otype M | has_magnitude(M))
+M max_magnitude( M a, M b ) {
+    M aa = abs(a), ab = abs(b);
+    return aa < ab ? b : a; 
+}
+\end{lstlisting}
+
+Semantically, a trait is merely a named list of type assertions, but they can be used in many of the same situations where an interface in Java or an abstract base class in \CC would be used.
+Unlike Java interfaces or \CC base classes, \CFA types do not explicitly state any inheritance relationship to traits they satisfy; this can be considered a form of structural inheritance, similar to interface implementation in Go, as opposed to the nominal inheritance model of Java and \CC. 
+% TODO talk about modelling of nominal inheritance with structural inheritance, possibility of investigating some resolver algorithms that require nominal
 
 \subsection{Name Overloading}
@@ -174,5 +206,5 @@
 Open research questions on this topic include whether a conversion graph can be generated that represents each allowable conversion in C with a unique minimal-length path, such that the path lengths accurately represent the relative costs of the conversions, whether such a graph representation can be usefully augmented to include user-defined types as well as built-in types, and whether the graph can be efficiently represented and included in the expression resolver.
 
-\subsection{Constructors \& Destructors}
+\subsection{Constructors and Destructors}
 Rob Shluntz, a current member of the \CFA research team, has added constructors and destructors to \CFA. 
 Each type has an overridable default-generated zero-argument constructor, copy constructor, assignment operator, and destructor; for struct types these functions each call their equivalents on each field of the struct. 
@@ -180,5 +212,5 @@
 
 \subsection{Generic Types}
-The author has added a generic type capability to \CFA, designed to efficiently and naturally integrate with \CFA's existing polymorphic functions. 
+I have already added a generic type capability to \CFA, designed to efficiently and naturally integrate with \CFA's existing polymorphic functions. 
 A generic type can be declared by placing a ©forall© specifier on a struct or union declaration, and instantiated using a parenthesized list of types after the type name:
 \begin{lstlisting}
@@ -195,7 +227,7 @@
 \end{lstlisting}
 For \emph{concrete} generic types, that is, those where none of the type parameters depend on polymorphic type variables (like ©pair(const char*, int)© above), the struct is essentially template expanded to a new struct type; for \emph{polymorphic} generic types (such as ©pair(const char*, T)© above), member access is handled by a runtime calculation of the field offset, based on the size and alignment information of the polymorphic parameter type. 
-The default-generated constructors, destructor \& assignment operator for a generic type are polymorphic functions with the same list of type parameters as the generic type definition.
-
-Aside from giving users the ability to create more parameterized types than just the built-in pointer, array \& function types, the combination of generic types with polymorphic functions and implicit conversions makes the edge case where a polymorphic function can match its own assertions much more common, as follows:
+The default-generated constructors, destructor and assignment operator for a generic type are polymorphic functions with the same list of type parameters as the generic type definition.
+
+Aside from giving users the ability to create more parameterized types than just the built-in pointer, array and function types, the combination of generic types with polymorphic functions and implicit conversions makes the edge case where a polymorphic function can match its own assertions much more common, as follows:
 \begin{itemize} 
 \item Given an expression in an untyped context, such as a top-level function call with no assignment of return values, apply a polymorphic implicit conversion to the expression that can produce multiple types (the built-in conversion from ©void*© to any other pointer type is one, but not the only).
@@ -221,5 +253,5 @@
 
 \subsection{Reference Types}
-The author, in collaboration with the rest of the \CFA research team, has been designing \emph{reference types} for \CFA. 
+I have been designing \emph{reference types} for \CFA, in collaboration with the rest of the \CFA research team. 
 Given some type ©T©, a ©T&© (``reference to ©T©'') is essentially an automatically dereferenced pointer; with these semantics most of the C standard's discussions of lvalues can be expressed in terms of references instead, with the benefit of being able to express the difference between the reference and non-reference version of a type in user code. 
 References preserve C's existing qualifier-dropping lvalue-to-rvalue conversion (\eg a ©const volatile int&© can be implicitly converted to a bare ©int©); the reference proposal also adds a rvalue-to-lvalue conversion to \CFA, implemented by storing the value in a new compiler-generated temporary and passing a reference to the temporary. 
@@ -229,5 +261,5 @@
 
 \subsection{Literal Types}
-Another proposal currently under consideration for the \CFA type system is assigning special types to the literal values ©0© and ©1©.%, say ©zero_t© and ©one_t©. 
+Another proposal currently under consideration for the \CFA type-system is assigning special types to the literal values ©0© and ©1©.%, say ©zero_t© and ©one_t©. 
 Implicit conversions from these types would allow ©0© and ©1© to be considered as values of many different types, depending on context, allowing expression desugarings like ©if ( x ) {}© $\Rightarrow$ ©if ( x != 0 ) {}© to be implemented efficiently and precicely. 
 This is a generalization of C's existing behaviour of treating ©0© as either an integer zero or a null pointer constant, and treating either of those values as boolean false. 
@@ -248,8 +280,8 @@
 Expression resolution is somewhat unavoidably exponential in $p$, the number of function parameters, and $d$, the depth of the expression tree, but these values are fixed by the user programmer, and generally bounded by reasonably small constants. 
 $k$, on the other hand, is mostly dependent on the representation of types in the system and the efficiency of type assertion checking; if a candidate argument combination can be compared to a function parameter list in linear time in the length of the list (\ie $k = 1$), then the $p^{k \cdot d}$ term is linear in the input size of the source code for the expression, otherwise the resolution algorithm will exibit sub-linear performance scaling on code containing more-deeply nested expressions.
-The number of valid interpretations of any subexpression, $i$, is bounded by the number of types in the system, which is possibly infinite, though practical resolution algorithms for \CFA must be able to place some finite bound on $i$, possibly at the expense of type system completeness. 
+The number of valid interpretations of any subexpression, $i$, is bounded by the number of types in the system, which is possibly infinite, though practical resolution algorithms for \CFA must be able to place some finite bound on $i$, possibly at the expense of type-system completeness. 
 
 The research goal of this project is to develop a performant expression resolver for \CFA; this analysis suggests two primary areas of investigation to accomplish that end. 
-The first is efficient argument-parameter matching; Bilson\cite{Bilson03} mentions significant optimization opportunities available in the current literature to improve on the existing {CFA-CC} compiler.
+The first is efficient argument-parameter matching; Bilson\cite{Bilson03} mentions significant optimization opportunities available in the current literature to improve on the existing CFA compiler.
 %TODO: look up and lit review 
 The second, and likely more fruitful, area of investigation is heuristics and algorithmic approaches to reduce the number of argument interpretations considered in the common case; given the large ($p+1$) exponent on number of interpretations considered in the runtime analysis, even small reductions here could have a significant effect on overall resolver runtime. 
@@ -299,14 +331,15 @@
 Another approach would be to generate a set of possible implicit conversions for each set of interpretations of a given argument. 
 This would have the benefit of detecting ambiguous interpretations of arguments at the level of the argument rather than its containing call, would also never find more than one interpretation of the argument with a given type, and would re-use calculation of implicit conversions between function candidates. 
-On the other hand, this approach may unncessarily generate argument interpretations that will never match a parameter, wasting work.
+On the other hand, this approach may unncessarily generate argument interpretations that will never match a parameter, wasting work. 
+Further, in the presence of tuple types this approach may lead to a combinatorial explosion of argument interpretations considered, unless the tuple can be considered as a sequence of elements rather than a unified whole.
 
 \subsection{Candidate Set Generation}
-Cormack\cite{Cormack81}, Baker\cite{Baker82} \& Bilson\cite{Bilson03} all generate the complete set of candidate argument interpretations before attempting to match the containing function call expression. 
+Cormack\cite{Cormack81}, Baker\cite{Baker82} and Bilson\cite{Bilson03} all generate the complete set of candidate argument interpretations before attempting to match the containing function call expression. 
 However, given that the top-level expression interpretation that is ultimately chosen will be the minimal-cost valid interpretation, any consideration of non-minimal-cost interpretations is in some sense wasted work.
 If we assume that user programmers will generally write function calls with relatively low-cost interpretations, a possible work-saving heuristic is to generate only the lowest-cost argument interpretations first, attempt to find a valid top-level interpretation using them, and only if that fails generate the higher-cost argument interpretations.
 
 \subsubsection{Eager}
-Within the eager approach taken by Cormack, Baker \& Bilson, there are still variants to explore. 
-Cormack \& Baker do not account for implict conversions, and thus do not account for the possibility of multiple valid interpretations with distinct costs; Bilson, on the other hand, sorts the list of interpretations to aid in finding minimal-cost interpretations. 
+Within the eager approach taken by Cormack, Baker and Bilson, there are still variants to explore. 
+Cormack and Baker do not account for implict conversions, and thus do not account for the possibility of multiple valid interpretations with distinct costs; Bilson, on the other hand, sorts the list of interpretations to aid in finding minimal-cost interpretations. 
 Sorting the lists of argument or function call interpretations by cost at some point during resolution may provide useful opportunities to short-circuit expression evaluation when a minimal-cost interpretation is found, though it is not clear if this short-circuiting behaviour would justify the cost of the sort.
 
@@ -315,5 +348,5 @@
 However, if user programmers actually use relatively few implicit conversions, then the ``on arguments'' approach to implicit conversions will generate a large number of high-cost interpretations which may never be used. 
 The essence of the lazy approach to candidate set generation is to wrap the matching algorithm into the element generator of a lazy list type, only generating as few elements at a time as possible to ensure that the next-smallest-cost interpretation has been generated. 
-Assuming that argument interpretations are provided to the parameter matching algorithm in sorted order, a sorted list of function call interpretations can be produced by generating combinations of arguments sorted by total cost\footnote{The author has developed a lazy $n$-way combination generation algorithm that can perform this task.}, then generating function call interpretations in the order suggested by this list. 
+Assuming that argument interpretations are provided to the parameter matching algorithm in sorted order, a sorted list of function call interpretations can be produced by generating combinations of arguments sorted by total cost\footnote{I have already developed a lazy $n$-way combination generation algorithm to perform this task.}, then generating function call interpretations in the order suggested by this list. 
 Note that the function call interpretation chosen may have costs of its own, for instance polymorphic type binding, so in some cases a number of argument combinations (any combination whose marginal cost does not exceed the cost of the function call interpretation itself) may need to be considered to determine the next-smallest-cost function call interpretation.
 Ideally, this candidate generation approach will lead to very few unused candidates being generated (in the expected case where the user programmer has, in fact, provided a validly-typable program), but this research project will need to determine whether or not the overheads of lazy generation exceed the benefit produced from considering fewer interpretations.
@@ -333,5 +366,5 @@
 %\subsection{Parameter-Directed}
 %\textbf{TODO: Richard's algorithm isn't Baker (Cormack?), disentangle from this section \ldots}. 
-%The expression resolution algorithm used by the existing iteration of {CFA-CC} is based on Baker's\cite{Baker82} algorithm for overload resolution in Ada. 
+%The expression resolution algorithm used by the existing iteration of CFA is based on Baker's\cite{Baker82} algorithm for overload resolution in Ada. 
 %The essential idea of this algorithm is to first find the possible interpretations of the most deeply nested subexpressions, then to use these interpretations to recursively generate valid interpretations of their superexpressions. 
 %To simplify matters, the only expressions considered in this discussion of the algorithm are function application and literal expressions; other expression types can generally be considered to be variants of one of these for the purposes of the resolver, \eg variables are essentially zero-argument functions. 
@@ -341,5 +374,5 @@
 %\textbf{TODO: Figure}
 %
-%Baker's algorithm was designed to account for name overloading; Richard Bilson\cite{Bilson03} extended this algorithm to also handle polymorphic functions, implicit conversions \& multiple return types when designing the original \CFA compiler. 
+%Baker's algorithm was designed to account for name overloading; Richard Bilson\cite{Bilson03} extended this algorithm to also handle polymorphic functions, implicit conversions and multiple return types when designing the original \CFA compiler. 
 %The core of the algorithm is a function which Baker refers to as $gen\_calls$. 
 %$gen\_calls$ takes as arguments the name of a function $f$ and a list containing the set of possible subexpression interpretations $S_j$ for each argument of the function and returns a set of possible interpretations of calling that function on those arguments. 
@@ -363,14 +396,14 @@
 \section{Proposal}
 Baker\cite{Baker82} discussed various expression resolution algorithms that could handle name overloading, but left experimental comparison of those algorithms to future work; Bilson\cite{Bilson03} described one extension of Baker's algorithm to handle implicit conversions, but did not fully explore the space of algorithmic approaches to handle both overloaded names and implicit conversions. 
-This project is intended to experimentally test a number of expression resolution algorithms which are powerful enough to handle the \CFA type system, including both name overloading and implicit conversions. 
+This project is intended to experimentally test a number of expression resolution algorithms which are powerful enough to handle the \CFA type-system, including both name overloading and implicit conversions. 
 This comparison will close Baker's open research question, as well as potentially improving on Bilson's \CFA compiler.
 
-Rather than testing all of these algorithms in-place in the \CFA compiler, a resolver prototype will be developed which acts on a simplified input language encapsulating the essential details of the \CFA type system\footnote{Note that this simplified input language is not required to be a usable programming language.}. 
+Rather than testing all of these algorithms in-place in the \CFA compiler, a resolver prototype will be developed which acts on a simplified input language encapsulating the essential details of the \CFA type-system\footnote{Note that this simplified input language is not required to be a usable programming language.}. 
 Multiple variants of this resolver prototype will be implemented, each encapsulating a different expression resolution variant, sharing as much code as feasible. 
 These variants will be instrumented to test runtime performance, and run on a variety of input files; the input files may be generated programmatically or from exisiting code in \CFA or similar languages.
-These experimental results will allow the research team to determine the algorithm likely to be most performant in practical use, and replace {CFA-CC}'s existing expression resolver with that code. 
+These experimental results will allow the research team to determine the algorithm likely to be most performant in practical use, and replace CFA's existing expression resolver with that code. 
 The experimental results will also provide some empirical sense of the compile-time cost of various language features by comparing the results of the most performant resolver variant that supports the feature with the most performant resolver variant that doesn't, a useful capability to guide language design.
 
-This proposed project should provide valuable data on how to implement a performant compiler for modern programming languages such as \CFA with powerful static type systems, specifically targeting the feature interaction between name overloading and implicit conversions.
+This proposed project should provide valuable data on how to implement a performant compiler for modern programming languages such as \CFA with powerful static type-systems, specifically targeting the feature interaction between name overloading and implicit conversions.
 
 \appendix
@@ -379,8 +412,8 @@
 \begin{center}
 \begin{tabular}{ | r @{--} l | p{4in} | }
-\hline       May 2015 & April 2016   & Project familiarization and generic types design \& implementation. \\
-\hline       May 2016 & April 2017   & Design \& implement resolver prototype and run performance experiments. \\
-\hline       May 2017 & August 2017  & Integrate new language features and best-performing resolver prototype into {CFA-CC}. \\
-\hline September 2017 & January 2018 & Thesis writing \& defense. \\
+\hline       May 2015 & April 2016   & Project familiarization and generic types design and implementation. \\
+\hline       May 2016 & April 2017   & Design and implement resolver prototype and run performance experiments. \\
+\hline       May 2017 & August 2017  & Integrate new language features and best-performing resolver prototype into CFA. \\
+\hline September 2017 & January 2018 & Thesis writing and defense. \\
 \hline
 \end{tabular}
Index: doc/working/resolver_design.md
===================================================================
--- doc/working/resolver_design.md	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ doc/working/resolver_design.md	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -37,5 +37,5 @@
 
 An alternate possibility would be to only count two-arg constructors 
-`void ?{} ( To*, From )` as unsafe conversions; under this semantics, safe and  
+`void ?{} ( To*, From )` as unsafe conversions; under this semantics, safe and 
 explicit conversions should also have a compiler-enforced restriction to 
 ensure that they are two-arg functions (this restriction may be valuable 
@@ -69,5 +69,5 @@
 two chains of conversions, one among the signed integral types, another among 
 the unsigned, and to use monomorphic conversions to allow conversions between 
-signed and unsigned integer types).   
+signed and unsigned integer types).
 
 ### Implementation Details ###
@@ -509,5 +509,5 @@
 A variant of the above scheme would be to fix a maximum depth of polymorphic 
 type variables (16 seems like a reasonable choice) at which a parameter would 
-be considered to be effectively monomorphic, and to subtract the value  
+be considered to be effectively monomorphic, and to subtract the value 
 described above from that maximum, clamping the result to a minimum of 0. 
 Under this scheme, assuming a maximum value of 4, `int` has value 0, `T` has 
@@ -577,5 +577,5 @@
 specifying the (completely arbitrary) maximum depth as part of the language or 
 allowing the compiler to refuse to accept otherwise well-typed deeply-nested 
-polymorphic types.  
+polymorphic types.
 
 For purposes of determining polymorphism, the list of return types of a 
@@ -951,7 +951,7 @@
 `sizeof`, `alignof`, and `offsetof` expressions have at most a single 
 interpretation, of type `size_t`. 
-`sizeof` and `alignof` expressions take either a type or an expression as a  
-an argument; if the argument is a type, it must be a complete type which is 
-not a function type, if an expression, the expression must have a single 
+`sizeof` and `alignof` expressions take either a type or an expression as an 
+argument; if the argument is a type, it must be a complete type which is not a 
+function type, if an expression, the expression must have a single 
 interpretation, the type of which conforms to the same rules. 
 `offsetof` takes two arguments, a type and a member name; the type must be 
@@ -1620,2 +1620,9 @@
 			= delete;
 	}
+
+## Appendix E: Features to Add in Resolver Re-write ##
+* Reference types
+* Special types for 0 and 1 literals
+* Expression type for return statement that resolves similarly to ?=?
+  - This is to get rid of the kludge in the box pass that effectively 
+    re-implements the resolver poorly.
Index: src/CodeGen/CodeGenerator.cc
===================================================================
--- src/CodeGen/CodeGenerator.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/CodeGen/CodeGenerator.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -148,4 +148,6 @@
 	void CodeGenerator::visit( ObjectDecl * objectDecl ) {
 		extension( objectDecl );
+		genAttributes( objectDecl->get_attributes() );
+
 		handleStorageClass( objectDecl );
 		output << genType( objectDecl->get_type(), mangleName( objectDecl ) );
@@ -271,9 +273,9 @@
 		printDesignators( init->get_designators() );
 		output << "{ ";
-		if ( init->begin_initializers() == init->end_initializers() ) {
+		if ( init->begin() == init->end() ) {
 			// illegal to leave initializer list empty for scalar initializers, but always legal to have 0
 			output << "0";
 		} else {
-			genCommaList( init->begin_initializers(), init->end_initializers() );
+			genCommaList( init->begin(), init->end() );
 		} // if
 		output << " }";
Index: src/GenPoly/Box.cc
===================================================================
--- src/GenPoly/Box.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/GenPoly/Box.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -62,91 +62,4 @@
 
 		FunctionType *makeAdapterType( FunctionType *adaptee, const TyVarMap &tyVars );
-
-		/// Abstracts type equality for a list of parameter types
-		struct TypeList {
-			TypeList() : params() {}
-			TypeList( const std::list< Type* > &_params ) : params() { cloneAll(_params, params); }
-			TypeList( std::list< Type* > &&_params ) : params( _params ) {}
-
-			TypeList( const TypeList &that ) : params() { cloneAll(that.params, params); }
-			TypeList( TypeList &&that ) : params( std::move( that.params ) ) {}
-
-			/// Extracts types from a list of TypeExpr*
-			TypeList( const std::list< TypeExpr* >& _params ) : params() {
-				for ( std::list< TypeExpr* >::const_iterator param = _params.begin(); param != _params.end(); ++param ) {
-					params.push_back( (*param)->get_type()->clone() );
-				}
-			}
-
-			TypeList& operator= ( const TypeList &that ) {
-				deleteAll( params );
-
-				params.clear();
-				cloneAll( that.params, params );
-
-				return *this;
-			}
-
-			TypeList& operator= ( TypeList &&that ) {
-				deleteAll( params );
-
-				params = std::move( that.params );
-
-				return *this;
-			}
-
-			~TypeList() { deleteAll( params ); }
-
-			bool operator== ( const TypeList& that ) const {
-				if ( params.size() != that.params.size() ) return false;
-
-				SymTab::Indexer dummy;
-				for ( std::list< Type* >::const_iterator it = params.begin(), jt = that.params.begin(); it != params.end(); ++it, ++jt ) {
-					if ( ! ResolvExpr::typesCompatible( *it, *jt, dummy ) ) return false;
-				}
-				return true;
-			}
-
-			std::list< Type* > params;  ///< Instantiation parameters
-		};
-
-		/// Maps a key and a TypeList to the some value, accounting for scope
-		template< typename Key, typename Value >
-		class InstantiationMap {
-			/// Wraps value for a specific (Key, TypeList) combination
-			typedef std::pair< TypeList, Value* > Instantiation;
-			/// List of TypeLists paired with their appropriate values
-			typedef std::vector< Instantiation > ValueList;
-			/// Underlying map type; maps keys to a linear list of corresponding TypeLists and values
-			typedef ScopedMap< Key*, ValueList > InnerMap;
-
-			InnerMap instantiations;  ///< instantiations
-
-		public:
-			/// Starts a new scope
-			void beginScope() { instantiations.beginScope(); }
-
-			/// Ends a scope
-			void endScope() { instantiations.endScope(); }
-
-			/// Gets the value for the (key, typeList) pair, returns NULL on none such.
-			Value *lookup( Key *key, const std::list< TypeExpr* >& params ) const {
- 				TypeList typeList( params );
-
-				// scan scopes for matches to the key
-				for ( typename InnerMap::const_iterator insts = instantiations.find( key ); insts != instantiations.end(); insts = instantiations.findNext( insts, key ) ) {
-					for ( typename ValueList::const_reverse_iterator inst = insts->second.rbegin(); inst != insts->second.rend(); ++inst ) {
-						if ( inst->first == typeList ) return inst->second;
-					}
-				}
-				// no matching instantiations found
-				return 0;
-			}
-
-			/// Adds a value for a (key, typeList) pair to the current scope
-			void insert( Key *key, const std::list< TypeExpr* > &params, Value *value ) {
-				instantiations[ key ].push_back( Instantiation( TypeList( params ), value ) );
-			}
-		};
 
 		/// Adds layout-generation functions to polymorphic types
@@ -239,32 +152,4 @@
 		};
 
-		/// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
-		class GenericInstantiator : public DeclMutator {
-			/// Map of (generic type, parameter list) pairs to concrete type instantiations
-			InstantiationMap< AggregateDecl, AggregateDecl > instantiations;
-			/// Namer for concrete types
-			UniqueName typeNamer;
-
-		public:
-			GenericInstantiator() : DeclMutator(), instantiations(), typeNamer("_conc_") {}
-
-			virtual Type* mutate( StructInstType *inst );
-			virtual Type* mutate( UnionInstType *inst );
-
-	// 		virtual Expression* mutate( MemberExpr *memberExpr );
-
-			virtual void doBeginScope();
-			virtual void doEndScope();
-		private:
-			/// Wrap instantiation lookup for structs
-			StructDecl* lookup( StructInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (StructDecl*)instantiations.lookup( inst->get_baseStruct(), typeSubs ); }
-			/// Wrap instantiation lookup for unions
-			UnionDecl* lookup( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (UnionDecl*)instantiations.lookup( inst->get_baseUnion(), typeSubs ); }
-			/// Wrap instantiation insertion for structs
-			void insert( StructInstType *inst, const std::list< TypeExpr* > &typeSubs, StructDecl *decl ) { instantiations.insert( inst->get_baseStruct(), typeSubs, decl ); }
-			/// Wrap instantiation insertion for unions
-			void insert( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs, UnionDecl *decl ) { instantiations.insert( inst->get_baseUnion(), typeSubs, decl ); }
-		};
-
 		/// Replaces member and size/align/offsetof expressions on polymorphic generic types with calculated expressions.
 		/// * Replaces member expressions for polymorphic types with calculated add-field-offset-and-dereference
@@ -354,5 +239,4 @@
 		Pass1 pass1;
 		Pass2 pass2;
-		GenericInstantiator instantiator;
 		PolyGenericCalculator polyCalculator;
 		Pass3 pass3;
@@ -361,5 +245,4 @@
 		mutateTranslationUnit/*All*/( translationUnit, pass1 );
 		mutateTranslationUnit/*All*/( translationUnit, pass2 );
-		instantiator.mutateDeclarationList( translationUnit );
 		mutateTranslationUnit/*All*/( translationUnit, polyCalculator );
 		mutateTranslationUnit/*All*/( translationUnit, pass3 );
@@ -889,5 +772,5 @@
 						arg++;
 					} else {
-						/// xxx - should this be an assertion?
+						// xxx - should this be an assertion?
 						throw SemanticError( "unbound type variable: " + tyParm->first + " in application ", appExpr );
 					} // if
@@ -902,5 +785,5 @@
 			std::list< DeclarationWithType* >::const_iterator fnParm = funcType->get_parameters().begin();
 			std::list< Expression* >::const_iterator fnArg = arg;
-			std::set< std::string > seenTypes; //< names for generic types we've seen
+			std::set< std::string > seenTypes; ///< names for generic types we've seen
 
 			// a polymorphic return type may need to be added to the argument list
@@ -1042,6 +925,6 @@
 		/// this gets rid of warnings from gcc.
 		void addCast( Expression *&actual, Type *formal, const TyVarMap &tyVars ) {
-			Type * newType = formal->clone();
-			if ( getFunctionType( newType ) ) {
+			if ( getFunctionType( formal ) ) {
+				Type * newType = formal->clone();
 				newType = ScrubTyVars::scrub( newType, tyVars );
 				actual = new CastExpr( actual, newType );
@@ -1775,193 +1658,4 @@
 		}
 
-//////////////////////////////////////// GenericInstantiator //////////////////////////////////////////////////
-
-		/// Makes substitutions of params into baseParams; returns true if all parameters substituted for a concrete type
-		bool makeSubstitutions( const std::list< TypeDecl* >& baseParams, const std::list< Expression* >& params, std::list< TypeExpr* >& out ) {
-			bool allConcrete = true;  // will finish the substitution list even if they're not all concrete
-
-			// substitute concrete types for given parameters, and incomplete types for placeholders
-			std::list< TypeDecl* >::const_iterator baseParam = baseParams.begin();
-			std::list< Expression* >::const_iterator param = params.begin();
-			for ( ; baseParam != baseParams.end() && param != params.end(); ++baseParam, ++param ) {
-	// 			switch ( (*baseParam)->get_kind() ) {
-	// 			case TypeDecl::Any: {   // any type is a valid substitution here; complete types can be used to instantiate generics
-					TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
-					assert(paramType && "Aggregate parameters should be type expressions");
-					out.push_back( paramType->clone() );
-					// check that the substituted type isn't a type variable itself
-					if ( dynamic_cast< TypeInstType* >( paramType->get_type() ) ) {
-						allConcrete = false;
-					}
-	// 				break;
-	// 			}
-	// 			case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
-	// 				out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
-	// 				break;
-	// 			case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
-	// 				out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
-	// 				break;
-	// 			}
-			}
-
-			// if any parameters left over, not done
-			if ( baseParam != baseParams.end() ) return false;
-	// 		// if not enough parameters given, substitute remaining incomplete types for placeholders
-	// 		for ( ; baseParam != baseParams.end(); ++baseParam ) {
-	// 			switch ( (*baseParam)->get_kind() ) {
-	// 			case TypeDecl::Any:    // no more substitutions here, fail early
-	// 				return false;
-	// 			case TypeDecl::Dtype:  // dtype can be consistently replaced with void [only pointers, which become void*]
-	// 				out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
-	// 				break;
-	// 			case TypeDecl::Ftype:  // pointer-to-ftype can be consistently replaced with void (*)(void) [similar to dtype]
-	// 				out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
-	// 				break;
-	// 			}
-	// 		}
-
-			return allConcrete;
-		}
-
-		/// Substitutes types of members of in according to baseParams => typeSubs, appending the result to out
-		void substituteMembers( const std::list< Declaration* >& in, const std::list< TypeDecl* >& baseParams, const std::list< TypeExpr* >& typeSubs,
-								std::list< Declaration* >& out ) {
-			// substitute types into new members
-			TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() );
-			for ( std::list< Declaration* >::const_iterator member = in.begin(); member != in.end(); ++member ) {
-				Declaration *newMember = (*member)->clone();
-				subs.apply(newMember);
-				out.push_back( newMember );
-			}
-		}
-
-		Type* GenericInstantiator::mutate( StructInstType *inst ) {
-			// mutate subtypes
-			Type *mutated = Mutator::mutate( inst );
-			inst = dynamic_cast< StructInstType* >( mutated );
-			if ( ! inst ) return mutated;
-
-			// exit early if no need for further mutation
-			if ( inst->get_parameters().empty() ) return inst;
-			assert( inst->get_baseParameters() && "Base struct has parameters" );
-
-			// check if type can be concretely instantiated; put substitutions into typeSubs
-			std::list< TypeExpr* > typeSubs;
-			if ( ! makeSubstitutions( *inst->get_baseParameters(), inst->get_parameters(), typeSubs ) ) {
-				deleteAll( typeSubs );
-				return inst;
-			}
-
-			// make concrete instantiation of generic type
-			StructDecl *concDecl = lookup( inst, typeSubs );
-			if ( ! concDecl ) {
-				// set concDecl to new type, insert type declaration into statements to add
-				concDecl = new StructDecl( typeNamer.newName( inst->get_name() ) );
-				substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, 	concDecl->get_members() );
-				DeclMutator::addDeclaration( concDecl );
-				insert( inst, typeSubs, concDecl );
-			}
-			StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() );
-			newInst->set_baseStruct( concDecl );
-
-			deleteAll( typeSubs );
-			delete inst;
-			return newInst;
-		}
-
-		Type* GenericInstantiator::mutate( UnionInstType *inst ) {
-			// mutate subtypes
-			Type *mutated = Mutator::mutate( inst );
-			inst = dynamic_cast< UnionInstType* >( mutated );
-			if ( ! inst ) return mutated;
-
-			// exit early if no need for further mutation
-			if ( inst->get_parameters().empty() ) return inst;
-			assert( inst->get_baseParameters() && "Base union has parameters" );
-
-			// check if type can be concretely instantiated; put substitutions into typeSubs
-			std::list< TypeExpr* > typeSubs;
-			if ( ! makeSubstitutions( *inst->get_baseParameters(), inst->get_parameters(), typeSubs ) ) {
-				deleteAll( typeSubs );
-				return inst;
-			}
-
-			// make concrete instantiation of generic type
-			UnionDecl *concDecl = lookup( inst, typeSubs );
-			if ( ! concDecl ) {
-				// set concDecl to new type, insert type declaration into statements to add
-				concDecl = new UnionDecl( typeNamer.newName( inst->get_name() ) );
-				substituteMembers( inst->get_baseUnion()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
-				DeclMutator::addDeclaration( concDecl );
-				insert( inst, typeSubs, concDecl );
-			}
-			UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() );
-			newInst->set_baseUnion( concDecl );
-
-			deleteAll( typeSubs );
-			delete inst;
-			return newInst;
-		}
-
-	// 	/// Gets the base struct or union declaration for a member expression; NULL if not applicable
-	// 	AggregateDecl* getMemberBaseDecl( MemberExpr *memberExpr ) {
-	// 		// get variable for member aggregate
-	// 		VariableExpr *varExpr = dynamic_cast< VariableExpr* >( memberExpr->get_aggregate() );
-	// 		if ( ! varExpr ) return NULL;
-	//
-	// 		// get object for variable
-	// 		ObjectDecl *objectDecl = dynamic_cast< ObjectDecl* >( varExpr->get_var() );
-	// 		if ( ! objectDecl ) return NULL;
-	//
-	// 		// get base declaration from object type
-	// 		Type *objectType = objectDecl->get_type();
-	// 		StructInstType *structType = dynamic_cast< StructInstType* >( objectType );
-	// 		if ( structType ) return structType->get_baseStruct();
-	// 		UnionInstType *unionType = dynamic_cast< UnionInstType* >( objectType );
-	// 		if ( unionType ) return unionType->get_baseUnion();
-	//
-	// 		return NULL;
-	// 	}
-	//
-	// 	/// Finds the declaration with the given name, returning decls.end() if none such
-	// 	std::list< Declaration* >::const_iterator findDeclNamed( const std::list< Declaration* > &decls, const std::string &name ) {
-	// 		for( std::list< Declaration* >::const_iterator decl = decls.begin(); decl != decls.end(); ++decl ) {
-	// 			if ( (*decl)->get_name() == name ) return decl;
-	// 		}
-	// 		return decls.end();
-	// 	}
-	//
-	// 	Expression* Instantiate::mutate( MemberExpr *memberExpr ) {
-	// 		// mutate, exiting early if no longer MemberExpr
-	// 		Expression *expr = Mutator::mutate( memberExpr );
-	// 		memberExpr = dynamic_cast< MemberExpr* >( expr );
-	// 		if ( ! memberExpr ) return expr;
-	//
-	// 		// get declaration of member and base declaration of member, exiting early if not found
-	// 		AggregateDecl *memberBase = getMemberBaseDecl( memberExpr );
-	// 		if ( ! memberBase ) return memberExpr;
-	// 		DeclarationWithType *memberDecl = memberExpr->get_member();
-	// 		std::list< Declaration* >::const_iterator baseIt = findDeclNamed( memberBase->get_members(), memberDecl->get_name() );
-	// 		if ( baseIt == memberBase->get_members().end() ) return memberExpr;
-	// 		DeclarationWithType *baseDecl = dynamic_cast< DeclarationWithType* >( *baseIt );
-	// 		if ( ! baseDecl ) return memberExpr;
-	//
-	// 		// check if stated type of the member is not the type of the member's declaration; if so, need a cast
-	// 		// this *SHOULD* be safe, I don't think anything but the void-replacements I put in for dtypes would make it past the typechecker
-	// 		SymTab::Indexer dummy;
-	// 		if ( ResolvExpr::typesCompatible( memberDecl->get_type(), baseDecl->get_type(), dummy ) ) return memberExpr;
-	// 		else return new CastExpr( memberExpr, memberDecl->get_type() );
-	// 	}
-
-		void GenericInstantiator::doBeginScope() {
-			DeclMutator::doBeginScope();
-			instantiations.beginScope();
-		}
-
-		void GenericInstantiator::doEndScope() {
-			DeclMutator::doEndScope();
-			instantiations.endScope();
-		}
-
 ////////////////////////////////////////// PolyGenericCalculator ////////////////////////////////////////////////////
 
@@ -2107,4 +1801,5 @@
 			findGeneric( objectType ); // ensure layout for this type is available
 
+			// replace member expression with dynamically-computed layout expression
 			Expression *newMemberExpr = 0;
 			if ( StructInstType *structType = dynamic_cast< StructInstType* >( objectType ) ) {
Index: src/GenPoly/DeclMutator.h
===================================================================
--- src/GenPoly/DeclMutator.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/GenPoly/DeclMutator.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -28,7 +28,10 @@
 	class DeclMutator : public Mutator {
 	public:
+		typedef Mutator Parent;
+
 		DeclMutator();
 		virtual ~DeclMutator();
-		
+
+		using Parent::mutate;
 		virtual CompoundStmt* mutate(CompoundStmt *compoundStmt);
 		virtual Statement* mutate(IfStmt *ifStmt);
@@ -42,5 +45,5 @@
 		/// Mutates a list of declarations with this visitor
 		void mutateDeclarationList(std::list< Declaration* >& decls);
-		
+
 		/// Called on entry to a new scope; overriders should call this as a super-class call
 		virtual void doBeginScope();
Index: src/GenPoly/InstantiateGeneric.cc
===================================================================
--- src/GenPoly/InstantiateGeneric.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
+++ src/GenPoly/InstantiateGeneric.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -0,0 +1,326 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// InstantiateGeneric.cc --
+//
+// Author           : Aaron B. Moss
+// Created On       : Thu Aug 04 18:33:00 2016
+// Last Modified By : Aaron B. Moss
+// Last Modified On : Thu Aug 04 18:33:00 2016
+// Update Count     : 1
+//
+
+#include <cassert>
+#include <list>
+#include <utility>
+#include <vector>
+
+#include "InstantiateGeneric.h"
+
+#include "DeclMutator.h"
+#include "GenPoly.h"
+#include "ScopedMap.h"
+
+#include "ResolvExpr/typeops.h"
+
+#include "SynTree/Declaration.h"
+#include "SynTree/Expression.h"
+#include "SynTree/Type.h"
+
+#include "Common/UniqueName.h"
+#include "Common/utility.h"
+
+namespace GenPoly {
+
+	/// Abstracts type equality for a list of parameter types
+	struct TypeList {
+		TypeList() : params() {}
+		TypeList( const std::list< Type* > &_params ) : params() { cloneAll(_params, params); }
+		TypeList( std::list< Type* > &&_params ) : params( _params ) {}
+
+		TypeList( const TypeList &that ) : params() { cloneAll(that.params, params); }
+		TypeList( TypeList &&that ) : params( std::move( that.params ) ) {}
+
+		/// Extracts types from a list of TypeExpr*
+		TypeList( const std::list< TypeExpr* >& _params ) : params() {
+			for ( std::list< TypeExpr* >::const_iterator param = _params.begin(); param != _params.end(); ++param ) {
+				params.push_back( (*param)->get_type()->clone() );
+			}
+		}
+
+		TypeList& operator= ( const TypeList &that ) {
+			deleteAll( params );
+
+			params.clear();
+			cloneAll( that.params, params );
+
+			return *this;
+		}
+
+		TypeList& operator= ( TypeList &&that ) {
+			deleteAll( params );
+
+			params = std::move( that.params );
+
+			return *this;
+		}
+
+		~TypeList() { deleteAll( params ); }
+
+		bool operator== ( const TypeList& that ) const {
+			if ( params.size() != that.params.size() ) return false;
+
+			SymTab::Indexer dummy;
+			for ( std::list< Type* >::const_iterator it = params.begin(), jt = that.params.begin(); it != params.end(); ++it, ++jt ) {
+				if ( ! ResolvExpr::typesCompatible( *it, *jt, dummy ) ) return false;
+			}
+			return true;
+		}
+
+		std::list< Type* > params;  ///< Instantiation parameters
+	};
+	
+	/// Maps a key and a TypeList to the some value, accounting for scope
+	template< typename Key, typename Value >
+	class InstantiationMap {
+		/// Wraps value for a specific (Key, TypeList) combination
+		typedef std::pair< TypeList, Value* > Instantiation;
+		/// List of TypeLists paired with their appropriate values
+		typedef std::vector< Instantiation > ValueList;
+		/// Underlying map type; maps keys to a linear list of corresponding TypeLists and values
+		typedef ScopedMap< Key*, ValueList > InnerMap;
+
+		InnerMap instantiations;  ///< instantiations
+
+	public:
+		/// Starts a new scope
+		void beginScope() { instantiations.beginScope(); }
+
+		/// Ends a scope
+		void endScope() { instantiations.endScope(); }
+
+		/// Gets the value for the (key, typeList) pair, returns NULL on none such.
+		Value *lookup( Key *key, const std::list< TypeExpr* >& params ) const {
+			TypeList typeList( params );
+
+			// scan scopes for matches to the key
+			for ( typename InnerMap::const_iterator insts = instantiations.find( key ); insts != instantiations.end(); insts = instantiations.findNext( insts, key ) ) {
+				for ( typename ValueList::const_reverse_iterator inst = insts->second.rbegin(); inst != insts->second.rend(); ++inst ) {
+					if ( inst->first == typeList ) return inst->second;
+				}
+			}
+			// no matching instantiations found
+			return 0;
+		}
+
+		/// Adds a value for a (key, typeList) pair to the current scope
+		void insert( Key *key, const std::list< TypeExpr* > &params, Value *value ) {
+			instantiations[ key ].push_back( Instantiation( TypeList( params ), value ) );
+		}
+	};
+	
+	/// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
+	class GenericInstantiator : public DeclMutator {
+		/// Map of (generic type, parameter list) pairs to concrete type instantiations
+		InstantiationMap< AggregateDecl, AggregateDecl > instantiations;
+		/// Namer for concrete types
+		UniqueName typeNamer;
+
+	public:
+		GenericInstantiator() : DeclMutator(), instantiations(), typeNamer("_conc_") {}
+
+		virtual Type* mutate( StructInstType *inst );
+		virtual Type* mutate( UnionInstType *inst );
+
+		virtual void doBeginScope();
+		virtual void doEndScope();
+	private:
+		/// Wrap instantiation lookup for structs
+		StructDecl* lookup( StructInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (StructDecl*)instantiations.lookup( inst->get_baseStruct(), typeSubs ); }
+		/// Wrap instantiation lookup for unions
+		UnionDecl* lookup( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs ) { return (UnionDecl*)instantiations.lookup( inst->get_baseUnion(), typeSubs ); }
+		/// Wrap instantiation insertion for structs
+		void insert( StructInstType *inst, const std::list< TypeExpr* > &typeSubs, StructDecl *decl ) { instantiations.insert( inst->get_baseStruct(), typeSubs, decl ); }
+		/// Wrap instantiation insertion for unions
+		void insert( UnionInstType *inst, const std::list< TypeExpr* > &typeSubs, UnionDecl *decl ) { instantiations.insert( inst->get_baseUnion(), typeSubs, decl ); }
+	};
+
+	void instantiateGeneric( std::list< Declaration* > &translationUnit ) {
+		GenericInstantiator instantiator;
+		instantiator.mutateDeclarationList( translationUnit );
+	}
+
+	//////////////////////////////////////// GenericInstantiator //////////////////////////////////////////////////
+
+	/// Possible options for a given specialization of a generic type
+	enum class genericType {
+		dtypeStatic,  ///< Concrete instantiation based solely on {d,f}type-to-void conversions
+		concrete,     ///< Concrete instantiation requiring at least one parameter type
+		dynamic       ///< No concrete instantiation
+	};
+
+	genericType& operator |= ( genericType& gt, const genericType& ht ) {
+		switch ( gt ) {
+		case genericType::dtypeStatic:
+			gt = ht;
+			break;
+		case genericType::concrete:
+			if ( ht == genericType::dynamic ) { gt = genericType::dynamic; }
+			break;
+		case genericType::dynamic:
+			// nothing possible
+			break;
+		}
+		return gt;
+	}
+
+	/// Makes substitutions of params into baseParams; returns true if all parameters substituted for a concrete type
+	genericType makeSubstitutions( const std::list< TypeDecl* >& baseParams, const std::list< Expression* >& params, std::list< TypeExpr* >& out ) {
+		genericType gt = genericType::dtypeStatic;
+
+		// substitute concrete types for given parameters, and incomplete types for placeholders
+		std::list< TypeDecl* >::const_iterator baseParam = baseParams.begin();
+		std::list< Expression* >::const_iterator param = params.begin();
+		for ( ; baseParam != baseParams.end() && param != params.end(); ++baseParam, ++param ) {
+			TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
+			assert(paramType && "Aggregate parameters should be type expressions");
+			
+			switch ( (*baseParam)->get_kind() ) {
+			case TypeDecl::Any: {
+				// substitute parameter for otype; makes the type concrete or dynamic depending on the parameter
+				out.push_back( paramType->clone() );
+				gt |= isPolyType( paramType->get_type() ) ? genericType::dynamic : genericType::concrete;
+				break;
+			}
+			case TypeDecl::Dtype:
+				// can pretend that any dtype is `void`
+				out.push_back( new TypeExpr( new VoidType( Type::Qualifiers() ) ) );
+				break;
+			case TypeDecl::Ftype:
+				// can pretend that any ftype is `void (*)(void)`
+				out.push_back( new TypeExpr( new FunctionType( Type::Qualifiers(), false ) ) );
+				break;
+			}
+		}
+
+		assert( baseParam == baseParams.end() && param == params.end() && "Type parameters should match type variables" );
+		return gt;
+	}
+
+	/// Substitutes types of members of in according to baseParams => typeSubs, appending the result to out
+	void substituteMembers( const std::list< Declaration* >& in, const std::list< TypeDecl* >& baseParams, const std::list< TypeExpr* >& typeSubs,
+							std::list< Declaration* >& out ) {
+		// substitute types into new members
+		TypeSubstitution subs( baseParams.begin(), baseParams.end(), typeSubs.begin() );
+		for ( std::list< Declaration* >::const_iterator member = in.begin(); member != in.end(); ++member ) {
+			Declaration *newMember = (*member)->clone();
+			subs.apply(newMember);
+			out.push_back( newMember );
+		}
+	}
+
+	Type* GenericInstantiator::mutate( StructInstType *inst ) {
+		// mutate subtypes
+		Type *mutated = Mutator::mutate( inst );
+		inst = dynamic_cast< StructInstType* >( mutated );
+		if ( ! inst ) return mutated;
+
+		// exit early if no need for further mutation
+		if ( inst->get_parameters().empty() ) return inst;
+		assert( inst->get_baseParameters() && "Base struct has parameters" );
+
+		// check if type can be concretely instantiated; put substitutions into typeSubs
+		std::list< TypeExpr* > typeSubs;
+		genericType gt = makeSubstitutions( *inst->get_baseParameters(), inst->get_parameters(), typeSubs );
+		switch ( gt ) {
+		case genericType::dtypeStatic: // TODO strip params off original decl and reuse here
+		case genericType::concrete:
+		{
+			// make concrete instantiation of generic type
+			StructDecl *concDecl = lookup( inst, typeSubs );
+			if ( ! concDecl ) {
+				// set concDecl to new type, insert type declaration into statements to add
+				concDecl = new StructDecl( typeNamer.newName( inst->get_name() ) );
+				substituteMembers( inst->get_baseStruct()->get_members(), *inst->get_baseParameters(), typeSubs, 	concDecl->get_members() );
+				DeclMutator::addDeclaration( concDecl );
+				insert( inst, typeSubs, concDecl );
+			}
+			StructInstType *newInst = new StructInstType( inst->get_qualifiers(), concDecl->get_name() );
+			newInst->set_baseStruct( concDecl );
+
+			delete inst;
+			inst = newInst;
+			break;
+		}
+
+		case genericType::dynamic:
+			// do nothing
+			break;
+		}
+
+		deleteAll( typeSubs );
+		return inst;
+	}
+
+	Type* GenericInstantiator::mutate( UnionInstType *inst ) {
+		// mutate subtypes
+		Type *mutated = Mutator::mutate( inst );
+		inst = dynamic_cast< UnionInstType* >( mutated );
+		if ( ! inst ) return mutated;
+
+		// exit early if no need for further mutation
+		if ( inst->get_parameters().empty() ) return inst;
+		assert( inst->get_baseParameters() && "Base union has parameters" );
+
+		// check if type can be concretely instantiated; put substitutions into typeSubs
+		std::list< TypeExpr* > typeSubs;
+		genericType gt = makeSubstitutions( *inst->get_baseParameters(), inst->get_parameters(), typeSubs );
+		switch ( gt ) {
+		case genericType::dtypeStatic:  // TODO strip params off original decls and reuse here
+		case genericType::concrete:
+		{
+			// make concrete instantiation of generic type
+			UnionDecl *concDecl = lookup( inst, typeSubs );
+			if ( ! concDecl ) {
+				// set concDecl to new type, insert type declaration into statements to add
+				concDecl = new UnionDecl( typeNamer.newName( inst->get_name() ) );
+				substituteMembers( inst->get_baseUnion()->get_members(), *inst->get_baseParameters(), typeSubs, concDecl->get_members() );
+				DeclMutator::addDeclaration( concDecl );
+				insert( inst, typeSubs, concDecl );
+			}
+			UnionInstType *newInst = new UnionInstType( inst->get_qualifiers(), concDecl->get_name() );
+			newInst->set_baseUnion( concDecl );
+
+			delete inst;
+			inst = newInst;
+			break;
+		}
+		case genericType::dynamic:
+			// do nothing
+			break;
+		}
+
+		deleteAll( typeSubs );
+		return inst;
+	}
+
+	void GenericInstantiator::doBeginScope() {
+		DeclMutator::doBeginScope();
+		instantiations.beginScope();
+	}
+
+	void GenericInstantiator::doEndScope() {
+		DeclMutator::doEndScope();
+		instantiations.endScope();
+	}
+
+} // namespace GenPoly
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/InstantiateGeneric.h
===================================================================
--- src/GenPoly/InstantiateGeneric.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
+++ src/GenPoly/InstantiateGeneric.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -0,0 +1,34 @@
+//
+// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
+//
+// The contents of this file are covered under the licence agreement in the
+// file "LICENCE" distributed with Cforall.
+//
+// InstantiateGeneric.h --
+//
+// Author           : Aaron B. Moss
+// Created On       : Thu Aug 04 18:33:00 2016
+// Last Modified By : Aaron B. Moss
+// Last Modified On : Thu Aug 04 18:33:00 2016
+// Update Count     : 1
+//
+
+#ifndef _INSTANTIATEGENERIC_H
+#define _INSTANTIATEGENERIC_H
+
+#include "SynTree/SynTree.h"
+
+namespace GenPoly {
+	/// Replaces all generic types that have static layout with concrete instantiations.
+	/// Types with concrete values for otype parameters will be template-expanded, while
+	/// dtype and ftype parameters will be replaced by the appropriate void type.
+	void instantiateGeneric( std::list< Declaration* > &translationUnit );
+} // namespace GenPoly
+
+#endif // _INSTANTIATEGENERIC_H
+
+// Local Variables: //
+// tab-width: 4 //
+// mode: c++ //
+// compile-command: "make install" //
+// End: //
Index: src/GenPoly/Specialize.cc
===================================================================
--- src/GenPoly/Specialize.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/GenPoly/Specialize.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -31,4 +31,5 @@
 #include "Common/UniqueName.h"
 #include "Common/utility.h"
+#include "InitTweak/InitTweak.h"
 
 namespace GenPoly {
@@ -184,10 +185,13 @@
 		mutateAll( appExpr->get_args(), *this );
 
-		// create thunks for the inferred parameters
-		for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) {
-			inferParam->second.expr = doSpecialization( inferParam->second.formalType, inferParam->second.expr, &appExpr->get_inferParams() );
-		}
-
-		handleExplicitParams( appExpr );
+		if ( ! InitTweak::isIntrinsicCallExpr( appExpr ) ) {
+			// create thunks for the inferred parameters
+			// don't need to do this for intrinsic calls, because they aren't actually passed
+			for ( InferredParams::iterator inferParam = appExpr->get_inferParams().begin(); inferParam != appExpr->get_inferParams().end(); ++inferParam ) {
+				inferParam->second.expr = doSpecialization( inferParam->second.formalType, inferParam->second.expr, &appExpr->get_inferParams() );
+			}
+
+			handleExplicitParams( appExpr );
+		}
 
 		return appExpr;
Index: src/GenPoly/module.mk
===================================================================
--- src/GenPoly/module.mk	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/GenPoly/module.mk	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -23,3 +23,4 @@
        GenPoly/CopyParams.cc \
        GenPoly/FindFunction.cc \
-       GenPoly/DeclMutator.cc
+       GenPoly/DeclMutator.cc \
+       GenPoly/InstantiateGeneric.cc
Index: src/InitTweak/FixGlobalInit.cc
===================================================================
--- src/InitTweak/FixGlobalInit.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/InitTweak/FixGlobalInit.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -46,47 +46,4 @@
 		FunctionDecl * destroyFunction;
 	};
-
-	class ConstExprChecker : public Visitor {
-	public:
-		ConstExprChecker() : isConstExpr( true ) {}
-
-		virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }
-		virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; }
-		virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; }
-		virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }
-		virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }
-		virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }
-		virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }
-		virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }
-		virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }
-		// these might be okay?
-		// virtual void visit( SizeofExpr *sizeofExpr );
-		// virtual void visit( AlignofExpr *alignofExpr );
-		// virtual void visit( UntypedOffsetofExpr *offsetofExpr );
-		// virtual void visit( OffsetofExpr *offsetofExpr );
-		// virtual void visit( OffsetPackExpr *offsetPackExpr );
-		// virtual void visit( AttrExpr *attrExpr );
-		// virtual void visit( CommaExpr *commaExpr );
-		// virtual void visit( LogicalExpr *logicalExpr );
-		// virtual void visit( ConditionalExpr *conditionalExpr );
-		virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; }
-		virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; }
-		virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; }
-		virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; }
-		virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; }
-		virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; }
-
-		bool isConstExpr;
-	};
-
-	bool isConstExpr( Initializer * init ) {
-		if ( init ) {
-			ConstExprChecker checker;
-			init->accept( checker );
-			return checker.isConstExpr;
-		} // if
-		// for all intents and purposes, no initializer means const expr
-		return true;
-	}
 
 	void fixGlobalInit( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary ) {
@@ -140,6 +97,4 @@
 		std::list< Statement * > & destroyStatements = destroyFunction->get_statements()->get_kids();
 
-		if ( ! tryConstruct( objDecl ) ) return; // don't construct @= or designated objects
-		if ( objDecl->get_storageClass() == DeclarationNode::Extern ) return;
 		// C allows you to initialize objects with constant expressions
 		// xxx - this is an optimization. Need to first resolve constructors before we decide
@@ -147,22 +102,27 @@
 		// if ( isConstExpr( objDecl->get_init() ) ) return;
 
-		if ( dynamic_cast< ArrayType * > ( objDecl->get_type() ) ) {
-			// xxx - initialize each element of the array
-		} else {
-			// steal initializer from object and attach it to a new temporary
-			ObjectDecl *newObj = new ObjectDecl( tempNamer.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, objDecl->get_type()->clone(), objDecl->get_init() );
-			objDecl->set_init( NULL );
-			initStatements.push_back( new DeclStmt( noLabels, newObj ) );
+		if ( ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() ) ) {
+			// a decision should have been made by the resolver, so ctor and init are not both non-NULL
+			assert( ! ctorInit->get_ctor() || ! ctorInit->get_init() );
 
-			// copy construct objDecl using temporary
-			UntypedExpr * init = new UntypedExpr( new NameExpr( "?{}" ) );
-			init->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
-			init->get_args().push_back( new VariableExpr( newObj ) );
-			initStatements.push_back( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, init ) ) );
-
-			// add destructor calls to global destroy function
-			UntypedExpr * destroy = new UntypedExpr( new NameExpr( "^?{}" ) );
-			destroy->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
-			destroyStatements.push_front( new ImplicitCtorDtorStmt( new ExprStmt( noLabels, destroy ) ) );
+			Statement * dtor = ctorInit->get_dtor();
+			if ( dtor && ! isIntrinsicSingleArgCallStmt( dtor ) ) {
+				// don't need to call intrinsic dtor, because it does nothing, but
+				// non-intrinsic dtors must be called
+				destroyStatements.push_front( dtor );
+				ctorInit->set_dtor( NULL );
+			} // if
+			if ( Statement * ctor = ctorInit->get_ctor() ) {
+				initStatements.push_back( ctor );
+				objDecl->set_init( NULL );
+				ctorInit->set_ctor( NULL );
+			} else if ( Initializer * init = ctorInit->get_init() ) {
+				objDecl->set_init( init );
+				ctorInit->set_init( NULL );
+			} else {
+				// no constructor and no initializer, which is okay
+				objDecl->set_init( NULL );
+			} // if
+			delete ctorInit;
 		} // if
 	}
Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/InitTweak/FixInit.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -18,6 +18,7 @@
 #include <iterator>
 #include <algorithm>
+#include "InitTweak.h"
 #include "FixInit.h"
-#include "InitTweak.h"
+#include "FixGlobalInit.h"
 #include "ResolvExpr/Resolver.h"
 #include "ResolvExpr/typeops.h"
@@ -25,4 +26,5 @@
 #include "SynTree/Type.h"
 #include "SynTree/Expression.h"
+#include "SynTree/Attribute.h"
 #include "SynTree/Statement.h"
 #include "SynTree/Initializer.h"
@@ -83,4 +85,5 @@
 		};
 
+		// debug
 		struct printSet {
 			typedef ObjDeclCollector::ObjectSet ObjectSet;
@@ -159,4 +162,6 @@
 
 			virtual DeclarationWithType * mutate( ObjectDecl *objDecl );
+
+			std::list< Declaration * > staticDtorDecls;
 		};
 
@@ -171,5 +176,8 @@
 	} // namespace
 
-	void fix( std::list< Declaration * > & translationUnit ) {
+	void fix( std::list< Declaration * > & translationUnit, const std::string & filename, bool inLibrary ) {
+		// fixes ConstructorInit for global variables. should happen before fixInitializers.
+		InitTweak::fixGlobalInit( translationUnit, filename, inLibrary );
+
 		InsertImplicitCalls::insert( translationUnit );
 		ResolveCopyCtors::resolveImplicitCalls( translationUnit );
@@ -194,5 +202,19 @@
 		void FixInit::fixInitializers( std::list< Declaration * > & translationUnit ) {
 			FixInit fixer;
-			mutateAll( translationUnit, fixer );
+
+			// can't use mutateAll, because need to insert declarations at top-level
+			// can't use DeclMutator, because sometimes need to insert IfStmt, etc.
+			SemanticError errors;
+			for ( std::list< Declaration * >::iterator i = translationUnit.begin(); i != translationUnit.end(); ++i ) {
+				try {
+					*i = maybeMutate( *i, fixer );
+					translationUnit.splice( i, fixer.staticDtorDecls );
+				} catch( SemanticError &e ) {
+					errors.append( e );
+				} // try
+			} // for
+			if ( ! errors.isEmpty() ) {
+				throw errors;
+			} // if
 		}
 
@@ -422,16 +444,27 @@
 				if ( Statement * ctor = ctorInit->get_ctor() ) {
 					if ( objDecl->get_storageClass() == DeclarationNode::Static ) {
+						// originally wanted to take advantage of gcc nested functions, but
+						// we get memory errors with this approach. To remedy this, the static
+						// variable is hoisted when the destructor needs to be called.
+						//
 						// generate:
-						// static bool __objName_uninitialized = true;
-						// if (__objName_uninitialized) {
-						//   __ctor(__objName);
-						//   void dtor_atexit() {
-						//     __dtor(__objName);
+						// static T __objName_static_varN;
+						// void __objName_dtor_atexitN() {
+						//   __dtor__...;
+						// }
+						// int f(...) {
+						//   ...
+						//   static bool __objName_uninitialized = true;
+						//   if (__objName_uninitialized) {
+						//     __ctor(__objName);
+						//     __objName_uninitialized = false;
+						//     atexit(__objName_dtor_atexitN);
 						//   }
-						//   on_exit(dtorOnExit, &__objName);
-						//   __objName_uninitialized = false;
+						//   ...
 						// }
 
-						// generate first line
+						static UniqueName dtorCallerNamer( "_dtor_atexit" );
+
+						// static bool __objName_uninitialized = true
 						BasicType * boolType = new BasicType( Type::Qualifiers(), BasicType::Bool );
 						SingleInit * boolInitExpr = new SingleInit( new ConstantExpr( Constant( boolType->clone(), "1" ) ), noDesignators );
@@ -439,13 +472,4 @@
 						isUninitializedVar->fixUniqueId();
 
-						// void dtor_atexit(...) {...}
-						FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + "_dtor_atexit", DeclarationNode::NoStorageClass, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
-						dtorCaller->fixUniqueId();
-						dtorCaller->get_statements()->get_kids().push_back( ctorInit->get_dtor()->clone() );
-
-						// on_exit(dtor_atexit);
-						UntypedExpr * callAtexit = new UntypedExpr( new NameExpr( "atexit" ) );
-						callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) );
-
 						// __objName_uninitialized = false;
 						UntypedExpr * setTrue = new UntypedExpr( new NameExpr( "?=?" ) );
@@ -457,6 +481,4 @@
 						std::list< Statement * > & body = initStmts->get_kids();
 						body.push_back( ctor );
-						body.push_back( new DeclStmt( noLabels, dtorCaller ) );
-						body.push_back( new ExprStmt( noLabels, callAtexit ) );
 						body.push_back( new ExprStmt( noLabels, setTrue ) );
 
@@ -465,4 +487,43 @@
 						stmtsToAddAfter.push_back( new DeclStmt( noLabels, isUninitializedVar ) );
 						stmtsToAddAfter.push_back( ifStmt );
+
+						if ( ctorInit->get_dtor() ) {
+							// if the object has a non-trivial destructor, have to
+							// hoist it and the object into the global space and
+							// call the destructor function with atexit.
+
+							Statement * dtorStmt = ctorInit->get_dtor()->clone();
+
+							// void __objName_dtor_atexitN(...) {...}
+							FunctionDecl * dtorCaller = new FunctionDecl( objDecl->get_mangleName() + dtorCallerNamer.newName(), DeclarationNode::Static, LinkageSpec::C, new FunctionType( Type::Qualifiers(), false ), new CompoundStmt( noLabels ), false, false );
+							dtorCaller->fixUniqueId();
+							dtorCaller->get_statements()->get_kids().push_back( dtorStmt );
+
+							// atexit(dtor_atexit);
+							UntypedExpr * callAtexit = new UntypedExpr( new NameExpr( "atexit" ) );
+							callAtexit->get_args().push_back( new VariableExpr( dtorCaller ) );
+
+							body.push_back( new ExprStmt( noLabels, callAtexit ) );
+
+							// hoist variable and dtor caller decls to list of decls that will be added into global scope
+							staticDtorDecls.push_back( objDecl );
+							staticDtorDecls.push_back( dtorCaller );
+
+							// need to rename object uniquely since it now appears
+							// at global scope and there could be multiple function-scoped
+							// static variables with the same name in different functions.
+							static UniqueName staticNamer( "_static_var" );
+							objDecl->set_mangleName( objDecl->get_mangleName() + staticNamer.newName() );
+
+							objDecl->set_init( NULL );
+							ctorInit->set_ctor( NULL );
+							delete ctorInit;
+
+							// xxx - temporary hack: need to return a declaration, but want to hoist the current object out of this scope
+							// create a new object which is never used
+							static UniqueName dummyNamer( "_dummy" );
+							ObjectDecl * dummy = new ObjectDecl( dummyNamer.newName(), DeclarationNode::Static, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new VoidType( Type::Qualifiers() ) ), 0, std::list< Attribute * >{ new Attribute("unused") } );
+							return dummy;
+						}
 					} else {
 						stmtsToAddAfter.push_back( ctor );
@@ -524,5 +585,5 @@
 					assert( ! ctorInit->get_ctor() || ! ctorInit->get_init() );
 					Statement * dtor = ctorInit->get_dtor();
-					if ( dtor && ! isInstrinsicSingleArgCallStmt( dtor ) ) {
+					if ( dtor && ! isIntrinsicSingleArgCallStmt( dtor ) ) {
 						// don't need to call intrinsic dtor, because it does nothing, but
 						// non-intrinsic dtors must be called
Index: src/InitTweak/FixInit.h
===================================================================
--- src/InitTweak/FixInit.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/InitTweak/FixInit.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -27,5 +27,5 @@
   /// replace constructor initializers with expression statements
   /// and unwrap basic C-style initializers
-	void fix( std::list< Declaration * > & translationUnit );
+	void fix( std::list< Declaration * > & translationUnit, const std::string & name, bool inLibrary );
 } // namespace
 
Index: src/InitTweak/GenInit.cc
===================================================================
--- src/InitTweak/GenInit.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/InitTweak/GenInit.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -26,4 +26,5 @@
 #include "SymTab/Autogen.h"
 #include "GenPoly/PolyMutator.h"
+#include "GenPoly/DeclMutator.h"
 
 namespace InitTweak {
@@ -55,28 +56,57 @@
 	  public:
 		/// create constructor and destructor statements for object declarations.
-		/// Destructors are inserted directly into the code, whereas constructors
-		/// will be added in after the resolver has run so that the initializer expression
-		/// is only removed if a constructor is found
+		/// the actual call statements will be added in after the resolver has run
+		/// so that the initializer expression is only removed if a constructor is found
+		/// and the same destructor call is inserted in all of the appropriate locations.
 		static void generateCtorDtor( std::list< Declaration * > &translationUnit );
-
-		CtorDtor() : inFunction( false ) {}
 
 		virtual DeclarationWithType * mutate( ObjectDecl * );
 		virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
-		virtual Declaration* mutate( StructDecl *aggregateDecl );
-		virtual Declaration* mutate( UnionDecl *aggregateDecl );
-		virtual Declaration* mutate( EnumDecl *aggregateDecl );
-		virtual Declaration* mutate( TraitDecl *aggregateDecl );
-		virtual TypeDecl* mutate( TypeDecl *typeDecl );
-		virtual Declaration* mutate( TypedefDecl *typeDecl );
-
-		virtual Type * mutate( FunctionType *funcType );
+		// should not traverse into any of these declarations to find objects
+		// that need to be constructed or destructed
+		virtual Declaration* mutate( StructDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual Declaration* mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual Declaration* mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual Declaration* mutate( TraitDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual TypeDecl* mutate( TypeDecl *typeDecl ) { return typeDecl; }
+		virtual Declaration* mutate( TypedefDecl *typeDecl ) { return typeDecl; }
+
+		virtual Type * mutate( FunctionType *funcType ) { return funcType; }
 
 	  protected:
-		bool inFunction;
+	};
+
+	class HoistArrayDimension : public GenPoly::DeclMutator {
+	  public:
+		typedef GenPoly::DeclMutator Parent;
+
+		/// hoist dimension from array types in object declaration so that it uses a single
+		/// const variable of type size_t, so that side effecting array dimensions are only
+		/// computed once.
+		static void hoistArrayDimension( std::list< Declaration * > & translationUnit );
+
+	  private:
+		virtual DeclarationWithType * mutate( ObjectDecl * objectDecl );
+		virtual DeclarationWithType * mutate( FunctionDecl *functionDecl );
+		// should not traverse into any of these declarations to find objects
+		// that need to be constructed or destructed
+		virtual Declaration* mutate( StructDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual Declaration* mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual Declaration* mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual Declaration* mutate( TraitDecl *aggregateDecl ) { return aggregateDecl; }
+		virtual TypeDecl* mutate( TypeDecl *typeDecl ) { return typeDecl; }
+		virtual Declaration* mutate( TypedefDecl *typeDecl ) { return typeDecl; }
+
+		virtual Type* mutate( FunctionType *funcType ) { return funcType; }
+
+		void hoist( Type * type );
+
+		DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;
+		bool inFunction = false;
 	};
 
 	void genInit( std::list< Declaration * > & translationUnit ) {
 		ReturnFixer::makeReturnTemp( translationUnit );
+		HoistArrayDimension::hoistArrayDimension( translationUnit );
 		CtorDtor::generateCtorDtor( translationUnit );
 	}
@@ -124,4 +154,53 @@
 	}
 
+	// precompute array dimension expression, because constructor generation may duplicate it,
+	// which would be incorrect if it is a side-effecting computation.
+	void HoistArrayDimension::hoistArrayDimension( std::list< Declaration * > & translationUnit ) {
+		HoistArrayDimension hoister;
+		hoister.mutateDeclarationList( translationUnit );
+	}
+
+	DeclarationWithType * HoistArrayDimension::mutate( ObjectDecl * objectDecl ) {
+		storageclass = objectDecl->get_storageClass();
+		DeclarationWithType * temp = Parent::mutate( objectDecl );
+		hoist( objectDecl->get_type() );
+		storageclass = DeclarationNode::NoStorageClass;
+		return temp;
+	}
+
+	void HoistArrayDimension::hoist( Type * type ) {
+		// if in function, generate const size_t var
+		static UniqueName dimensionName( "_array_dim" );
+
+		// C doesn't allow variable sized arrays at global scope or for static variables,
+		// so don't hoist dimension.
+		if ( ! inFunction ) return;
+		if ( storageclass == DeclarationNode::Static ) return;
+
+		if ( ArrayType * arrayType = dynamic_cast< ArrayType * >( type ) ) {
+			if ( ! arrayType->get_dimension() ) return; // xxx - recursive call to hoist?
+
+			// don't need to hoist dimension if it's a constexpr - only need to if there's potential
+			// for side effects.
+			if ( isConstExpr( arrayType->get_dimension() ) ) return;
+
+			ObjectDecl * arrayDimension = new ObjectDecl( dimensionName.newName(), storageclass, LinkageSpec::C, 0, SymTab::SizeType->clone(), new SingleInit( arrayType->get_dimension() ) );
+			arrayDimension->get_type()->set_isConst( true );
+
+			arrayType->set_dimension( new VariableExpr( arrayDimension ) );
+			addDeclaration( arrayDimension );
+
+			hoist( arrayType->get_base() );
+			return;
+		}
+	}
+
+	DeclarationWithType * HoistArrayDimension::mutate( FunctionDecl *functionDecl ) {
+		bool oldInFunc = inFunction;
+		inFunction = true;
+		DeclarationWithType * decl = Parent::mutate( functionDecl );
+		inFunction = oldInFunc;
+		return decl;
+	}
 
 	void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) {
@@ -130,60 +209,34 @@
 	}
 
-	namespace {
-		Expression * makeCtorDtorExpr( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) {
-			UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) );
-			expr->get_args().push_back( new AddressExpr( new VariableExpr( objDecl ) ) );
-			expr->get_args().splice( expr->get_args().end(), args );
-			return expr;
-		}
-	}
-
 	DeclarationWithType * CtorDtor::mutate( ObjectDecl * objDecl ) {
-		// hands off if designated or if @=
+		// hands off if designated, if @=, or if extern
 		if ( tryConstruct( objDecl ) ) {
-			if ( inFunction ) {
-				if ( ArrayType * at = dynamic_cast< ArrayType * >( objDecl->get_type() ) ) {
-					// call into makeArrayFunction from validate.cc to generate calls to ctor/dtor for each element of array
-					// TODO: walk initializer and generate appropriate copy ctor if element has initializer
-					std::list< Expression * > args = makeInitList( objDecl->get_init() );
-					if ( args.empty() ) {
-						std::list< Statement * > ctor;
-						std::list< Statement * > dtor;
-
-						SymTab::makeArrayFunction( NULL, new VariableExpr( objDecl ), at, "?{}", back_inserter( ctor ) );
-						SymTab::makeArrayFunction( NULL, new VariableExpr( objDecl ), at, "^?{}", front_inserter( dtor ), false );
-
-						// Currently makeArrayFunction produces a single Statement - a CompoundStmt
-						// which  wraps everything that needs to happen. As such, it's technically
-						// possible to use a Statement ** in the above calls, but this is inherently
-						// unsafe, so instead we take the slightly less efficient route, but will be
-						// immediately informed if somehow the above assumption is broken. In this case,
-						// we could always wrap the list of statements at this point with a CompoundStmt,
-						// but it seems reasonable at the moment for this to be done by makeArrayFunction
-						// itself
-						assert( ctor.size() == 1 && dynamic_cast< ImplicitCtorDtorStmt * >( ctor.front() ) );
-						assert( dtor.size() == 1 && dynamic_cast< ImplicitCtorDtorStmt * >( dtor.front() ) );
-						objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ) );
-					} else {
-						// array came with an initializer list: initialize each element
-						// may have more initializers than elements in the array - need to check at each index that
-						// we haven't exceeded size. This requires precomputing the size because it might be a side-effecting
-						// computation.
-						// may have fewer initializers than eleemnts in the array - need to default construct
-						// remaining elements.
-						// might be able to merge this with the case above.
-					}
-				} else {
-					// it's sufficient to attempt to call the ctor/dtor for the given object and its initializer
-					Expression * ctor = makeCtorDtorExpr( "?{}", objDecl, makeInitList( objDecl->get_init() ) );
-					Expression * dtor = makeCtorDtorExpr( "^?{}", objDecl, std::list< Expression * >() );
-
-					// need to remember init expression, in case no ctors exist
-					// if ctor does exist, want to use ctor expression instead of init
-					// push this decision to the resolver
-					ExprStmt * ctorStmt = new ExprStmt( noLabels, ctor );
-					ExprStmt * dtorStmt = new ExprStmt( noLabels, dtor );
-					objDecl->set_init( new ConstructorInit( new ImplicitCtorDtorStmt( ctorStmt ), new ImplicitCtorDtorStmt( dtorStmt ), objDecl->get_init() ) );
-				}
+			// call into genImplicitCall from Autogen.h to generate calls to ctor/dtor
+			// for each constructable object
+			std::list< Statement * > ctor;
+			std::list< Statement * > dtor;
+
+			InitExpander srcParam( objDecl->get_init() );
+			InitExpander nullParam( (Initializer *)NULL );
+			SymTab::genImplicitCall( srcParam, new VariableExpr( objDecl ), "?{}", back_inserter( ctor ), objDecl );
+			SymTab::genImplicitCall( nullParam, new VariableExpr( objDecl ), "^?{}", front_inserter( dtor ), objDecl, false );
+
+			// Currently genImplicitCall produces a single Statement - a CompoundStmt
+			// which  wraps everything that needs to happen. As such, it's technically
+			// possible to use a Statement ** in the above calls, but this is inherently
+			// unsafe, so instead we take the slightly less efficient route, but will be
+			// immediately informed if somehow the above assumption is broken. In this case,
+			// we could always wrap the list of statements at this point with a CompoundStmt,
+			// but it seems reasonable at the moment for this to be done by genImplicitCall
+			// itself. It is possible that genImplicitCall produces no statements (e.g. if
+			// an array type does not have a dimension). In this case, it's fine to ignore
+			// the object for the purposes of construction.
+			assert( ctor.size() == dtor.size() && ctor.size() <= 1 );
+			if ( ctor.size() == 1 ) {
+				// need to remember init expression, in case no ctors exist
+				// if ctor does exist, want to use ctor expression instead of init
+				// push this decision to the resolver
+				assert( dynamic_cast< ImplicitCtorDtorStmt * > ( ctor.front() ) && dynamic_cast< ImplicitCtorDtorStmt * > ( dtor.front() ) );
+				objDecl->set_init( new ConstructorInit( ctor.front(), dtor.front(), objDecl->get_init() ) );
 			}
 		}
@@ -193,22 +246,8 @@
 	DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) {
 		// parameters should not be constructed and destructed, so don't mutate FunctionType
-		bool oldInFunc = inFunction;
 		mutateAll( functionDecl->get_oldDecls(), *this );
-		inFunction = true;
 		functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
-		inFunction = oldInFunc;
 		return functionDecl;
 	}
-
-	// should not traverse into any of these declarations to find objects
-	// that need to be constructed or destructed
-	Declaration* CtorDtor::mutate( StructDecl *aggregateDecl ) { return aggregateDecl; }
-	Declaration* CtorDtor::mutate( UnionDecl *aggregateDecl ) { return aggregateDecl; }
-	Declaration* CtorDtor::mutate( EnumDecl *aggregateDecl ) { return aggregateDecl; }
-	Declaration* CtorDtor::mutate( TraitDecl *aggregateDecl ) { return aggregateDecl; }
-	TypeDecl* CtorDtor::mutate( TypeDecl *typeDecl ) { return typeDecl; }
-	Declaration* CtorDtor::mutate( TypedefDecl *typeDecl ) { return typeDecl; }
-	Type* CtorDtor::mutate( FunctionType *funcType ) { return funcType; }
-
 } // namespace InitTweak
 
Index: src/InitTweak/InitTweak.cc
===================================================================
--- src/InitTweak/InitTweak.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/InitTweak/InitTweak.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -1,2 +1,3 @@
+#include <algorithm>
 #include "InitTweak.h"
 #include "SynTree/Visitor.h"
@@ -4,4 +5,5 @@
 #include "SynTree/Initializer.h"
 #include "SynTree/Expression.h"
+#include "SynTree/Attribute.h"
 #include "GenPoly/GenPoly.h"
 
@@ -20,7 +22,6 @@
 		};
 
-		class InitExpander : public Visitor {
+		class InitFlattener : public Visitor {
 			public:
-			InitExpander() {}
 			virtual void visit( SingleInit * singleInit );
 			virtual void visit( ListInit * listInit );
@@ -28,12 +29,12 @@
 		};
 
-		void InitExpander::visit( SingleInit * singleInit ) {
+		void InitFlattener::visit( SingleInit * singleInit ) {
 			argList.push_back( singleInit->get_value()->clone() );
 		}
 
-		void InitExpander::visit( ListInit * listInit ) {
-			// xxx - for now, assume no nested list inits
-			std::list<Initializer*>::iterator it = listInit->begin_initializers();
-			for ( ; it != listInit->end_initializers(); ++it ) {
+		void InitFlattener::visit( ListInit * listInit ) {
+			// flatten nested list inits
+			std::list<Initializer*>::iterator it = listInit->begin();
+			for ( ; it != listInit->end(); ++it ) {
 				(*it)->accept( *this );
 			}
@@ -42,7 +43,7 @@
 
 	std::list< Expression * > makeInitList( Initializer * init ) {
-		InitExpander expander;
-		maybeAccept( init, expander );
-		return expander.argList;
+		InitFlattener flattener;
+		maybeAccept( init, flattener );
+		return flattener.argList;
 	}
 
@@ -53,48 +54,254 @@
 	}
 
+	class InitExpander::ExpanderImpl {
+	public:
+		virtual std::list< Expression * > next( std::list< Expression * > & indices ) = 0;
+		virtual Statement * buildListInit( UntypedExpr * callExpr, std::list< Expression * > & indices ) = 0;
+	};
+
+	class InitImpl : public InitExpander::ExpanderImpl {
+	public:
+		InitImpl( Initializer * init ) : init( init ) {}
+
+		virtual std::list< Expression * > next( std::list< Expression * > & indices ) {
+			// this is wrong, but just a placeholder for now
+			// if ( ! flattened ) flatten( indices );
+			// return ! inits.empty() ? makeInitList( inits.front() ) : std::list< Expression * >();
+			return makeInitList( init );
+		}
+
+		virtual Statement * buildListInit( UntypedExpr * callExpr, std::list< Expression * > & indices );
+	private:
+		Initializer * init;
+	};
+
+	class ExprImpl : public InitExpander::ExpanderImpl {
+	public:
+		ExprImpl( Expression * expr ) : arg( expr ) {}
+
+		virtual std::list< Expression * > next( std::list< Expression * > & indices ) {
+			std::list< Expression * > ret;
+			Expression * expr = maybeClone( arg );
+			if ( expr ) {
+				for ( std::list< Expression * >::reverse_iterator it = indices.rbegin(); it != indices.rend(); ++it ) {
+					// go through indices and layer on subscript exprs ?[?]
+					++it;
+					UntypedExpr * subscriptExpr = new UntypedExpr( new NameExpr( "?[?]") );
+					subscriptExpr->get_args().push_back( expr );
+					subscriptExpr->get_args().push_back( (*it)->clone() );
+					expr = subscriptExpr;
+				}
+				ret.push_back( expr );
+			}
+			return ret;
+		}
+
+		virtual Statement * buildListInit( UntypedExpr * callExpr, std::list< Expression * > & indices );
+	private:
+		Expression * arg;
+	};
+
+	InitExpander::InitExpander( Initializer * init ) : expander( new InitImpl( init ) ) {}
+
+	InitExpander::InitExpander( Expression * expr ) : expander( new ExprImpl( expr ) ) {}
+
+	std::list< Expression * > InitExpander::operator*() {
+		return cur;
+	}
+
+	InitExpander & InitExpander::operator++() {
+		cur = expander->next( indices );
+		return *this;
+	}
+
+	// use array indices list to build switch statement
+	void InitExpander::addArrayIndex( Expression * index, Expression * dimension ) {
+		indices.push_back( index );
+		indices.push_back( dimension );
+	}
+
+	void InitExpander::clearArrayIndices() {
+		indices.clear();
+	}
+
+	namespace {
+		/// given index i, dimension d, initializer init, and callExpr f, generates
+		///   if (i < d) f(..., init)
+		///   ++i;
+		/// so that only elements within the range of the array are constructed
+		template< typename OutIterator >
+		void buildCallExpr( UntypedExpr * callExpr, Expression * index, Expression * dimension, Initializer * init, OutIterator out ) {
+			UntypedExpr * cond = new UntypedExpr( new NameExpr( "?<?") );
+			cond->get_args().push_back( index->clone() );
+			cond->get_args().push_back( dimension->clone() );
+
+			std::list< Expression * > args = makeInitList( init );
+			callExpr->get_args().splice( callExpr->get_args().end(), args );
+
+			*out++ = new IfStmt( noLabels, cond, new ExprStmt( noLabels, callExpr ), NULL );
+
+			UntypedExpr * increment = new UntypedExpr( new NameExpr( "++?" ) );
+			increment->get_args().push_back( new AddressExpr( index->clone() ) );
+			*out++ = new ExprStmt( noLabels, increment );
+		}
+
+		template< typename OutIterator >
+		void build( UntypedExpr * callExpr, InitExpander::IndexList::iterator idx, InitExpander::IndexList::iterator idxEnd, Initializer * init, OutIterator out ) {
+			if ( idx == idxEnd ) return;
+			Expression * index = *idx++;
+			assert( idx != idxEnd );
+			Expression * dimension = *idx++;
+
+			// xxx - may want to eventually issue a warning here if we can detect
+			// that the number of elements exceeds to dimension of the array
+			if ( idx == idxEnd ) {
+				if ( ListInit * listInit = dynamic_cast< ListInit * >( init ) ) {
+					for ( Initializer * init : *listInit ) {
+						buildCallExpr( callExpr->clone(), index, dimension, init, out );
+					}
+				} else {
+					buildCallExpr( callExpr->clone(), index, dimension, init, out );
+				}
+			} else {
+				std::list< Statement * > branches;
+
+				unsigned long cond = 0;
+				ListInit * listInit = dynamic_cast< ListInit * >( init );
+				if ( ! listInit ) {
+					// xxx - this shouldn't be an error, but need a way to
+					// terminate without creating output, so should catch this error
+					throw SemanticError( "unbalanced list initializers" );
+				}
+
+				static UniqueName targetLabel( "L__autogen__" );
+				Label switchLabel( targetLabel.newName(), 0, std::list< Attribute * >{ new Attribute("unused") } );
+				for ( Initializer * init : *listInit ) {
+					Expression * condition;
+					// check for designations
+					// if ( init-> ) {
+						condition = new ConstantExpr( Constant::from_ulong( cond ) );
+						++cond;
+					// } else {
+					// 	condition = // ... take designation
+					// 	cond = // ... take designation+1
+					// }
+					std::list< Statement * > stmts;
+					build( callExpr, idx, idxEnd, init, back_inserter( stmts ) );
+					stmts.push_back( new BranchStmt( noLabels, switchLabel, BranchStmt::Break ) );
+					CaseStmt * caseStmt = new CaseStmt( noLabels, condition, stmts );
+					branches.push_back( caseStmt );
+				}
+				*out++ = new SwitchStmt( noLabels, index->clone(), branches );
+				*out++ = new NullStmt( std::list<Label>{ switchLabel } );
+			}
+		}
+	}
+
+	// if array came with an initializer list: initialize each element
+	// may have more initializers than elements in the array - need to check at each index that
+	// we haven't exceeded size.
+	// may have fewer initializers than elements in the array - need to default construct
+	// remaining elements.
+	// To accomplish this, generate switch statement, consuming all of expander's elements
+	Statement * InitImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) {
+		if ( ! init ) return NULL;
+		CompoundStmt * block = new CompoundStmt( noLabels );
+		build( dst, indices.begin(), indices.end(), init, back_inserter( block->get_kids() ) );
+		if ( block->get_kids().empty() ) {
+			delete block;
+			return NULL;
+		} else {
+			init = NULL; // init was consumed in creating the list init
+			return block;
+		}
+	}
+
+	Statement * ExprImpl::buildListInit( UntypedExpr * dst, std::list< Expression * > & indices ) {
+		return NULL;
+	}
+
+	Statement * InitExpander::buildListInit( UntypedExpr * dst ) {
+		return expander->buildListInit( dst, indices );
+	}
+
 	bool tryConstruct( ObjectDecl * objDecl ) {
 		return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&
 			(objDecl->get_init() == NULL ||
 				( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() )) &&
-			! isDesignated( objDecl->get_init() );
+			! isDesignated( objDecl->get_init() )
+			&& objDecl->get_storageClass() != DeclarationNode::Extern;
+	}
+
+	class CallFinder : public Visitor {
+	public:
+		typedef Visitor Parent;
+		CallFinder( const std::list< std::string > & names ) : names( names ) {}
+
+		virtual void visit( ApplicationExpr * appExpr ) {
+			handleCallExpr( appExpr );
+		}
+
+		virtual void visit( UntypedExpr * untypedExpr ) {
+			handleCallExpr( untypedExpr );
+		}
+
+		std::list< Expression * > * matches;
+	private:
+		const std::list< std::string > names;
+
+		template< typename CallExpr >
+		void handleCallExpr( CallExpr * expr ) {
+			Parent::visit( expr );
+			std::string fname = getFunctionName( expr );
+			if ( std::find( names.begin(), names.end(), fname ) != names.end() ) {
+				matches->push_back( expr );
+			}
+		}
+	};
+
+	void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches ) {
+		static CallFinder finder( std::list< std::string >{ "?{}", "^?{}" } );
+		finder.matches = &matches;
+		maybeAccept( stmt, finder );
 	}
 
 	Expression * getCtorDtorCall( Statement * stmt ) {
-		if ( stmt == NULL ) return NULL;
-		if ( ExprStmt * exprStmt = dynamic_cast< ExprStmt * >( stmt ) ) {
-			return exprStmt->get_expr();
-		} else if ( CompoundStmt * compoundStmt = dynamic_cast< CompoundStmt * >( stmt ) ) {
-			// could also be a compound statement with a loop, in the case of an array
-			if( compoundStmt->get_kids().size() == 2 ) {
-				// loop variable and loop
-				ForStmt * forStmt = dynamic_cast< ForStmt * >( compoundStmt->get_kids().back() );
-				assert( forStmt && forStmt->get_body() );
-				return getCtorDtorCall( forStmt->get_body() );
-			} else if ( compoundStmt->get_kids().size() == 1 ) {
-				// should be the call statement, but in any case there's only one option
-				return getCtorDtorCall( compoundStmt->get_kids().front() );
-			} else {
-				assert( false && "too many statements in compoundStmt for getCtorDtorCall" );
-			}
-		} if ( ImplicitCtorDtorStmt * impCtorDtorStmt = dynamic_cast< ImplicitCtorDtorStmt * > ( stmt ) ) {
-			return getCtorDtorCall( impCtorDtorStmt->get_callStmt() );
-		} else {
-			// should never get here
-			assert( false && "encountered unknown call statement" );
-		}
-	}
-
-	bool isInstrinsicSingleArgCallStmt( Statement * stmt ) {
-		Expression * callExpr = getCtorDtorCall( stmt );
-		if ( ! callExpr ) return false;
-		ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( callExpr );
-		assert( appExpr );
-		VariableExpr * function = dynamic_cast< VariableExpr * >( appExpr->get_function() );
+		std::list< Expression * > matches;
+		collectCtorDtorCalls( stmt, matches );
+		assert( matches.size() <= 1 );
+		return matches.size() == 1 ? matches.front() : NULL;
+	}
+
+	namespace {
+		VariableExpr * getCalledFunction( ApplicationExpr * appExpr ) {
+			assert( appExpr );
+			// xxx - it's possible this can be other things, e.g. MemberExpr, so this is insufficient
+			return dynamic_cast< VariableExpr * >( appExpr->get_function() );
+		}
+	}
+
+	ApplicationExpr * isIntrinsicCallExpr( Expression * expr ) {
+		ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * >( expr );
+		if ( ! appExpr ) return NULL;
+		VariableExpr * function = getCalledFunction( appExpr );
 		assert( function );
 		// check for Intrinsic only - don't want to remove all overridable ctor/dtors because autogenerated ctor/dtor
 		// will call all member dtors, and some members may have a user defined dtor.
-		FunctionType * funcType = GenPoly::getFunctionType( function->get_var()->get_type() );
-		assert( funcType );
-		return function->get_var()->get_linkage() == LinkageSpec::Intrinsic && funcType->get_parameters().size() == 1;
+		return function->get_var()->get_linkage() == LinkageSpec::Intrinsic ? appExpr : NULL;
+	}
+
+	bool isIntrinsicSingleArgCallStmt( Statement * stmt ) {
+		std::list< Expression * > callExprs;
+		collectCtorDtorCalls( stmt, callExprs );
+		// if ( callExprs.empty() ) return false; // xxx - do I still need this check?
+		return std::all_of( callExprs.begin(), callExprs.end(), []( Expression * callExpr ){
+			if ( ApplicationExpr * appExpr = isIntrinsicCallExpr( callExpr ) ) {
+				assert( ! appExpr->get_function()->get_results().empty() );
+				FunctionType *funcType = GenPoly::getFunctionType( appExpr->get_function()->get_results().front() );
+				assert( funcType );
+				return funcType->get_parameters().size() == 1;
+			}
+			return false;
+		});
 	}
 
@@ -160,3 +367,56 @@
 		else return NULL;
 	}
+
+	class ConstExprChecker : public Visitor {
+	public:
+		ConstExprChecker() : isConstExpr( true ) {}
+
+		virtual void visit( ApplicationExpr *applicationExpr ) { isConstExpr = false; }
+		virtual void visit( UntypedExpr *untypedExpr ) { isConstExpr = false; }
+		virtual void visit( NameExpr *nameExpr ) { isConstExpr = false; }
+		virtual void visit( CastExpr *castExpr ) { isConstExpr = false; }
+		virtual void visit( LabelAddressExpr *labAddressExpr ) { isConstExpr = false; }
+		virtual void visit( UntypedMemberExpr *memberExpr ) { isConstExpr = false; }
+		virtual void visit( MemberExpr *memberExpr ) { isConstExpr = false; }
+		virtual void visit( VariableExpr *variableExpr ) { isConstExpr = false; }
+		virtual void visit( ConstantExpr *constantExpr ) { /* bottom out */ }
+		// these might be okay?
+		// virtual void visit( SizeofExpr *sizeofExpr );
+		// virtual void visit( AlignofExpr *alignofExpr );
+		// virtual void visit( UntypedOffsetofExpr *offsetofExpr );
+		// virtual void visit( OffsetofExpr *offsetofExpr );
+		// virtual void visit( OffsetPackExpr *offsetPackExpr );
+		// virtual void visit( AttrExpr *attrExpr );
+		// virtual void visit( CommaExpr *commaExpr );
+		// virtual void visit( LogicalExpr *logicalExpr );
+		// virtual void visit( ConditionalExpr *conditionalExpr );
+		virtual void visit( TupleExpr *tupleExpr ) { isConstExpr = false; }
+		virtual void visit( SolvedTupleExpr *tupleExpr ) { isConstExpr = false; }
+		virtual void visit( TypeExpr *typeExpr ) { isConstExpr = false; }
+		virtual void visit( AsmExpr *asmExpr ) { isConstExpr = false; }
+		virtual void visit( UntypedValofExpr *valofExpr ) { isConstExpr = false; }
+		virtual void visit( CompoundLiteralExpr *compLitExpr ) { isConstExpr = false; }
+
+		bool isConstExpr;
+	};
+
+	bool isConstExpr( Expression * expr ) {
+		if ( expr ) {
+			ConstExprChecker checker;
+			expr->accept( checker );
+			return checker.isConstExpr;
+		}
+		return true;
+	}
+
+	bool isConstExpr( Initializer * init ) {
+		if ( init ) {
+			ConstExprChecker checker;
+			init->accept( checker );
+			return checker.isConstExpr;
+		} // if
+		// for all intents and purposes, no initializer means const expr
+		return true;
+	}
+
 }
Index: src/InitTweak/InitTweak.h
===================================================================
--- src/InitTweak/InitTweak.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/InitTweak/InitTweak.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -26,32 +26,70 @@
 // helper functions for initialization
 namespace InitTweak {
-  /// transform Initializer into an argument list that can be passed to a call expression
-  std::list< Expression * > makeInitList( Initializer * init );
+	/// transform Initializer into an argument list that can be passed to a call expression
+	std::list< Expression * > makeInitList( Initializer * init );
 
-  /// True if the resolver should try to construct objDecl
-  bool tryConstruct( ObjectDecl * objDecl );
+	/// True if the resolver should try to construct objDecl
+	bool tryConstruct( ObjectDecl * objDecl );
 
-  /// True if the Initializer contains designations
-  bool isDesignated( Initializer * init );
+	/// True if the Initializer contains designations
+	bool isDesignated( Initializer * init );
 
-  /// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
-  /// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
-  /// Currently has assertions that make it less than fully general.
-  bool isInstrinsicSingleArgCallStmt( Statement * expr );
+  /// Non-Null if expr is a call expression whose target function is intrinsic
+  ApplicationExpr * isIntrinsicCallExpr( Expression * expr );
 
-  /// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
-  Expression * getCtorDtorCall( Statement * stmt );
+	/// True if stmt is a call statement where the function called is intrinsic and takes one parameter.
+	/// Intended to be used for default ctor/dtor calls, but might have use elsewhere.
+	/// Currently has assertions that make it less than fully general.
+	bool isIntrinsicSingleArgCallStmt( Statement * expr );
 
-  /// returns the name of the function being called
-  std::string getFunctionName( Expression * expr );
+	/// get all Ctor/Dtor call expressions from a Statement
+	void collectCtorDtorCalls( Statement * stmt, std::list< Expression * > & matches );
 
-  /// returns the argument to a call expression in position N indexed from 0
-  Expression *& getCallArg( Expression * callExpr, unsigned int pos );
+	/// get the Ctor/Dtor call expression from a Statement that looks like a generated ctor/dtor call
+	Expression * getCtorDtorCall( Statement * stmt );
 
-  /// returns the base type of a PointerType or ArrayType, else returns NULL
-  Type * getPointerBase( Type * );
+	/// returns the name of the function being called
+	std::string getFunctionName( Expression * expr );
 
-  /// returns the argument if it is a PointerType or ArrayType, else returns NULL
-  Type * isPointerType( Type * );
+	/// returns the argument to a call expression in position N indexed from 0
+	Expression *& getCallArg( Expression * callExpr, unsigned int pos );
+
+	/// returns the base type of a PointerType or ArrayType, else returns NULL
+	Type * getPointerBase( Type * );
+
+	/// returns the argument if it is a PointerType or ArrayType, else returns NULL
+	Type * isPointerType( Type * );
+
+	/// returns true if expr is trivially a compile-time constant
+	bool isConstExpr( Expression * expr );
+	bool isConstExpr( Initializer * init );
+
+	class InitExpander {
+	public:
+		// expand by stepping through init to get each list of arguments
+		InitExpander( Initializer * init );
+
+		// always expand to expr
+		InitExpander( Expression * expr );
+
+		// iterator-like interface
+		std::list< Expression * > operator*();
+		InitExpander & operator++();
+
+		// builds statement which has the same semantics as a C-style list initializer
+		// (for array initializers) using callExpr as the base expression to perform initialization
+		Statement * buildListInit( UntypedExpr * callExpr );
+		void addArrayIndex( Expression * index, Expression * dimension );
+		void clearArrayIndices();
+
+		class ExpanderImpl;
+	private:
+		std::shared_ptr< ExpanderImpl > expander;
+		std::list< Expression * > cur;
+
+		// invariant: list of size 2N (elements come in pairs [index, dimension])
+		typedef std::list< Expression * > IndexList;
+		IndexList indices;
+	};
 } // namespace
 
Index: src/Makefile.in
===================================================================
--- src/Makefile.in	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/Makefile.in	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -121,4 +121,5 @@
 	GenPoly/driver_cfa_cpp-FindFunction.$(OBJEXT) \
 	GenPoly/driver_cfa_cpp-DeclMutator.$(OBJEXT) \
+	GenPoly/driver_cfa_cpp-InstantiateGeneric.$(OBJEXT) \
 	InitTweak/driver_cfa_cpp-GenInit.$(OBJEXT) \
 	InitTweak/driver_cfa_cpp-FixInit.$(OBJEXT) \
@@ -377,12 +378,12 @@
 	GenPoly/ScrubTyVars.cc GenPoly/Lvalue.cc GenPoly/Specialize.cc \
 	GenPoly/CopyParams.cc GenPoly/FindFunction.cc \
-	GenPoly/DeclMutator.cc InitTweak/GenInit.cc \
-	InitTweak/FixInit.cc InitTweak/FixGlobalInit.cc \
-	InitTweak/InitTweak.cc Parser/parser.yy Parser/lex.ll \
-	Parser/TypedefTable.cc Parser/ParseNode.cc \
-	Parser/DeclarationNode.cc Parser/ExpressionNode.cc \
-	Parser/StatementNode.cc Parser/InitializerNode.cc \
-	Parser/TypeData.cc Parser/LinkageSpec.cc \
-	Parser/parseutility.cc Parser/Parser.cc \
+	GenPoly/DeclMutator.cc GenPoly/InstantiateGeneric.cc \
+	InitTweak/GenInit.cc InitTweak/FixInit.cc \
+	InitTweak/FixGlobalInit.cc InitTweak/InitTweak.cc \
+	Parser/parser.yy Parser/lex.ll Parser/TypedefTable.cc \
+	Parser/ParseNode.cc Parser/DeclarationNode.cc \
+	Parser/ExpressionNode.cc Parser/StatementNode.cc \
+	Parser/InitializerNode.cc Parser/TypeData.cc \
+	Parser/LinkageSpec.cc Parser/parseutility.cc Parser/Parser.cc \
 	ResolvExpr/AlternativeFinder.cc ResolvExpr/Alternative.cc \
 	ResolvExpr/Unify.cc ResolvExpr/PtrsAssignable.cc \
@@ -585,4 +586,6 @@
 GenPoly/driver_cfa_cpp-DeclMutator.$(OBJEXT): GenPoly/$(am__dirstamp) \
 	GenPoly/$(DEPDIR)/$(am__dirstamp)
+GenPoly/driver_cfa_cpp-InstantiateGeneric.$(OBJEXT):  \
+	GenPoly/$(am__dirstamp) GenPoly/$(DEPDIR)/$(am__dirstamp)
 InitTweak/$(am__dirstamp):
 	@$(MKDIR_P) InitTweak
@@ -828,4 +831,5 @@
 	-rm -f GenPoly/driver_cfa_cpp-FindFunction.$(OBJEXT)
 	-rm -f GenPoly/driver_cfa_cpp-GenPoly.$(OBJEXT)
+	-rm -f GenPoly/driver_cfa_cpp-InstantiateGeneric.$(OBJEXT)
 	-rm -f GenPoly/driver_cfa_cpp-Lvalue.$(OBJEXT)
 	-rm -f GenPoly/driver_cfa_cpp-PolyMutator.$(OBJEXT)
@@ -937,4 +941,5 @@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-FindFunction.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-GenPoly.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-Lvalue.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@GenPoly/$(DEPDIR)/driver_cfa_cpp-PolyMutator.Po@am__quote@
@@ -1388,4 +1393,18 @@
 @am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/driver_cfa_cpp-DeclMutator.obj `if test -f 'GenPoly/DeclMutator.cc'; then $(CYGPATH_W) 'GenPoly/DeclMutator.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/DeclMutator.cc'; fi`
 
+GenPoly/driver_cfa_cpp-InstantiateGeneric.o: GenPoly/InstantiateGeneric.cc
+@am__fastdepCXX_TRUE@	$(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/driver_cfa_cpp-InstantiateGeneric.o -MD -MP -MF GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Tpo -c -o GenPoly/driver_cfa_cpp-InstantiateGeneric.o `test -f 'GenPoly/InstantiateGeneric.cc' || echo '$(srcdir)/'`GenPoly/InstantiateGeneric.cc
+@am__fastdepCXX_TRUE@	$(AM_V_at)$(am__mv) GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Tpo GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='GenPoly/InstantiateGeneric.cc' object='GenPoly/driver_cfa_cpp-InstantiateGeneric.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/driver_cfa_cpp-InstantiateGeneric.o `test -f 'GenPoly/InstantiateGeneric.cc' || echo '$(srcdir)/'`GenPoly/InstantiateGeneric.cc
+
+GenPoly/driver_cfa_cpp-InstantiateGeneric.obj: GenPoly/InstantiateGeneric.cc
+@am__fastdepCXX_TRUE@	$(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT GenPoly/driver_cfa_cpp-InstantiateGeneric.obj -MD -MP -MF GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Tpo -c -o GenPoly/driver_cfa_cpp-InstantiateGeneric.obj `if test -f 'GenPoly/InstantiateGeneric.cc'; then $(CYGPATH_W) 'GenPoly/InstantiateGeneric.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/InstantiateGeneric.cc'; fi`
+@am__fastdepCXX_TRUE@	$(AM_V_at)$(am__mv) GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Tpo GenPoly/$(DEPDIR)/driver_cfa_cpp-InstantiateGeneric.Po
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	$(AM_V_CXX)source='GenPoly/InstantiateGeneric.cc' object='GenPoly/driver_cfa_cpp-InstantiateGeneric.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCXX_FALSE@	DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCXX_FALSE@	$(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -c -o GenPoly/driver_cfa_cpp-InstantiateGeneric.obj `if test -f 'GenPoly/InstantiateGeneric.cc'; then $(CYGPATH_W) 'GenPoly/InstantiateGeneric.cc'; else $(CYGPATH_W) '$(srcdir)/GenPoly/InstantiateGeneric.cc'; fi`
+
 InitTweak/driver_cfa_cpp-GenInit.o: InitTweak/GenInit.cc
 @am__fastdepCXX_TRUE@	$(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(driver_cfa_cpp_CXXFLAGS) $(CXXFLAGS) -MT InitTweak/driver_cfa_cpp-GenInit.o -MD -MP -MF InitTweak/$(DEPDIR)/driver_cfa_cpp-GenInit.Tpo -c -o InitTweak/driver_cfa_cpp-GenInit.o `test -f 'InitTweak/GenInit.cc' || echo '$(srcdir)/'`InitTweak/GenInit.cc
Index: src/Parser/ExpressionNode.cc
===================================================================
--- src/Parser/ExpressionNode.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/Parser/ExpressionNode.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -529,23 +529,4 @@
 //##############################################################################
 
-CommaExprNode::CommaExprNode(): CompositeExprNode( new OperatorNode( OperatorNode::Comma )) {}
-
-CommaExprNode::CommaExprNode( ExpressionNode *exp ) : CompositeExprNode( new OperatorNode( OperatorNode::Comma ), exp ) {
-}
-
-CommaExprNode::CommaExprNode( ExpressionNode *exp1, ExpressionNode *exp2) : CompositeExprNode( new OperatorNode( OperatorNode::Comma ), exp1, exp2) {
-}
-
-// CommaExprNode *CommaExprNode::add_to_list( ExpressionNode *exp ) {
-// 	add_arg( exp );
-//
-// 	return this;
-// }
-
-CommaExprNode::CommaExprNode( const CommaExprNode &other ) : CompositeExprNode( other ) {
-}
-
-//##############################################################################
-
 ValofExprNode::ValofExprNode( StatementNode *s ): body( s ) {}
 
Index: src/Parser/ParseNode.h
===================================================================
--- src/Parser/ParseNode.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/Parser/ParseNode.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -324,15 +324,4 @@
   private:
 	std::list< Label > labels;
-};
-
-class CommaExprNode : public CompositeExprNode {
-  public:
-	CommaExprNode();
-	CommaExprNode( ExpressionNode * );
-	CommaExprNode( ExpressionNode *, ExpressionNode * );
-	CommaExprNode( const CommaExprNode &other );
-
-	// virtual CommaExprNode *add_to_list( ExpressionNode * );
-	virtual CommaExprNode *clone() const { return new CommaExprNode( *this ); }
 };
 
@@ -567,10 +556,4 @@
 };
 
-class NullStmtNode : public CompoundStmtNode {
-  public:
-	Statement *build() const;
-	void print( std::ostream &, int indent = 0 ) const;
-};
-
 class InitializerNode : public ParseNode {
   public:
Index: src/Parser/StatementNode.cc
===================================================================
--- src/Parser/StatementNode.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/Parser/StatementNode.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -417,13 +417,4 @@
 }
 
-
-void NullStmtNode::print( ostream &os, int indent ) const {
-	os << string( indent, ' ' ) << "Null Statement:" << endl;
-}
-
-Statement *NullStmtNode::build() const {
-	return new NullStmt;
-}
-
 // Local Variables: //
 // tab-width: 4 //
Index: src/Parser/TypeData.cc
===================================================================
--- src/Parser/TypeData.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/Parser/TypeData.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -510,5 +510,5 @@
 		return buildVariable();
 	} else {
-		return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init, isInline, isNoreturn );
+		return new ObjectDecl( name, sc, linkage, bitfieldWidth, build(), init, std::list< Attribute * >(),  isInline, isNoreturn );
 	} // if
 	return 0;
Index: src/ResolvExpr/Resolver.cc
===================================================================
--- src/ResolvExpr/Resolver.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/ResolvExpr/Resolver.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -24,4 +24,5 @@
 #include "SynTree/Initializer.h"
 #include "SymTab/Indexer.h"
+#include "SymTab/Autogen.h"
 #include "Common/utility.h"
 #include "InitTweak/InitTweak.h"
@@ -41,4 +42,5 @@
 
 		virtual void visit( ArrayType * at );
+		virtual void visit( PointerType * at );
 
 		virtual void visit( ExprStmt *exprStmt );
@@ -52,5 +54,4 @@
 		virtual void visit( BranchStmt *branchStmt );
 		virtual void visit( ReturnStmt *returnStmt );
-		virtual void visit( ImplicitCtorDtorStmt * impCtorDtorStmt );
 
 		virtual void visit( SingleInit *singleInit );
@@ -59,4 +60,7 @@
 	  private:
   	typedef std::list< Initializer * >::iterator InitIterator;
+
+		template< typename PtrType >
+		void handlePtrType( PtrType * type );
 
 	  void resolveAggrInit( AggregateDecl *, InitIterator &, InitIterator & );
@@ -192,13 +196,22 @@
 	}
 
+	template< typename PtrType >
+	void Resolver::handlePtrType( PtrType * type ) {
+		if ( type->get_dimension() ) {
+			CastExpr *castExpr = new CastExpr( type->get_dimension(), SymTab::SizeType->clone() );
+			Expression *newExpr = findSingleExpression( castExpr, *this );
+			delete type->get_dimension();
+			type->set_dimension( newExpr );
+		}
+	}
+
 	void Resolver::visit( ArrayType * at ) {
-		if ( at->get_dimension() ) {
-			BasicType arrayLenType = BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
-			CastExpr *castExpr = new CastExpr( at->get_dimension(), arrayLenType.clone() );
-			Expression *newExpr = findSingleExpression( castExpr, *this );
-			delete at->get_dimension();
-			at->set_dimension( newExpr );
-		}
+		handlePtrType( at );
 		Visitor::visit( at );
+	}
+
+	void Resolver::visit( PointerType * pt ) {
+		handlePtrType( pt );
+		Visitor::visit( pt );
 	}
 
@@ -422,6 +435,6 @@
 
 	void Resolver::visit( ListInit * listInit ) {
-		InitIterator iter = listInit->begin_initializers();
-		InitIterator end = listInit->end_initializers();
+		InitIterator iter = listInit->begin();
+		InitIterator end = listInit->end();
 
 		if ( ArrayType * at = dynamic_cast< ArrayType * >( initContext ) ) {
@@ -521,54 +534,19 @@
 		// implicitly generated, there's no way for it to have side effects, so get rid of it
 		// to clean up generated code.
-		if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
+		if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
 			delete ctorInit->get_ctor();
 			ctorInit->set_ctor( NULL );
 		}
-		if ( InitTweak::isInstrinsicSingleArgCallStmt( ctorInit->get_ctor() ) ) {
+
+		// xxx - todo
+		// if ( InitTweak::isIntrinsicCallStmt( ctorInit->get_ctor() ) ) {
+		// 	// can reduce the constructor down to a SingleInit using the
+		// 	// second argument from the ctor call
+		// }
+
+		if ( InitTweak::isIntrinsicSingleArgCallStmt( ctorInit->get_dtor() ) ) {
 			delete ctorInit->get_dtor();
 			ctorInit->set_dtor( NULL );
 		}
-	}
-
-	void Resolver::visit( ImplicitCtorDtorStmt * impCtorDtorStmt ) {
-		// before resolving ctor/dtor, need to remove type qualifiers from the first argument (the object being constructed).
-		// Do this through a cast expression to greatly simplify the code.
-		Expression * callExpr = InitTweak::getCtorDtorCall( impCtorDtorStmt );
-		assert( callExpr );
-		Expression *& constructee = InitTweak::getCallArg( callExpr, 0 );
-		Type * type = 0;
-
-		// need to find the type of the first argument, which is unfortunately not uniform since array construction
-		// includes an untyped '+' expression.
-		if ( UntypedExpr * plusExpr = dynamic_cast< UntypedExpr * >( constructee ) ) {
-			// constructee is <array>+<index>
-			// get Variable <array>, then get the base type of the VariableExpr - this is the type that needs to be fixed
-			Expression * arr = InitTweak::getCallArg( plusExpr, 0 );
-			assert( dynamic_cast< VariableExpr * >( arr ) || dynamic_cast< MemberExpr *>( arr ) );
-			assert( arr && arr->get_results().size() == 1 );
-			type = arr->get_results().front()->clone();
-		} else {
-			// otherwise, constructing a plain object, which means the object's address is being taken.
-			// Need to get the type of the VariableExpr object, because the AddressExpr is rebuilt and uses the
-			// type of the VariableExpr to do so.
-			assert( constructee->get_results().size() == 1 );
-			AddressExpr * addrExpr = dynamic_cast< AddressExpr * > ( constructee );
-			assert( addrExpr && addrExpr->get_results().size() == 1 );
-			type = addrExpr->get_results().front()->clone();
-		}
-		// cast to T* with qualifiers removed.
-		// unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
-		// must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
-		// remove lvalue as a qualifier, this can change to
-		//   type->get_qualifiers() = Type::Qualifiers();
-		Type * base = InitTweak::getPointerBase( type );
-		assert( base );
-		base->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
-		// if pointer has lvalue qualifier, cast won't appear in output
-		type->set_isLvalue( false );
-		constructee = new CastExpr( constructee, type );
-
-		// finally, resolve the ctor/dtor
-		impCtorDtorStmt->get_callStmt()->accept( *this );
 	}
 } // namespace ResolvExpr
Index: src/SymTab/Autogen.cc
===================================================================
--- src/SymTab/Autogen.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SymTab/Autogen.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -26,4 +26,6 @@
 
 namespace SymTab {
+	Type * SizeType = 0;
+
 	class AutogenerateRoutines : public Visitor {
 		public:
@@ -59,36 +61,4 @@
 	bool isUnnamedBitfield( ObjectDecl * obj ) {
 		return obj != NULL && obj->get_name() == "" && obj->get_bitfieldWidth() != NULL;
-	}
-
-	template< typename OutputIterator >
-	void makeScalarFunction( Expression *src, ObjectDecl *dstParam, DeclarationWithType *member, std::string fname, OutputIterator out ) {
-		ObjectDecl *obj = dynamic_cast<ObjectDecl *>( member );
-		// unnamed bit fields are not copied as they cannot be accessed
-		if ( isUnnamedBitfield( obj ) ) return;
-
-		// want to be able to generate assignment, ctor, and dtor generically,
-		// so fname is either ?=?, ?{}, or ^?{}
-		UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
-
-		UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
-		derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
-
-		// do something special for unnamed members
-		Expression *dstselect = new AddressExpr( new MemberExpr( member, derefExpr ) );
-		fExpr->get_args().push_back( dstselect );
-
-		if ( src ) {
-			fExpr->get_args().push_back( src );
-		}
-
-		Statement * callStmt = new ExprStmt( noLabels, fExpr );
-		if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) ) ) {
-			// 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;
 	}
 
@@ -203,13 +173,7 @@
 	}
 
-	void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) {
-		if ( isGeneric ) {
-			// rewrite member type in terms of the type variables on this operator
-			field = field->clone();
-			genericSubs.apply( field );
-
-			if ( src ) {
-				genericSubs.apply( src );
-			}
+	void makeStructMemberOp( ObjectDecl * dstParam, Expression * src, DeclarationWithType * field, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) {
+		if ( isDynamicLayout && src ) {
+			genericSubs.apply( src );
 		}
 
@@ -219,26 +183,22 @@
 		}
 
+		InitTweak::InitExpander srcParam( src );
+
 		// assign to destination (and return value if generic)
-		if ( ArrayType *array = dynamic_cast< ArrayType * >( field->get_type() ) ) {
-			UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
-			derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
-			Expression *dstselect = new MemberExpr( field, derefExpr );
-
-			makeArrayFunction( src, dstselect, array, func->get_name(), back_inserter( func->get_statements()->get_kids() ), forward );
-			if ( isGeneric && returnVal ) {
-				UntypedExpr *derefRet = new UntypedExpr( new NameExpr( "*?" ) );
-				derefRet->get_args().push_back( new VariableExpr( returnVal ) );
-				Expression *retselect = new MemberExpr( field, derefRet );
-
-				makeArrayFunction( src, retselect, array, func->get_name(), back_inserter( func->get_statements()->get_kids() ), forward );
-			}
-		} else {
-			makeScalarFunction( src, dstParam, field, func->get_name(), back_inserter( func->get_statements()->get_kids() ) );
-			if ( isGeneric && returnVal ) makeScalarFunction( src, returnVal, field, func->get_name(), back_inserter( func->get_statements()->get_kids() ) );
+		UntypedExpr *derefExpr = new UntypedExpr( new NameExpr( "*?" ) );
+		derefExpr->get_args().push_back( new VariableExpr( dstParam ) );
+		Expression *dstselect = new MemberExpr( field, derefExpr );
+		genImplicitCall( srcParam, dstselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
+
+		if ( isDynamicLayout && returnVal ) {
+			UntypedExpr *derefRet = new UntypedExpr( new NameExpr( "*?" ) );
+			derefRet->get_args().push_back( new VariableExpr( returnVal ) );
+			Expression *retselect = new MemberExpr( field, derefRet );
+			genImplicitCall( srcParam, retselect, func->get_name(), back_inserter( func->get_statements()->get_kids() ), field, forward );
 		} // if
 	}
 
 	template<typename Iterator>
-	void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric, bool forward = true ) {
+	void makeStructFunctionBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout, bool forward = true ) {
 		for ( ; member != end; ++member ) {
 			if ( DeclarationWithType *field = dynamic_cast< DeclarationWithType * >( *member ) ) { // otherwise some form of type declaration, e.g. Aggregate
@@ -276,5 +236,5 @@
 
 				Expression *srcselect = srcParam ? new MemberExpr( field, new VariableExpr( srcParam ) ) : NULL;
-				makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric, forward );
+				makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isDynamicLayout, forward );
 			} // if
 		} // for
@@ -284,5 +244,5 @@
 	/// void ?{}(A *, int) and void?{}(A *, int, int) for a struct A which has two int fields.
 	template<typename Iterator>
-	void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isGeneric ) {
+	void makeStructFieldCtorBody( Iterator member, Iterator end, FunctionDecl * func, TypeSubstitution & genericSubs, bool isDynamicLayout ) {
 		FunctionType * ftype = func->get_functionType();
 		std::list<DeclarationWithType*> & params = ftype->get_parameters();
@@ -310,9 +270,9 @@
 					// matching parameter, initialize field with copy ctor
 					Expression *srcselect = new VariableExpr(*parameter);
-					makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isGeneric );
+					makeStructMemberOp( dstParam, srcselect, field, func, genericSubs, isDynamicLayout );
 					++parameter;
 				} else {
 					// no matching parameter, initialize field with default ctor
-					makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isGeneric );
+					makeStructMemberOp( dstParam, NULL, field, func, genericSubs, isDynamicLayout );
 				}
 			}
@@ -324,10 +284,10 @@
 
 		// Make function polymorphic in same parameters as generic struct, if applicable
-		bool isGeneric = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
+		bool isDynamicLayout = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for union)
 		std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
 		std::list< Expression* > structParams;  // List of matching parameters to put on types
 		TypeSubstitution genericSubs; // Substitutions to make to member types of struct
 		for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
-			isGeneric = true;
+			if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true;
 			TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
 			assignType->get_forall().push_back( typeParam );
@@ -389,5 +349,5 @@
 			FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType->clone(), new CompoundStmt( noLabels ), true, false );
 			ctor->fixUniqueId();
-			makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isGeneric );
+			makeStructFieldCtorBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctor, genericSubs, isDynamicLayout );
 			memCtors.push_back( ctor );
 		}
@@ -395,11 +355,11 @@
 
 		// generate appropriate calls to member ctor, assignment
-		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isGeneric );
-		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isGeneric );
-		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isGeneric );
+		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), assignDecl, genericSubs, isDynamicLayout );
+		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), ctorDecl, genericSubs, isDynamicLayout );
+		makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), copyCtorDecl, genericSubs, isDynamicLayout );
 		// needs to do everything in reverse, so pass "forward" as false
-		makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isGeneric, false );
-
-		if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
+		makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dtorDecl, genericSubs, isDynamicLayout, false );
+
+		if ( ! isDynamicLayout ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
 
 		declsToAdd.push_back( assignDecl );
@@ -414,9 +374,9 @@
 
 		// Make function polymorphic in same parameters as generic union, if applicable
-		bool isGeneric = false;  // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)
+		bool isDynamicLayout = false; // NOTE this flag is an incredibly ugly kludge; we should fix the assignment signature instead (ditto for struct)
 		std::list< TypeDecl* >& genericParams = aggregateDecl->get_parameters();
 		std::list< Expression* > unionParams;  // List of matching parameters to put on types
 		for ( std::list< TypeDecl* >::const_iterator param = genericParams.begin(); param != genericParams.end(); ++param ) {
-			isGeneric = true;
+			if ( (*param)->get_kind() == TypeDecl::Any ) isDynamicLayout = true;
 			TypeDecl *typeParam = cloneAndRename( *param, "_autoassign_" + aggregateDecl->get_name() + "_" + (*param)->get_name() );
 			assignType->get_forall().push_back( typeParam );
@@ -454,7 +414,6 @@
 
 		makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
-		if ( isGeneric ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
-
-		if ( ! isGeneric ) assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
+		if ( isDynamicLayout ) makeUnionFieldsAssignment( srcParam, returnVal, cloneWithParams( refType, unionParams ), back_inserter( assignDecl->get_statements()->get_kids() ) );
+		else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
 
 		// body of assignment and copy ctor is the same
Index: src/SymTab/Autogen.h
===================================================================
--- src/SymTab/Autogen.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SymTab/Autogen.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -22,82 +22,160 @@
 #include "SynTree/Declaration.h"
 #include "SynTree/Initializer.h"
+#include "InitTweak/InitTweak.h"
 
 namespace SymTab {
-  /// Generates assignment operators, constructors, and destructor for aggregate types as required
-  void autogenerateRoutines( std::list< Declaration * > &translationUnit );
+	/// Generates assignment operators, constructors, and destructor for aggregate types as required
+	void autogenerateRoutines( std::list< Declaration * > &translationUnit );
 
-  // originally makeArrayAssignment - changed to Function because it is now used for ctors and dtors as well
-  // admittedly not a great name change. This used to live in Validate.cc, but has been moved so it can be reused elsewhere
+	/// returns true if obj's name is the empty string and it has a bitfield width
+	bool isUnnamedBitfield( ObjectDecl * obj );
 
-  /// Store in out a loop which calls fname on each element of the array with srcParam and dstParam as arguments.
-  /// If forward is true, loop goes from 0 to N-1, else N-1 to 0
-  template< typename OutputIterator >
-  void makeArrayFunction( Expression *srcParam, Expression *dstParam, ArrayType *array, std::string fname, OutputIterator out, bool forward = true ) {
-    static UniqueName indexName( "_index" );
+	/// size_t type - set when size_t typedef is seen. Useful in a few places,
+	/// such as in determining array dimension type
+	extern Type * SizeType;
 
-    // for a flexible array member nothing is done -- user must define own assignment
-    if ( ! array->get_dimension() ) return;
+	/// 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 >
+	Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
 
-    Expression * begin, * end, * update, * cmp;
-    if ( forward ) {
-      // generate: for ( int i = 0; i < 0; ++i )
-      begin = new NameExpr( "0" );
-      end = array->get_dimension()->clone();
-      cmp = new NameExpr( "?<?" );
-      update = new NameExpr( "++?" );
-    } else {
-      // generate: for ( int i = N-1; i >= 0; --i )
-      begin = new UntypedExpr( new NameExpr( "?-?" ) );
-      ((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() );
-      ((UntypedExpr*)begin)->get_args().push_back( new NameExpr( "1" ) );
-      end = new NameExpr( "0" );
-      cmp = new NameExpr( "?>=?" );
-      update = new NameExpr( "--?" );
-    }
+	/// 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 >
+	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 ^?{}
+		UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
 
-    ObjectDecl *index = new ObjectDecl( indexName.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), NULL );
+		// do something special for unnamed members
+		dstParam = new AddressExpr( dstParam );
+		if ( addCast ) {
+			// cast to T* with qualifiers removed, so that qualified objects can be constructed
+			// and destructed with the same functions as non-qualified objects.
+			// unfortunately, lvalue is considered a qualifier. For AddressExpr to resolve, its argument
+			// must have an lvalue qualified type, so remove all qualifiers except lvalue. If we ever
+			// remove lvalue as a qualifier, this can change to
+			//   type->get_qualifiers() = Type::Qualifiers();
+			assert( type );
+			Type * castType = type->clone();
+			castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
+			castType->set_isLvalue( true ); // xxx - might not need this
+			dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
+		}
+		fExpr->get_args().push_back( dstParam );
 
-    UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );
-    init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
-    init->get_args().push_back( begin );
-    index->set_init( new SingleInit( init, std::list<Expression*>() ) );
+		Statement * listInit = srcParam.buildListInit( fExpr );
 
-    UntypedExpr *cond = new UntypedExpr( cmp );
-    cond->get_args().push_back( new VariableExpr( index ) );
-    cond->get_args().push_back( end );
+		std::list< Expression * > args = *++srcParam;
+		fExpr->get_args().splice( fExpr->get_args().end(), args );
 
-    UntypedExpr *inc = new UntypedExpr( update );
-    inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
+		*out++ = new ExprStmt( noLabels, fExpr );
 
-    // want to be able to generate assignment, ctor, and dtor generically,
-    // so fname is either ?=?, ?{}, or ^?{}
-    UntypedExpr *fExpr = new UntypedExpr( new NameExpr( fname ) );
+		srcParam.clearArrayIndices();
 
-    UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?+?" ) );
-    dstIndex->get_args().push_back( dstParam );
-    dstIndex->get_args().push_back( new VariableExpr( index ) );
-    fExpr->get_args().push_back( dstIndex );
+		return listInit;
+	}
 
-    // srcParam is NULL for default ctor/dtor
-    if ( srcParam ) {
-      UntypedExpr *srcIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
-      srcIndex->get_args().push_back( srcParam );
-      srcIndex->get_args().push_back( new VariableExpr( index ) );
-      fExpr->get_args().push_back( srcIndex );
-    }
+	/// Store in out a loop which calls fname on each element of the array with srcParam and dstParam as arguments.
+	/// If forward is true, loop goes from 0 to N-1, else N-1 to 0
+	template< typename OutputIterator >
+	void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) {
+		static UniqueName indexName( "_index" );
 
-    std::list<Statement *> initList;
-    CompoundStmt * block = new CompoundStmt( noLabels );
-    block->get_kids().push_back( new DeclStmt( noLabels, index ) );
-    block->get_kids().push_back( new ForStmt( noLabels, initList, cond, inc, new ExprStmt( noLabels, fExpr ) ) );
+		// for a flexible array member nothing is done -- user must define own assignment
+		if ( ! array->get_dimension() ) return ;
 
-    Statement * stmt = block;
-    if ( fname == "?{}" || fname == "^?{}" ) {
-      // implicitly generated ctor/dtor calls should be wrapped
-      // so that later passes are aware they were generated
-      stmt = new ImplicitCtorDtorStmt( stmt );
-    }
-    *out++ = stmt;
-  }
+		Expression * begin, * end, * update, * cmp;
+		if ( forward ) {
+			// generate: for ( int i = 0; i < 0; ++i )
+			begin = new NameExpr( "0" );
+			end = array->get_dimension()->clone();
+			cmp = new NameExpr( "?<?" );
+			update = new NameExpr( "++?" );
+		} else {
+			// generate: for ( int i = N-1; i >= 0; --i )
+			begin = new UntypedExpr( new NameExpr( "?-?" ) );
+			((UntypedExpr*)begin)->get_args().push_back( array->get_dimension()->clone() );
+			((UntypedExpr*)begin)->get_args().push_back( new NameExpr( "1" ) );
+			end = new NameExpr( "0" );
+			cmp = new NameExpr( "?>=?" );
+			update = new NameExpr( "--?" );
+		}
+
+		ObjectDecl *index = new ObjectDecl( indexName.newName(), DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::SignedInt ), NULL );
+
+		UntypedExpr *init = new UntypedExpr( new NameExpr( "?=?" ) );
+		init->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
+		init->get_args().push_back( begin );
+		index->set_init( new SingleInit( init, std::list<Expression*>() ) );
+
+		UntypedExpr *cond = new UntypedExpr( cmp );
+		cond->get_args().push_back( new VariableExpr( index ) );
+		cond->get_args().push_back( end );
+
+		UntypedExpr *inc = new UntypedExpr( update );
+		inc->get_args().push_back( new AddressExpr( new VariableExpr( index ) ) );
+
+		UntypedExpr *dstIndex = new UntypedExpr( new NameExpr( "?[?]" ) );
+		dstIndex->get_args().push_back( dstParam );
+		dstIndex->get_args().push_back( new VariableExpr( index ) );
+		dstParam = dstIndex;
+
+		// srcParam must keep track of the array indices to build the
+		// source parameter and/or array list initializer
+		srcParam.addArrayIndex( new VariableExpr( index ), array->get_dimension()->clone() );
+
+		// for stmt's body, eventually containing call
+		CompoundStmt * body = new CompoundStmt( noLabels );
+		Statement * listInit = genCall( srcParam, dstParam, fname, back_inserter( body->get_kids() ), array->get_base(), addCast, forward );
+
+		// block containing for stmt and index variable
+		std::list<Statement *> initList;
+		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 ) );
+
+		*out++ = block;
+	}
+
+	template< typename OutputIterator >
+	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 {
+			return genScalarCall( srcParam, dstParam, fname, out, type, addCast );
+		}
+	}
+
+	/// inserts into out a generated call expression to function fname with arguments dstParam
+	/// and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. decl is the
+	/// object being constructed. The function wraps constructor and destructor calls in an
+	/// ImplicitCtorDtorStmt node.
+	template< typename OutputIterator >
+	void genImplicitCall( InitTweak::InitExpander &  srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, DeclarationWithType * decl, bool forward = true ) {
+		ObjectDecl *obj = dynamic_cast<ObjectDecl *>( decl );
+		assert( obj );
+		// unnamed bit fields are not copied as they cannot be accessed
+		if ( isUnnamedBitfield( obj ) ) return;
+
+		bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && obj->get_bitfieldWidth() == NULL ) );
+		std::list< Statement * > stmts;
+		genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->get_type(), addCast, forward );
+
+		// 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;
+		}
+	}
 } // namespace SymTab
 #endif // AUTOGEN_H
Index: src/SymTab/FixFunction.cc
===================================================================
--- src/SymTab/FixFunction.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SymTab/FixFunction.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// FixFunction.cc -- 
+// FixFunction.cc --
 //
 // Author           : Richard C. Bilson
@@ -44,5 +44,6 @@
 
 	Type * FixFunction::mutate(ArrayType *arrayType) {
-		PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), maybeClone( arrayType->get_base()->clone() ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() );
+		// need to recursively mutate the base type in order for multi-dimensional arrays to work.
+		PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() );
 		delete arrayType;
 		return pointerType;
Index: src/SymTab/Validate.cc
===================================================================
--- src/SymTab/Validate.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SymTab/Validate.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -174,5 +174,5 @@
 
 		virtual void visit( FunctionDecl *funcDecl );
-};
+	};
 
 	class CompoundLiteral : public GenPoly::DeclMutator {
@@ -191,9 +191,9 @@
 		EliminateTypedef::eliminateTypedef( translationUnit );
 		HoistStruct::hoistStruct( translationUnit );
+		autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs Pass1
 		acceptAll( translationUnit, pass1 );
 		acceptAll( translationUnit, pass2 );
 		ReturnChecker::checkFunctionReturns( translationUnit );
-		mutateAll( translationUnit, compoundliteral );
-		autogenerateRoutines( translationUnit );
+		compoundliteral.mutateDeclarationList( translationUnit );
 		acceptAll( translationUnit, pass3 );
 		VerifyCtorDtor::verify( translationUnit );
@@ -490,5 +490,14 @@
 		EliminateTypedef eliminator;
 		mutateAll( translationUnit, eliminator );
+		if ( eliminator.typedefNames.count( "size_t" ) ) {
+			// grab and remember declaration of size_t
+			SizeType = eliminator.typedefNames["size_t"].first->get_base()->clone();
+		} else {
+			// xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
+			// eventually should have a warning for this case.
+			SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
+		}
 		filter( translationUnit, isTypedef, true );
+
 	}
 
@@ -518,4 +527,5 @@
 	Declaration *EliminateTypedef::mutate( TypedefDecl * tyDecl ) {
 		Declaration *ret = Mutator::mutate( tyDecl );
+
 		if ( typedefNames.count( tyDecl->get_name() ) == 1 && typedefNames[ tyDecl->get_name() ].second == scopeLevel ) {
 			// typedef to the same name from the same scope
Index: src/SynTree/Declaration.cc
===================================================================
--- src/SynTree/Declaration.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/Declaration.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Declaration.cc -- 
+// Declaration.cc --
 //
 // Author           : Richard C. Bilson
@@ -20,4 +20,5 @@
 #include "Initializer.h"
 #include "Type.h"
+#include "Attribute.h"
 #include "Common/utility.h"
 
Index: src/SynTree/Declaration.h
===================================================================
--- src/SynTree/Declaration.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/Declaration.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -64,5 +64,5 @@
 class DeclarationWithType : public Declaration {
   public:
-	DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage );
+	DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, const std::list< Attribute * > & attributes );
 	DeclarationWithType( const DeclarationWithType &other );
 	virtual ~DeclarationWithType();
@@ -75,4 +75,7 @@
 	int get_scopeLevel() const { return scopeLevel; }
 	void set_scopeLevel( int newValue ) { scopeLevel = newValue; }
+
+	std::list< Attribute * >& get_attributes() { return attributes; }
+	const std::list< Attribute * >& get_attributes() const { return attributes; }
 
 	virtual DeclarationWithType *clone() const = 0;
@@ -87,4 +90,6 @@
 	// shadowed identifiers can be accessed
 	int scopeLevel = 0;
+
+	std::list< Attribute * > attributes;
 };
 
@@ -92,5 +97,5 @@
 	typedef DeclarationWithType Parent;
   public:
-	ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline = false, bool isNoreturn = false );
+	ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, const std::list< Attribute * > attributes = std::list< Attribute * >(), bool isInline = false, bool isNoreturn = false );
 	ObjectDecl( const ObjectDecl &other );
 	virtual ~ObjectDecl();
@@ -131,5 +136,4 @@
 	std::list< std::string >& get_oldIdents() { return oldIdents; }
 	std::list< Declaration* >& get_oldDecls() { return oldDecls; }
-	std::list< Attribute * >& get_attributes() { return attributes; }
 
 	virtual FunctionDecl *clone() const { return new FunctionDecl( *this ); }
@@ -143,5 +147,4 @@
 	std::list< std::string > oldIdents;
 	std::list< Declaration* > oldDecls;
-	std::list< Attribute * > attributes;
 };
 
Index: src/SynTree/DeclarationWithType.cc
===================================================================
--- src/SynTree/DeclarationWithType.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/DeclarationWithType.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -16,15 +16,18 @@
 #include "Declaration.h"
 #include "Type.h"
+#include "Attribute.h"
 #include "Common/utility.h"
 
-DeclarationWithType::DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage )
-		: Declaration( name, sc, linkage ) {
+DeclarationWithType::DeclarationWithType( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, const std::list< Attribute * > & attributes )
+		: Declaration( name, sc, linkage ), attributes( attributes ) {
 }
 
 DeclarationWithType::DeclarationWithType( const DeclarationWithType &other )
 		: Declaration( other ), mangleName( other.mangleName ), scopeLevel( other.scopeLevel ) {
+	cloneAll( other.attributes, attributes );
 }
 
 DeclarationWithType::~DeclarationWithType() {
+	deleteAll( attributes );
 }
 
Index: src/SynTree/Expression.cc
===================================================================
--- src/SynTree/Expression.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/Expression.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -344,10 +344,11 @@
 }
 
+//// is this right? It's cloning the member, but the member is a declaration so probably shouldn't be cloned...
 MemberExpr::MemberExpr( const MemberExpr &other ) :
-		Expression( other ), member( maybeClone( other.member ) ), aggregate( maybeClone( other.aggregate ) ) {
+		Expression( other ), member( other.member ), aggregate( maybeClone( other.aggregate ) ) {
 }
 
 MemberExpr::~MemberExpr() {
-	delete member;
+	// delete member;
 	delete aggregate;
 }
Index: src/SynTree/FunctionDecl.cc
===================================================================
--- src/SynTree/FunctionDecl.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/FunctionDecl.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -23,5 +23,5 @@
 
 FunctionDecl::FunctionDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, FunctionType *type, CompoundStmt *statements, bool isInline, bool isNoreturn, std::list< Attribute * > attributes )
-		: Parent( name, sc, linkage ), type( type ), statements( statements ), attributes( attributes ) {
+		: Parent( name, sc, linkage, attributes ), type( type ), statements( statements ) {
 	set_isInline( isInline );
 	set_isNoreturn( isNoreturn );
@@ -34,5 +34,4 @@
 FunctionDecl::FunctionDecl( const FunctionDecl &other )
 	: Parent( other ), type( maybeClone( other.type ) ), statements( maybeClone( other.statements ) ) {
-		cloneAll( other.attributes, attributes );
 }
 
@@ -40,5 +39,4 @@
 	delete type;
 	delete statements;
-	deleteAll( attributes );
 }
 
@@ -69,5 +67,5 @@
 	} // if
 
-	printAll( attributes, os, indent );
+	printAll( get_attributes(), os, indent );
 
 	if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
Index: src/SynTree/Initializer.h
===================================================================
--- src/SynTree/Initializer.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/Initializer.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -93,6 +93,7 @@
 	std::list<Initializer*> &get_initializers() { return initializers; }
 
-	std::list<Initializer*>::iterator begin_initializers() { return initializers.begin(); }
-	std::list<Initializer*>::iterator end_initializers() { return initializers.end(); }
+	typedef std::list<Initializer*>::iterator iterator;
+	iterator begin() { return initializers.begin(); }
+	iterator end() { return initializers.end(); }
 
 	virtual ListInit *clone() const { return new ListInit( *this ); }
Index: src/SynTree/Label.h
===================================================================
--- src/SynTree/Label.h	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/Label.h	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -24,5 +24,5 @@
 class Label {
   public:
-	Label( const std::string & name = "", Statement * labelled = 0 ) : name( name ), labelled( labelled ) {}
+	Label( const std::string & name = "", Statement * labelled = 0, const std::list< Attribute * > & attributes = std::list< Attribute * >() ) : name( name ), labelled( labelled ), attributes( attributes ) {}
 	Label( const char * name, Statement * labelled = 0 ) : name( name ), labelled( labelled ) {}
 
Index: src/SynTree/ObjectDecl.cc
===================================================================
--- src/SynTree/ObjectDecl.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/SynTree/ObjectDecl.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -18,9 +18,10 @@
 #include "Initializer.h"
 #include "Expression.h"
+#include "Attribute.h"
 #include "Common/utility.h"
 #include "Statement.h"
 
-ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, bool isInline, bool isNoreturn )
-	: Parent( name, sc, linkage ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
+ObjectDecl::ObjectDecl( const std::string &name, DeclarationNode::StorageClass sc, LinkageSpec::Type linkage, Expression *bitfieldWidth, Type *type, Initializer *init, const std::list< Attribute * > attributes, bool isInline, bool isNoreturn )
+	: Parent( name, sc, linkage, attributes ), type( type ), init( init ), bitfieldWidth( bitfieldWidth ) {
 	set_isInline( isInline );
 	set_isNoreturn( isNoreturn );
@@ -45,4 +46,6 @@
 		os << LinkageSpec::toString( get_linkage() ) << " ";
 	} // if
+
+	printAll( get_attributes(), os, indent );
 
 	if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
@@ -80,4 +83,6 @@
 	} // if
 
+	// xxx - should printShort print attributes?
+
 	if ( get_storageClass() != DeclarationNode::NoStorageClass ) {
 		os << DeclarationNode::storageName[ get_storageClass() ] << ' ';
Index: src/main.cc
===================================================================
--- src/main.cc	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/main.cc	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -28,4 +28,5 @@
 #include "GenPoly/Box.h"
 #include "GenPoly/CopyParams.h"
+#include "GenPoly/InstantiateGeneric.h"
 #include "CodeGen/Generate.h"
 #include "CodeGen/FixNames.h"
@@ -42,5 +43,4 @@
 #include "InitTweak/GenInit.h"
 #include "InitTweak/FixInit.h"
-#include "InitTweak/FixGlobalInit.h"
 //#include "Explain/GenProlog.h"
 //#include "Try/Visit.h"
@@ -282,6 +282,4 @@
 		OPTPRINT( "fixNames" )
 		CodeGen::fixNames( translationUnit );
-		OPTPRINT( "fixGlobalInit" );
-		InitTweak::fixGlobalInit( translationUnit, filename, libcfap || treep );
 		OPTPRINT( "tweakInit" )
 		InitTweak::genInit( translationUnit );
@@ -304,7 +302,7 @@
 		}
 
+		// fix ObjectDecl - replaces ConstructorInit nodes
 		OPTPRINT( "fixInit" )
-		// fix ObjectDecl - replaces ConstructorInit nodes
-		InitTweak::fix( translationUnit );
+		InitTweak::fix( translationUnit, filename, libcfap || treep );
 		if ( ctorinitp ) {
 			dump ( translationUnit );
@@ -312,4 +310,6 @@
 		}
 
+		OPTPRINT("instantiateGenerics")
+		GenPoly::instantiateGeneric( translationUnit );
 		OPTPRINT( "copyParams" );
 		GenPoly::copyParams( translationUnit );
Index: src/tests/.expect/64/extension.txt
===================================================================
--- src/tests/.expect/64/extension.txt	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/tests/.expect/64/extension.txt	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -100,15 +100,2 @@
     ((void)((__extension__ __a__i_2 , __extension__ __b__i_2) , __extension__ __c__i_2));
 }
-__attribute__ ((constructor(),)) static void _init_extension(void){
-    int _global_init0;
-    ((void)((*((int *)(&__a__i_1)))=_global_init0) /* ?{} */);
-    int _global_init1;
-    ((void)((*((int *)(&__b__i_1)))=_global_init1) /* ?{} */);
-    int _global_init2;
-    ((void)((*((int *)(&__c__i_1)))=_global_init2) /* ?{} */);
-}
-__attribute__ ((destructor(),)) static void _destroy_extension(void){
-    ((void)((*((int *)(&__c__i_1)))) /* ^?{} */);
-    ((void)((*((int *)(&__b__i_1)))) /* ^?{} */);
-    ((void)((*((int *)(&__a__i_1)))) /* ^?{} */);
-}
Index: src/tests/.expect/multiDimension.txt
===================================================================
--- src/tests/.expect/multiDimension.txt	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
+++ src/tests/.expect/multiDimension.txt	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -0,0 +1,304 @@
+constructing with 1
+constructing with 2
+constructing with 3
+constructing with 4
+constructing with 5
+constructing with 6
+constructing with 7
+constructing with 8
+constructing with 9
+constructing with 10
+constructing with 1
+constructing with 2
+constructing with 3
+constructing with 4
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+constructing with 1234567
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+constructing with 1
+constructing with 2
+constructing with 3
+constructing with 4
+constructing with 5
+constructing with 6
+constructing with 7
+constructing with 8
+constructing with 9
+constructing with 0
+constructing with 0
+constructing with 0
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+default constructing
+constructing with 999
+constructing with 1111
+default constructing
+default constructing
+constructing with 1
+constructing with 2
+constructing with 3
+constructing with 4
+default constructing
+default constructing
+default constructing
+default constructing
+constructing with 0
+default constructing
+default constructing
+default constructing
+constructing with 11
+constructing with 22
+constructing with 33
+constructing with 55
+constructing with 66
+default constructing
+constructing with 77
+default constructing
+default constructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
+destructing
Index: src/tests/init_once.c
===================================================================
--- src/tests/init_once.c	(revision 97065543cf1b9f9729488075aec62a4941f19f0d)
+++ src/tests/init_once.c	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -92,4 +92,8 @@
 init_once y = x;
 
+void static_variable() {
+	static init_once x;
+}
+
 int main() {
 	// local variables
@@ -179,4 +183,9 @@
 		}
 	}
+
+	// function-scoped static variable
+	for (int i = 0; i < 10; i++) {
+		static_variable();
+	}
 }
 
Index: src/tests/multiDimension.c
===================================================================
--- src/tests/multiDimension.c	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
+++ src/tests/multiDimension.c	(revision 71a3593146d24665b26d962ad83af645b8cb9505)
@@ -0,0 +1,72 @@
+struct X {
+  int a;
+  int * ptr;
+};
+
+void ?{}(X * this) {
+  printf("default constructing\n");
+  (&this->a){ 123 };
+  this->ptr = malloc(sizeof(int));
+}
+
+void ?{}(X * this, X other) {
+  printf("copy constructing\n");
+  (&this->a){ other.a };
+  this->ptr = malloc(sizeof(int));
+}
+
+void ?{}(X * this, int a) {
+  printf("constructing with %d\n", a);
+  (&this->a){ a };
+  this->ptr = malloc(sizeof(int));
+}
+
+void ^?{}(X * this) {
+  printf("destructing\n");
+  free(this->ptr);
+}
+
+X ?=?(X * this, X other) {
+  this->a = other.a;
+  return *this;
+}
+
+X global[10][10] = {
+  { 1, { 2 }, { 3 }, { 4 }, 5, 6, 7, 8, 9, 10, 11, 12 },
+  { 1, 2, 3, 4 },
+  { { 1234567 } }
+};
+
+X global2[3][3][3] = {
+  {
+    { 1, 2, 3 },
+    { 4, 5, 6 },
+    { 7, 8, 9 },
+    { 10, 11, 12 }
+  },
+  {
+    { 0, 0, 0 }
+  }
+};
+
+int foo() {
+  static X abc[3][3] = {
+    { 11, 22, 33, 44 },
+    { 55, 66 },
+    { 77 },
+    { 88, 99, 1010 }
+  };
+}
+
+int main() {
+  X abc[4][4] = {
+    { 999, 1111 },
+    { 1, 2, 3, 4, 5 },
+    {},
+    { 0 },
+    { 88 }
+  };
+
+  foo();
+  foo();
+}
