Index: src/AST/Pass.hpp
===================================================================
--- src/AST/Pass.hpp	(revision 3606fe4fcb57ddc626e19a892c71e8e351bda641)
+++ src/AST/Pass.hpp	(revision a9762dce275b7241171979d7d5528dc795b1f283)
@@ -327,4 +327,8 @@
 struct PureVisitor {};
 
+struct WithCodeLocation {
+	const CodeLocation * location = nullptr;
+};
+
 /// Keep track of the polymorphic const TypeSubstitution * typeSubs for the current expression.
 struct WithConstTypeSubstitution {
Index: src/AST/Pass.impl.hpp
===================================================================
--- src/AST/Pass.impl.hpp	(revision 3606fe4fcb57ddc626e19a892c71e8e351bda641)
+++ src/AST/Pass.impl.hpp	(revision a9762dce275b7241171979d7d5528dc795b1f283)
@@ -25,4 +25,6 @@
 #define VISIT_START( node ) \
 	using namespace ast; \
+	/* back-up the last known code location */ \
+	__attribute__((unused)) auto loc_guard = ast::__pass::make_location_guard( core, node ); \
 	/* back-up the visit children */ \
 	__attribute__((unused)) ast::__pass::visit_children_guard guard1( ast::__pass::visit_children(core, 0) ); \
Index: src/AST/Pass.proto.hpp
===================================================================
--- src/AST/Pass.proto.hpp	(revision 3606fe4fcb57ddc626e19a892c71e8e351bda641)
+++ src/AST/Pass.proto.hpp	(revision a9762dce275b7241171979d7d5528dc795b1f283)
@@ -295,4 +295,5 @@
 	FIELD_PTR( at_cleanup, __pass::at_cleanup_t )
 	FIELD_PTR( visitor, ast::Pass<core_t> * const )
+	FIELD_PTR( location, const CodeLocation * )
 
 	// Remove the macro to make sure we don't clash
@@ -324,4 +325,18 @@
 	static auto on_error (core_t & core, ptr<Decl> & decl, int) -> decltype(core.on_error(decl)) {
 		return core.on_error(decl);
+	}
+
+	template< typename core_t, typename node_t >
+	static auto make_location_guard(core_t & core, node_t * node) -> ValueGuardPtr<const CodeLocation *> {
+		if constexpr (std::is_base_of<ParseNode, node_t>::value) {
+			const CodeLocation ** p = location(core, 0);
+			if(p) {
+				ValueGuardPtr<const CodeLocation *> g = { p };
+				*p = &node->location;
+				return g;
+			}
+		}
+		(void)node;
+		return { nullptr };
 	}
 
