Index: src/SymTab/Autogen.cc
===================================================================
--- src/SymTab/Autogen.cc	(revision 242d4587f77845aedb54424e5c82b19ce6fc14ab)
+++ src/SymTab/Autogen.cc	(revision a465caff623c39b44749b156091c82701114e584)
@@ -68,5 +68,5 @@
 		copy->get_args().push_back( new VariableExpr( dstParam ) );
 		copy->get_args().push_back( new AddressExpr( new VariableExpr( srcParam ) ) );
-		copy->get_args().push_back( new SizeofExpr( unionType ) );
+		copy->get_args().push_back( new SizeofExpr( srcParam->get_type()->clone() ) );
 
 		*out++ = new ExprStmt( noLabels, copy );
@@ -421,9 +421,29 @@
 		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 ) ) );
+		else assignDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) );
 
 		// body of assignment and copy ctor is the same
 		copyCtorDecl->set_statements( assignDecl->get_statements()->clone() );
+
+		// create a constructor which takes the first member type as a parameter.
+		// for example, for Union A { int x; double y; }; generate
+		// void ?{}(A *, int)
+		// This is to mimic C's behaviour which initializes the first member of the union.
+		std::list<Declaration *> memCtors;
+		for ( Declaration * member : aggregateDecl->get_members() ) {
+			if ( DeclarationWithType * field = dynamic_cast< DeclarationWithType * >( member ) ) {
+				ObjectDecl * srcParam = new ObjectDecl( "src", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, field->get_type()->clone(), 0 );
+
+				FunctionType * memCtorType = ctorType->clone();
+				memCtorType->get_parameters().push_back( srcParam );
+				FunctionDecl * ctor = new FunctionDecl( "?{}", functionNesting > 0 ? DeclarationNode::NoStorageClass : DeclarationNode::Static, LinkageSpec::AutoGen, memCtorType, new CompoundStmt( noLabels ), true, false );
+				ctor->fixUniqueId();
+
+				makeUnionFieldsAssignment( srcParam, dstParam, cloneWithParams( refType, unionParams ), back_inserter( ctor->get_statements()->get_kids() ) );
+				memCtors.push_back( ctor );
+				// only generate a ctor for the first field
+				break;
+			}
+		}
 
 		declsToAdd.push_back( assignDecl );
@@ -431,4 +451,5 @@
 		declsToAdd.push_back( copyCtorDecl );
 		declsToAdd.push_back( dtorDecl );
+		declsToAdd.splice( declsToAdd.end(), memCtors );
 	}
 
