Index: src/InitTweak/RemoveInit.cc
===================================================================
--- src/InitTweak/RemoveInit.cc	(revision a56767c553787fe4920170c20ffd7e869a093d76)
+++ src/InitTweak/RemoveInit.cc	(revision 02c7d048c23eb98f2aef98ff111715a540cfb3fe)
@@ -10,6 +10,6 @@
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Rob Schluntz
-// Last Modified On : Mon Jan 11 14:41:26 2016
-// Update Count     : 118
+// Last Modified On : Mon Jan 11 16:10:45 2016
+// Update Count     : 150
 //
 
@@ -32,4 +32,11 @@
 	class RemoveInit : public GenPoly::PolyMutator {
 	  public:
+		/// removes and replaces initialization for polymorphic value objects
+		/// with assignment (TODO: constructor) statements.
+		/// also consistently allocates a temporary variable for the return value
+		/// of a function so that anything which the resolver decides can be assigned
+		/// into the return type of a function can be returned.
+		static void removeInitializers( std::list< Declaration * > &translationUnit );
+
 		RemoveInit();
 		virtual ObjectDecl * mutate( ObjectDecl *objDecl );
@@ -46,13 +53,22 @@
 	class CtorDtor : public GenPoly::PolyMutator {
 	  public:
-		// CtorDtor();
+		/// 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
+		static void generateCtorDtor( std::list< Declaration * > &translationUnit );
 
 		virtual ObjectDecl * 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( ContextDecl *aggregateDecl );
+		virtual TypeDecl* mutate( TypeDecl *typeDecl );
+		virtual Declaration* mutate( TypedefDecl *typeDecl );
 
 		virtual CompoundStmt * mutate( CompoundStmt * compoundStmt );
 
 	  protected:
-		typedef std::map< std::string, DeclarationWithType * > MMMMAP;
-		std::stack< MMMMAP > constructedObjects;
 
 		// to be added before block ends - use push_front so order is correct
@@ -60,9 +76,12 @@
 	};
 
-	void tweak( std::list< Declaration * > translationUnit ) {
+	void tweak( std::list< Declaration * > & translationUnit ) {
+		RemoveInit::removeInitializers( translationUnit );
+		CtorDtor::generateCtorDtor( translationUnit );
+	}
+
+	void RemoveInit::removeInitializers( std::list< Declaration * > & translationUnit ) {
 		RemoveInit remover;
-		CtorDtor ctordtor;
 		mutateAll( translationUnit, remover );
-		mutateAll( translationUnit, ctordtor );
 	}
 
@@ -115,52 +134,50 @@
 	}
 
-	bool tryConstruct( ObjectDecl * objDecl ) {
-		// xxx - handle designations
-		return objDecl->get_init() == NULL ||
-			( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() );
-	}
-
-	ExprStmt * makeCtorDtorStmt( std::string name, ObjectDecl * objDecl, std::list< Expression * > args ) {
-		UntypedExpr * expr = new UntypedExpr( new NameExpr( name ) );
-		expr->get_args().push_back( new VariableExpr( objDecl ) );
-		expr->get_args().splice( expr->get_args().end(), args );
-		return new ExprStmt( noLabels, expr );
-	}
-
-	// InitExpander ctor/dtor being marked as weak symbols
-	// this is causing a bug - Rodolfo's InitExpander is being constructed and destructed
-	// with different fields, which causes a segfault
-
-	class InitExpander : public Visitor {
-	  public:
-	  InitExpander() {}
-	  // ~InitExpander() {}
-		virtual void visit( SingleInit * singleInit );
-		virtual void visit( ListInit * listInit );
-		std::list< Expression * > argList;
-	};
-
-	void InitExpander::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 ) {
-			(*it)->accept( *this );
-		}
-	}
-
-	std::list< Expression * > makeInitList( Initializer * init ) {
-		if ( init ) {
+
+	void CtorDtor::generateCtorDtor( std::list< Declaration * > & translationUnit ) {
+		CtorDtor ctordtor;
+		mutateAll( translationUnit, ctordtor );
+	}
+
+	namespace {
+		bool tryConstruct( ObjectDecl * objDecl ) {
+			// xxx - handle designations
+			return ! LinkageSpec::isBuiltin( objDecl->get_linkage() ) &&
+	 			(objDecl->get_init() == NULL ||
+				( objDecl->get_init() != NULL && objDecl->get_init()->get_maybeConstructed() ));
+		}
+
+		ExprStmt * makeCtorDtorStmt( 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 new ExprStmt( noLabels, expr );
+		}
+
+		class InitExpander : public Visitor {
+		  public:
+		  InitExpander() {}
+		  // ~InitExpander() {}
+			virtual void visit( SingleInit * singleInit );
+			virtual void visit( ListInit * listInit );
+			std::list< Expression * > argList;
+		};
+
+		void InitExpander::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 ) {
+				(*it)->accept( *this );
+			}
+		}
+
+		std::list< Expression * > makeInitList( Initializer * init ) {
 			InitExpander expander;
-			// init->accept( expander );
-			// std::list< Expression * > l = expander.argList;
-			std::list< Expression * > l;
-			return l;
-		} else {
-			std::list< Expression * > l;
-			return l;
+			maybeAccept( init, expander );
+			return expander.argList;
 		}
 	}
@@ -179,4 +196,11 @@
 		}
 		return objDecl;
+	}
+
+	DeclarationWithType * CtorDtor::mutate( FunctionDecl *functionDecl ) {
+		// parameters should not be constructed and destructed, so don't mutate FunctionType
+		mutateAll( functionDecl->get_oldDecls(), *this );
+		functionDecl->set_statements( maybeMutate( functionDecl->get_statements(), *this ) );
+		return functionDecl;
 	}
 
@@ -190,5 +214,12 @@
 	}
 
-
+	// 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( ContextDecl *aggregateDecl ) { return aggregateDecl; }
+	TypeDecl* CtorDtor::mutate( TypeDecl *typeDecl ) { return typeDecl; }
+	Declaration* CtorDtor::mutate( TypedefDecl *typeDecl ) { return typeDecl; }
 
 } // namespace InitTweak
Index: src/InitTweak/RemoveInit.h
===================================================================
--- src/InitTweak/RemoveInit.h	(revision a56767c553787fe4920170c20ffd7e869a093d76)
+++ src/InitTweak/RemoveInit.h	(revision 02c7d048c23eb98f2aef98ff111715a540cfb3fe)
@@ -5,11 +5,11 @@
 // file "LICENCE" distributed with Cforall.
 //
-// RemoveInit.h -- 
+// RemoveInit.h --
 //
 // Author           : Rodolfo G. Esteves
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Nov 27 17:00:47 2015
-// Update Count     : 2
+// Last Modified By : Rob Schluntz
+// Last Modified On : Mon Jan 11 16:02:44 2016
+// Update Count     : 3
 //
 
@@ -26,6 +26,6 @@
 namespace InitTweak {
 	/// Adds assignment statements for polymorphic type initializers
-	void tweak( std::list< Declaration * > translationUnit );
-} // namespace 
+	void tweak( std::list< Declaration * > & translationUnit );
+} // namespace
 
 #endif // GENPOLY_POLYMUTATOR_H
