Index: src/GenPoly/Lvalue.cc
===================================================================
--- src/GenPoly/Lvalue.cc	(revision 02fdb8eb4c22b14a7fc7116a96f53d73dae71205)
+++ src/GenPoly/Lvalue.cc	(revision 2c04369a0b21c0ce78ea35835ad1f3d320c8813a)
@@ -9,7 +9,7 @@
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
-// Last Modified By : Peter A. Buhr
-// Last Modified On : Fri Mar 17 09:11:18 2017
-// Update Count     : 5
+// Last Modified By : Andrew Beach
+// Last Modified On : Tue May 28 11:07:00 2019
+// Update Count     : 6
 //
 
@@ -42,23 +42,42 @@
 namespace GenPoly {
 	namespace {
-		// TODO: fold this into the general createDeref function??
-		Expression * mkDeref( Expression * arg ) {
-			if ( SymTab::dereferenceOperator ) {
-				// note: reference depth can be arbitrarily deep here, so peel off the outermost pointer/reference, not just pointer because they are effecitvely equivalent in this pass
-				VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator );
-				deref->result = new PointerType( Type::Qualifiers(), deref->result );
-				Type * base = InitTweak::getPointerBase( arg->result );
-				assertf( base, "expected pointer type in dereference (type was %s)", toString( arg->result ).c_str() );
-				ApplicationExpr * ret = new ApplicationExpr( deref, { arg } );
-				delete ret->result;
-				ret->result = base->clone();
-				ret->result->set_lvalue( true );
-				return ret;
-			} else {
-				return UntypedExpr::createDeref( arg );
-			}
-		}
-
-		struct ReferenceConversions final : public WithStmtsToAdd {
+		/// Local helper for pass visitors that need to add reference operations.
+		struct WithDerefOp {
+			FunctionDecl * dereferenceOperator = nullptr;
+
+			// TODO: fold this into the general createDeref function??
+			Expression * mkDeref( Expression * arg ) {
+				if ( dereferenceOperator ) {
+					// note: reference depth can be arbitrarily deep here, so peel off the
+					// outermost pointer/reference, not just pointer because they are effecitvely
+					// equivalent in this pass
+					VariableExpr * deref = new VariableExpr( dereferenceOperator );
+					deref->result = new PointerType( Type::Qualifiers(), deref->result );
+					Type * base = InitTweak::getPointerBase( arg->result );
+					assertf( base, "expected pointer type in dereference (type was %s)",
+						toString( arg->result ).c_str() );
+					ApplicationExpr * ret = new ApplicationExpr( deref, { arg } );
+					delete ret->result;
+					ret->result = base->clone();
+					ret->result->set_lvalue( true );
+					return ret;
+				} else {
+					return UntypedExpr::createDeref( arg );
+				}
+			}
+
+			void previsit( FunctionDecl * funcDecl ) {
+				if ( dereferenceOperator ) return;
+				if ( funcDecl->get_name() != "*?" ) return;
+				if ( funcDecl->get_linkage() == LinkageSpec::Intrinsic ) return;
+				FunctionType * ftype = funcDecl->get_functionType();
+				if ( ftype->get_parameters().size() != 1 ) return;
+				DeclarationWithType * arg0 = ftype->get_parameters().front();
+				if ( arg0->get_type()->get_qualifiers() == Type::Qualifiers() ) return;
+				dereferenceOperator = funcDecl;
+			}
+		};
+
+		struct ReferenceConversions final : public WithStmtsToAdd, public WithDerefOp {
 			Expression * postmutate( CastExpr * castExpr );
 			Expression * postmutate( AddressExpr * addrExpr );
@@ -66,5 +85,5 @@
 
 		/// Intrinsic functions that take reference parameters don't REALLY take reference parameters -- their reference arguments must always be implicitly dereferenced.
-		struct FixIntrinsicArgs final {
+		struct FixIntrinsicArgs final : public WithDerefOp {
 			Expression * postmutate( ApplicationExpr * appExpr );
 		};
@@ -98,5 +117,6 @@
 		};
 
-		struct AddrRef final : public WithGuards, public WithVisitorRef<AddrRef>, public WithShortCircuiting {
+		struct AddrRef final : public WithGuards, public WithVisitorRef<AddrRef>,
+				public WithShortCircuiting, public WithDerefOp {
 			void premutate( AddressExpr * addrExpr );
 			Expression * postmutate( AddressExpr * addrExpr );
