Index: src/CodeGen/FixNames.cc
===================================================================
--- src/CodeGen/FixNames.cc	(revision d958834bbaca85420da00e8a912914e2702ecacb)
+++ src/CodeGen/FixNames.cc	(revision def751fb5e94c970d065746c20eda0539c4b38ef)
@@ -5,11 +5,11 @@
 // file "LICENCE" distributed with Cforall.
 //
-// FixNames.cc --
+// FixNames.cc -- Adjustments to typed declarations.
 //
 // Author           : Richard C. Bilson
 // Created On       : Mon May 18 07:44:20 2015
 // Last Modified By : Andrew Beach
-// Last Modified On : Fri Oct 29 15:49:00 2021
-// Update Count     : 23
+// Last Modified On : Wed Jul 20 11:49:00 2022
+// Update Count     : 24
 //
 
@@ -87,5 +87,5 @@
 
 /// Does work with the main function and scopeLevels.
-class FixNames_new : public ast::WithGuards {
+class FixNames_new final {
 	int scopeLevel = 1;
 
@@ -103,14 +103,10 @@
 
 	const ast::FunctionDecl *postvisit( const ast::FunctionDecl *functionDecl ) {
-		// This store is used to ensure a maximum of one call to mutate.
-		ast::FunctionDecl * mutDecl = nullptr;
+		if ( FixMain::isMain( functionDecl ) ) {
+			auto mutDecl = ast::mutate( functionDecl );
 
-		if ( shouldSetScopeLevel( functionDecl ) ) {
-			mutDecl = ast::mutate( functionDecl );
-			mutDecl->scopeLevel = scopeLevel;
-		}
-
-		if ( FixMain::isMain( functionDecl ) ) {
-			if ( !mutDecl ) { mutDecl = ast::mutate( functionDecl ); }
+			if ( shouldSetScopeLevel( mutDecl ) ) {
+				mutDecl->scopeLevel = scopeLevel;
+			}
 
 			int nargs = mutDecl->params.size();
@@ -124,10 +120,19 @@
 				)
 			);
+
+			return mutDecl;
+		} else if ( shouldSetScopeLevel( functionDecl ) ) {
+			return ast::mutate_field( functionDecl, &ast::FunctionDecl::scopeLevel, scopeLevel );
+		} else {
+			return functionDecl;
 		}
-		return mutDecl ? mutDecl : functionDecl;
 	}
 
 	void previsit( const ast::CompoundStmt * ) {
-		GuardValue( scopeLevel ) += 1;
+		scopeLevel += 1;
+	}
+
+	void postvisit( const ast::CompoundStmt * ) {
+		scopeLevel -= 1;
 	}
 };
Index: src/CodeGen/FixNames.h
===================================================================
--- src/CodeGen/FixNames.h	(revision d958834bbaca85420da00e8a912914e2702ecacb)
+++ src/CodeGen/FixNames.h	(revision def751fb5e94c970d065746c20eda0539c4b38ef)
@@ -5,5 +5,5 @@
 // file "LICENCE" distributed with Cforall.
 //
-// FixNames.h --
+// FixNames.h -- Adjustments to typed declarations.
 //
 // Author           : Richard C. Bilson
@@ -26,5 +26,6 @@
 	/// mangles object and function names
 	void fixNames( std::list< Declaration* > & translationUnit );
-	void fixNames( ast::TranslationUnit & translationUnit );
+/// Sets scope levels and fills in main's default return.
+void fixNames( ast::TranslationUnit & translationUnit );
 } // namespace CodeGen
 
