The Volvo S40 and Mazda3 share about 40 percent of a small-car platform engineered jointly by Mazda, Ford and Volvo. (Ford owns Volvo and has a controlling interest in Mazda.) A version of the same platform is also used for the Volvo V50 wagon.
Ford has been trying to "rationalize" its vehicle platforms around the world so that different brands, such as Mazda and Volvo, aren't needlessly creating separate platforms for essentially similar vehicles.