Index: src/GenPoly/Specialize.cc
===================================================================
--- src/GenPoly/Specialize.cc	(revision c6c682cfa1a2b3a58b9c8cde325953a89154db7a)
+++ src/GenPoly/Specialize.cc	(revision 3100754a66119592e773d53876efbcdb4e3e70f8)
@@ -218,4 +218,8 @@
 		thunkFunc->get_attributes().push_back( new Attribute( "unused" ) );
 
+		// Thunks at the global level must be static to avoid collisions between files.
+		// (Conversly thunks inside a function must be unique and not static.)
+		thunkFunc->storageClasses.is_static = !isInFunction();
+
 		// thread thunk parameters into call to actual function, naming thunk parameters as we go
 		UniqueName paramNamer( paramPrefix );
@@ -321,21 +325,7 @@
 	}
 
-	// Fold it into Specialize if we find a good way.
-	struct StaticThunks final : public WithShortCircuiting {
-		void previsit( Declaration * ) {
-			visit_children = false;
-		}
-		void postvisit( FunctionDecl * decl ) {
-			if ( isPrefix( decl->name, "_thunk" ) ) {
-				decl->storageClasses.is_static = true;
-			}
-		}
-	};
-
 	void convertSpecializations( std::list< Declaration* >& translationUnit ) {
 		PassVisitor<Specialize> spec;
 		mutateAll( translationUnit, spec );
-		PassVisitor<StaticThunks> staticThunks;
-		acceptAll( translationUnit, staticThunks );
 	}
 } // namespace GenPoly
