Index: src/GenPoly/Lvalue.cc
===================================================================
--- src/GenPoly/Lvalue.cc	(revision 8a6cf7efc5b53b47e66ba1a8f429bb5b7c181aa2)
+++ src/GenPoly/Lvalue.cc	(revision b0440b732d17cea05c65a11feb548d684a9ff930)
@@ -94,4 +94,10 @@
 	} // namespace
 
+	static bool referencesEliminated = false;
+	// used by UntypedExpr::createDeref to determine whether result type of dereference should be ReferenceType or value type.
+	bool referencesPermissable() {
+		return ! referencesEliminated;
+	}
+
 	void convertLvalue( std::list< Declaration* >& translationUnit ) {
 		std::cerr << "convertLvalue" << std::endl;
@@ -106,4 +112,7 @@
 		mutateAll( translationUnit, collapser );
 		mutateAll( translationUnit, elim );  // last because other passes need reference types to work
+
+		// from this point forward, no other pass should create reference types.
+		referencesEliminated = true;
 	}
 
@@ -134,4 +143,11 @@
 				// can be of differing lengths only when function is variadic
 				assertf( ftype->get_parameters().size() == appExpr->get_args().size() || ftype->get_isVarArgs(), "ApplicationExpr args do not match formal parameter type." );
+
+				if ( isIntrinsicReference( appExpr ) ) {
+					// eliminate reference types from intrinsic applications - now they return lvalues
+					appExpr->set_result( appExpr->get_result()->stripReferences() );
+					appExpr->get_result()->set_lvalue( true );
+				}
+
 				unsigned int i = 0;
 				const unsigned int end = ftype->get_parameters().size();
@@ -252,5 +268,6 @@
 				}
 				if ( ResolvExpr::typesCompatibleIgnoreQualifiers( castExpr->get_result(), castExpr->get_arg()->get_result()->stripReferences(), SymTab::Indexer() ) ) {
-					// can remove cast if types are compatible
+					// can remove cast if types are compatible, changing expression type to value type
+					ret->set_result( castExpr->get_result()->clone() );
 					castExpr->set_arg( nullptr );
 					delete castExpr;
Index: src/GenPoly/Lvalue.h
===================================================================
--- src/GenPoly/Lvalue.h	(revision 8a6cf7efc5b53b47e66ba1a8f429bb5b7c181aa2)
+++ src/GenPoly/Lvalue.h	(revision b0440b732d17cea05c65a11feb548d684a9ff930)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// Lvalue.h -- 
+// Lvalue.h --
 //
 // Author           : Richard C. Bilson
@@ -24,4 +24,7 @@
 	/// replaces return type of `lvalue T` with `T*`, along with appropriate address-of and dereference operators
 	void convertLvalue( std::list< Declaration* >& translationUnit );
+
+	/// true after reference types have been eliminated from the source code. After this point, reference types should not be added to the AST.
+	bool referencesPermissable();
 } // namespace GenPoly
 
