Index: src/InitTweak/FixInit.cc
===================================================================
--- src/InitTweak/FixInit.cc	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/InitTweak/FixInit.cc	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -54,4 +54,5 @@
 #include "SynTree/Type.h"              // for Type, Type::StorageClasses
 #include "SynTree/TypeSubstitution.h"  // for TypeSubstitution, operator<<
+#include "SynTree/VarExprReplacer.h"   // for VarExprReplacer
 #include "SynTree/Visitor.h"           // for acceptAll, maybeAccept
 
@@ -158,10 +159,6 @@
 			using Parent::previsit;
 
-			void previsit( ObjectDecl * objDecl );
 			void previsit( FunctionDecl * funcDecl );
 
-			void previsit( CompoundStmt * compoundStmt );
-			void postvisit( CompoundStmt * compoundStmt );
-			void previsit( ReturnStmt * returnStmt );
 			void previsit( BranchStmt * stmt );
 		private:
@@ -203,4 +200,6 @@
 			static void generate( std::list< Declaration * > & translationUnit );
 
+			void previsit( StructDecl * structDecl );
+
 			void previsit( FunctionDecl * funcDecl );
 			void postvisit( FunctionDecl * funcDecl );
@@ -220,4 +219,8 @@
 			bool isCtor = false; // true if current function is a constructor
 			StructDecl * structDecl = nullptr;
+
+			// special built-in functions necessary for this to work
+			StructDecl * dtorStruct = nullptr;
+			FunctionDecl * dtorStructDestroy = nullptr;
 		};
 
@@ -650,4 +653,33 @@
 		}
 
+		DeclarationWithType * getDtorFunc( ObjectDecl * objDecl, Statement * dtor, std::list< Statement * > & stmtsToAdd ) {
+			if ( dynamic_cast< ExprStmt * >( dtor ) ) {
+				if ( DeclarationWithType * func = getFunction( getCtorDtorCall( dtor ) ) ) {
+					// cleanup argument must be a function, not an object (including function pointer)
+					if ( FunctionDecl * dtorFunc = dynamic_cast< FunctionDecl * > ( func ) ) {
+						if ( dtorFunc->type->forall.empty() ) {
+							// simple case where the destructor is a monomorphic function call - can simply
+							// use that function as the cleanup function.
+							delete dtor;
+							return func;
+						}
+					}
+				}
+			}
+
+			// otherwise the cleanup is more complicated - need to build a single argument cleanup function that
+			// wraps the more complicated code.
+			static UniqueName dtorNamer( "__cleanup_dtor" );
+			FunctionDecl * dtorFunc = FunctionDecl::newFunction( dtorNamer.newName(), SymTab::genDefaultType( objDecl->type->stripReferences(), false ), new CompoundStmt( noLabels ) );
+			stmtsToAdd.push_back( new DeclStmt( noLabels, dtorFunc ) );
+
+			// the original code contains uses of objDecl - replace them with the newly generated 'this' parameter.
+			ObjectDecl * thisParam = getParamThis( dtorFunc->type );
+			VarExprReplacer::replace( dtor, { std::make_pair( objDecl, thisParam ) } );
+			dtorFunc->statements->push_back( dtor );
+
+			return dtorFunc;
+		}
+
 		DeclarationWithType * FixInit::postmutate( ObjectDecl *objDecl ) {
 			// since this removes the init field from objDecl, it must occur after children are mutated (i.e. postmutate)
@@ -762,4 +794,19 @@
 							ctorInit->ctor = nullptr;
 						}
+
+						Statement * dtor = ctorInit->dtor;
+						if ( dtor ) {
+							ImplicitCtorDtorStmt * implicit = strict_dynamic_cast< ImplicitCtorDtorStmt * >( dtor );
+							Statement * dtorStmt = implicit->callStmt;
+							// don't need to call intrinsic dtor, because it does nothing, but
+							// non-intrinsic dtors must be called
+							if ( ! isIntrinsicSingleArgCallStmt( dtorStmt ) ) {
+								// set dtor location to the object's location for error messages
+								DeclarationWithType * dtorFunc = getDtorFunc( objDecl, dtorStmt, stmtsToAddBefore );
+								objDecl->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorFunc ) } ) );
+								// objDecl->attributes.push_back( new Attribute( "cleanup", { new NameExpr( dtorFunc->name ) } ) );
+								ctorInit->dtor = nullptr;
+							} // if
+						}
 					} // if
 				} else if ( Initializer * init = ctorInit->init ) {
@@ -804,36 +851,4 @@
 
 
-		template<typename Iterator, typename OutputIterator>
-		void insertDtors( Iterator begin, Iterator end, OutputIterator out ) {
-			for ( Iterator it = begin ; it != end ; ++it ) {
-				// extract destructor statement from the object decl and insert it into the output. Note that this is
-				// only called on lists of non-static objects with implicit non-intrinsic dtors, so if the user manually
-				// calls an intrinsic dtor then the call must (and will) still be generated since the argument may
-				// contain side effects.
-				ObjectDecl * objDecl = *it;
-				ConstructorInit * ctorInit = dynamic_cast< ConstructorInit * >( objDecl->get_init() );
-				assert( ctorInit && ctorInit->get_dtor() );
-				*out++ = ctorInit->get_dtor()->clone();
-			} // for
-		}
-
-		void InsertDtors::previsit( ObjectDecl * objDecl ) {
-			// remember non-static destructed objects so that their destructors can be inserted later
-			if ( ! objDecl->get_storageClasses().is_static ) {
-				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() );
-					Statement * dtor = ctorInit->get_dtor();
-					// don't need to call intrinsic dtor, because it does nothing, but
-					// non-intrinsic dtors must be called
-					if ( dtor && ! isIntrinsicSingleArgCallStmt( dtor ) ) {
-						// set dtor location to the object's location for error messages
-						ctorInit->dtor->location = objDecl->location;
-						reverseDeclOrder.front().push_front( objDecl );
-					} // if
-				} // if
-			} // if
-		}
-
 		void InsertDtors::previsit( FunctionDecl * funcDecl ) {
 			// each function needs to have its own set of labels
@@ -848,29 +863,4 @@
 		}
 
-		void InsertDtors::previsit( CompoundStmt * compoundStmt ) {
-			// visit statements - this will also populate reverseDeclOrder list.  don't want to dump all destructors
-			// when block is left, just the destructors associated with variables defined in this block, so push a new
-			// list to the top of the stack so that we can differentiate scopes
-			reverseDeclOrder.push_front( OrderedDecls() );
-			Parent::previsit( compoundStmt );
-		}
-
-		void InsertDtors::postvisit( CompoundStmt * compoundStmt ) {
-			// add destructors for the current scope that we're exiting, unless the last statement is a return, which
-			// causes unreachable code warnings
-			std::list< Statement * > & statements = compoundStmt->get_kids();
-			if ( ! statements.empty() && ! dynamic_cast< ReturnStmt * >( statements.back() ) ) {
-				insertDtors( reverseDeclOrder.front().begin(), reverseDeclOrder.front().end(), back_inserter( statements ) );
-			}
-			reverseDeclOrder.pop_front();
-		}
-
-		void InsertDtors::previsit( ReturnStmt * ) {
-			// return exits all scopes, so dump destructors for all scopes
-			for ( OrderedDecls & od : reverseDeclOrder ) {
-				insertDtors( od.begin(), od.end(), back_inserter( stmtsToAddBefore ) );
-			} // for
-		}
-
 		// Handle break/continue/goto in the same manner as C++.  Basic idea: any objects that are in scope at the
 		// BranchStmt but not at the labelled (target) statement must be destructed.  If there are any objects in scope
@@ -900,22 +890,4 @@
 			if ( ! diff.empty() ) {
 				throw SemanticError( std::string("jump to label '") + stmt->get_target().get_name() + "' crosses initialization of " + (*diff.begin())->get_name() + " ", stmt );
-			} // if
-			// S_G-S_L results in set of objects that must be destructed
-			diff.clear();
-			std::set_difference( curVars.begin(), curVars.end(), lvars.begin(), lvars.end(), std::inserter( diff, diff.end() ) );
-			DTOR_PRINT(
-				std::cerr << "S_G-S_L = " << printSet( diff ) << std::endl;
-			)
-			if ( ! diff.empty() ) {
-				// create an auxilliary set for fast lookup -- can't make diff a set, because diff ordering should be consistent for error messages.
-				std::unordered_set<ObjectDecl *> needsDestructor( diff.begin(), diff.end() );
-
-				// go through decl ordered list of objectdecl. for each element that occurs in diff, output destructor
-				OrderedDecls ordered;
-				for ( OrderedDecls & rdo : reverseDeclOrder ) {
-					// add elements from reverseDeclOrder into ordered if they occur in diff - it is key that this happens in reverse declaration order.
-					copy_if( rdo.begin(), rdo.end(), back_inserter( ordered ), [&]( ObjectDecl * objDecl ) { return needsDestructor.count( objDecl ); } );
-				} // for
-				insertDtors( ordered.begin(), ordered.end(), back_inserter( stmtsToAddBefore ) );
 			} // if
 		}
@@ -956,4 +928,10 @@
 		}
 
+		void GenStructMemberCalls::previsit( StructDecl * structDecl ) {
+			if ( ! dtorStruct && structDecl->name == "__Destructor" ) {
+				dtorStruct = structDecl;
+			}
+		}
+
 		void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
 			GuardValue( function );
@@ -968,4 +946,9 @@
 			unhandled.clear();
 			usedUninit.clear();
+
+			if ( ! dtorStructDestroy && funcDecl->name == "__destroy_Destructor" ) {
+				dtorStructDestroy = funcDecl;
+				return;
+			}
 
 			function = funcDecl;
@@ -979,4 +962,5 @@
 				if ( structType ) {
 					structDecl = structType->get_baseStruct();
+					if ( structDecl == dtorStruct ) return;
 					for ( Declaration * member : structDecl->get_members() ) {
 						if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( member ) ) {
@@ -1050,8 +1034,24 @@
 							callStmt->acceptMutator( resolver );
 							if ( isCtor ) {
-								function->get_statements()->push_front( callStmt );
+								function->statements->push_front( callStmt );
 							} else {
 								// destructor statements should be added at the end
-								function->get_statements()->push_back( callStmt );
+								// function->get_statements()->push_back( callStmt );
+
+								// Destructor _dtor0 = { &b.a1, _destroy_A };
+								std::list< Statement * > stmtsToAdd;
+
+								static UniqueName memberDtorNamer = { "__memberDtor" };
+								assertf( dtorStruct, "builtin __Destructor not found." );
+								assertf( dtorStructDestroy, "builtin __destroy_Destructor not found." );
+
+								Expression * thisExpr = new AddressExpr( new VariableExpr( thisParam ) );
+								Expression * dtorExpr = new VariableExpr( getDtorFunc( thisParam, callStmt, stmtsToAdd ) );
+
+								ObjectDecl * destructor = ObjectDecl::newObject( memberDtorNamer.newName(), new StructInstType( Type::Qualifiers(), dtorStruct ), new ListInit( { new SingleInit( thisExpr ), new SingleInit( dtorExpr ) } ) );
+								function->statements->push_front( new DeclStmt( noLabels, destructor ) );
+								destructor->attributes.push_back( new Attribute( "cleanup", { new VariableExpr( dtorStructDestroy ) } ) );
+
+								function->statements->kids.splice( function->statements->kids.begin(), stmtsToAdd );
 							}
 						} catch ( SemanticError & error ) {
Index: src/SymTab/Autogen.cc
===================================================================
--- src/SymTab/Autogen.cc	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/SymTab/Autogen.cc	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -46,5 +46,5 @@
 	/// Data used to generate functions generically. Specifically, the name of the generated function and a function which generates the routine protoype
 	struct FuncData {
-		typedef FunctionType * (*TypeGen)( Type * );
+		typedef FunctionType * (*TypeGen)( Type *, bool );
 		FuncData( const std::string & fname, const TypeGen & genType ) : fname( fname ), genType( genType ) {}
 		std::string fname;
@@ -236,8 +236,11 @@
 
 	/// given type T, generate type of default ctor/dtor, i.e. function type void (*) (T *)
-	FunctionType * genDefaultType( Type * paramType ) {
-		const auto & typeParams = getGenericParams( paramType );
+	FunctionType * genDefaultType( Type * paramType, bool maybePolymorphic ) {
 		FunctionType *ftype = new FunctionType( Type::Qualifiers(), false );
-		cloneAll( typeParams, ftype->forall );
+		if ( maybePolymorphic ) {
+			// only copy in
+			const auto & typeParams = getGenericParams( paramType );
+			cloneAll( typeParams, ftype->forall );
+		}
 		ObjectDecl *dstParam = new ObjectDecl( "_dst", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, new ReferenceType( Type::Qualifiers(), paramType->clone() ), nullptr );
 		ftype->parameters.push_back( dstParam );
@@ -246,6 +249,6 @@
 
 	/// given type T, generate type of copy ctor, i.e. function type void (*) (T *, T)
-	FunctionType * genCopyType( Type * paramType ) {
-		FunctionType *ftype = genDefaultType( paramType );
+	FunctionType * genCopyType( Type * paramType, bool maybePolymorphic ) {
+		FunctionType *ftype = genDefaultType( paramType, maybePolymorphic );
 		ObjectDecl *srcParam = new ObjectDecl( "_src", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr );
 		ftype->parameters.push_back( srcParam );
@@ -254,6 +257,6 @@
 
 	/// given type T, generate type of assignment, i.e. function type T (*) (T *, T)
-	FunctionType * genAssignType( Type * paramType ) {
-		FunctionType *ftype = genCopyType( paramType );
+	FunctionType * genAssignType( Type * paramType, bool maybePolymorphic ) {
+		FunctionType *ftype = genCopyType( paramType, maybePolymorphic );
 		ObjectDecl *returnVal = new ObjectDecl( "_ret", Type::StorageClasses(), LinkageSpec::Cforall, nullptr, paramType->clone(), nullptr );
 		ftype->returnVals.push_back( returnVal );
@@ -313,5 +316,5 @@
 		for ( const FuncData & d : data ) {
 			// generate a function (?{}, ?=?, ^?{}) based on the current FuncData.
-			FunctionType * ftype = d.genType( type );
+			FunctionType * ftype = d.genType( type, true );
 
 			// destructor for concurrent type must be mutex
Index: src/SymTab/Autogen.h
===================================================================
--- src/SymTab/Autogen.h	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/SymTab/Autogen.h	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -45,12 +45,15 @@
 	extern FunctionDecl * dereferenceOperator;
 
-	// generate the type of an assignment function for paramType
-	FunctionType * genAssignType( Type * paramType );
-
-	// generate the type of a default constructor or destructor for paramType
-	FunctionType * genDefaultType( Type * paramType );
-
-	// generate the type of a copy constructor for paramType
-	FunctionType * genCopyType( Type * paramType );
+	/// generate the type of an assignment function for paramType.
+	/// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
+	FunctionType * genAssignType( Type * paramType, bool maybePolymorphic = true );
+
+	/// generate the type of a default constructor or destructor for paramType.
+	/// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
+	FunctionType * genDefaultType( Type * paramType, bool maybePolymorphic = true );
+
+	/// generate the type of a copy constructor for paramType.
+	/// maybePolymorphic is true if the resulting FunctionType is allowed to be polymorphic
+	FunctionType * genCopyType( Type * paramType, bool maybePolymorphic = true );
 
 	/// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
Index: src/SynTree/Mutator.h
===================================================================
--- src/SynTree/Mutator.h	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/SynTree/Mutator.h	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -119,4 +119,5 @@
 
 	virtual TypeSubstitution * mutate( TypeSubstitution * sub );
+
   private:
 	virtual Declaration * handleAggregateDecl(AggregateDecl * aggregateDecl );
Index: src/prelude/builtins.c
===================================================================
--- src/prelude/builtins.c	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/prelude/builtins.c	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -91,4 +91,25 @@
 static inline unsigned int ?\=?( unsigned int & x, unsigned long int y ) { x = x \ y; return x; }
 
+// type that wraps a pointer and a destructor-like function - used in generating implicit destructor calls for struct members in user-defined functions
+forall(dtype T)
+struct __Destructor {
+  T * object;
+  void (*dtor)(T *);
+};
+
+// defined destructor in the case that non-generated code wants to use __Destructor
+forall(dtype T)
+static inline void ^?{}(__Destructor(T) & x) {
+  x.dtor(x.object);
+}
+
+// easy interface into __Destructor's destructor for easy codegen purposes
+extern "C" {
+  forall(dtype T)
+  static inline void __destroy_Destructor(__Destructor(T) * dtor) {
+    ^(*dtor){};
+  }
+}
+
 // Local Variables: //
 // mode: c //
Index: src/tests/.expect/memberCtors-ERR1.txt
===================================================================
--- src/tests/.expect/memberCtors-ERR1.txt	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/tests/.expect/memberCtors-ERR1.txt	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -1,1 +1,1 @@
-memberCtors.c:71:1 error: in void ?{}(B &b), field a2 used before being constructed
+memberCtors.c:78:1 error: in void ?{}(B &b), field a2 used before being constructed
Index: src/tests/.expect/memberCtors.txt
===================================================================
--- src/tests/.expect/memberCtors.txt	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/tests/.expect/memberCtors.txt	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -98,4 +98,5 @@
 end copy construct A
 End of main
+begin destruct B
 constructing int
 constructing int
@@ -146,13 +147,15 @@
 destructing int: 0
 destructing int: 1000
-destructing int: 0
-destructing int: 0
-destructing int: 999
-destructing int: 0
-destructing int: 0
-destructing int: 0
-destructing int: 0
-destructing int: 0
-destructing int: 999
+end destruct B
+destructing int: 0
+destructing int: 0
+destructing int: 999
+destructing int: 0
+destructing int: 0
+destructing int: 0
+destructing int: 0
+destructing int: 0
+destructing int: 999
+begin destruct B
 constructing int
 constructing int
@@ -203,11 +206,12 @@
 destructing int: 0
 destructing int: 1000
-destructing int: 0
-destructing int: 0
-destructing int: 999
-destructing int: 0
-destructing int: 0
-destructing int: 0
-destructing int: 0
-destructing int: 0
-destructing int: 999
+end destruct B
+destructing int: 0
+destructing int: 0
+destructing int: 999
+destructing int: 0
+destructing int: 0
+destructing int: 0
+destructing int: 0
+destructing int: 0
+destructing int: 999
Index: src/tests/memberCtors.c
===================================================================
--- src/tests/memberCtors.c	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/tests/memberCtors.c	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -22,8 +22,15 @@
 }
 
-void ?=?(WrappedInt & this, int x) {
+/* WrappedInt */ void ?=?(WrappedInt & this, int x) {
   printf("assigning int: %d %d\n", this.x, x);
   this.x = x;
+  // return this;
 }
+
+// WrappedInt ?=?(WrappedInt & this, WrappedInt other) {
+//   printf("assigning int: %d %d\n", this.x, other.x);
+//   this.x = other.x;
+//   return this;
+// }
 
 struct A {
@@ -79,11 +86,13 @@
 
 void ^?{}(B & b) {
+  printf("begin destruct B\n");
   b.a2 = (A) { 0 };
   ^(b.a1){};
+  printf("end destruct B\n");
 } // a2, a3 never destructed - will be automatically destructed
 
 int main() {
   printf("Before declaration of b1\n");
-  B b1;
+  B b1;  // b1 = { { 1000, 0, 0 }, { 1001, 0, 0 }, { 0, 0, 0 } }
   printf("Before declaration of b2\n");
   B b2 = b1;
Index: src/tests/multiDimension.c
===================================================================
--- src/tests/multiDimension.c	(revision e35f30aa1a6d9c1e9ec668432b5671719a8b5882)
+++ src/tests/multiDimension.c	(revision 4ee36bf0680fbfd721631faa08c4418325dde9d5)
@@ -32,44 +32,46 @@
 }
 
-X global[10][10] = {
-  { 1, { 2 }, { 3 }, { 4 }, 5, 6, 7, 8, 9, 10, 11, 12 },
-  { 1, 2, 3, 4 },
-  { { 1234567 } }
-};
+// 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 }
-  }
-};
+// 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 foo() {
+//   static X abc[3][3] = {
+//     { 11, 22, 33, 44 },
+//     { 55, 66 },
+//     { 77 },
+//     { 88, 99, 1010 }
+//   };
+// }
 
 // ensure constructed const arrays continue to compile
-const int global[1] = { -2 };
+// const int global[1] = { -2 };
 
 int main() {
-  X abc[4][4] = {
-    { 999, 1111 },
-    { 1, 2, 3, 4, 5 },
-    {},
-    { 0 },
-    { 88 }
-  };
+  X a;
+  X abc[2];
+  // X abc[4]/*[4]*/ = {
+  //   /*{*/ 999, 1111 /*}*/,
+  //   // { 1, 2, 3, 4, 5 },
+  //   // {},
+  //   // { 0 },
+  //   // { 88 }
+  // };
 
-  foo();
-  foo();
+  // foo();
+  // foo();
 }
