Index: src/GenPoly/Box.cpp
===================================================================
--- src/GenPoly/Box.cpp	(revision c4570af36d5be981e5714c9d730a86bc48ac9d4a)
+++ src/GenPoly/Box.cpp	(revision dd900b564c8c9f6b67d2f5484e3ebcedce82b1ee)
@@ -40,4 +40,15 @@
 namespace {
 
+/// The layout type is used to represent sizes, alignments and offsets.
+ast::BasicType * makeLayoutType() {
+	return new ast::BasicType( ast::BasicType::LongUnsignedInt );
+}
+
+/// Fixed version of layout type (just adding a 'C' in C++ style).
+ast::BasicType * makeLayoutCType() {
+	return new ast::BasicType( ast::BasicType::LongUnsignedInt,
+		ast::CV::Qualifiers( ast::CV::Const ) );
+}
+
 // --------------------------------------------------------------------------
 /// Adds layout-generation functions to polymorphic types.
@@ -60,8 +71,4 @@
 	}
 	return sizedParams;
-}
-
-ast::BasicType * makeSizeAlignType() {
-	return new ast::BasicType( ast::BasicType::LongUnsignedInt );
 }
 
@@ -76,16 +83,16 @@
 			sizedParam->location,
 			sizeofName( paramName ),
-			makeSizeAlignType()
+			makeLayoutCType()
 		) );
 		params.emplace_back( new ast::ObjectDecl(
 			sizedParam->location,
 			alignofName( paramName ),
-			makeSizeAlignType()
+			makeLayoutCType()
 		) );
 	}
 }
 
-ast::Type * makeSizeAlignOutType() {
-	return new ast::PointerType( makeSizeAlignType() );
+ast::Type * makeLayoutOutType() {
+	return new ast::PointerType( makeLayoutType() );
 }
 
@@ -104,10 +111,10 @@
 		location,
 		sizeofName( aggr->name ),
-		makeSizeAlignOutType()
+		makeLayoutOutType()
 	);
 	ast::ObjectDecl * alignParam = new ast::ObjectDecl(
 		location,
 		alignofName( aggr->name ),
-		makeSizeAlignOutType()
+		makeLayoutOutType()
 	);
 	ast::ObjectDecl * offsetParam = nullptr;
@@ -117,5 +124,5 @@
 			location,
 			offsetofName( aggr->name ),
-			makeSizeAlignOutType()
+			makeLayoutOutType()
 		);
 		params.push_back( offsetParam );
@@ -1372,11 +1379,20 @@
 };
 
-// size/align/offset parameters may not be used, so add the unused attribute.
 ast::ObjectDecl * makeObj(
 		CodeLocation const & location, std::string const & name ) {
+	// The size/align parameters may be unused, so add the unused attribute.
 	return new ast::ObjectDecl( location, name,
-		makeSizeAlignType(),
+		makeLayoutCType(),
 		nullptr, ast::Storage::Classes(), ast::Linkage::C, nullptr,
 		{ new ast::Attribute( "unused" ) } );
+}
+
+/// A modified and specialized version of ast::add_qualifiers.
+ast::Type const * addConst( ast::Type const * type ) {
+	ast::CV::Qualifiers cvq = { ast::CV::Const };
+	if ( ( type->qualifiers & cvq ) != 0 ) return type;
+	auto mutType = ast::mutate( type );
+	mutType->qualifiers |= cvq;
+	return mutType;
 }
 
@@ -1418,9 +1434,10 @@
 	}
 	for ( ast::ptr<ast::DeclWithType> & assert : mutDecl->assertions ) {
+		ast::DeclWithType * mutAssert = ast::mutate( assert.get() );
 		// Assertion parameters may not be used in body,
 		// pass along with unused attribute.
-		assert.get_and_mutate()->attributes.push_back(
-			new ast::Attribute( "unused" ) );
-		inferredParams.push_back( assert );
+		mutAssert->attributes.push_back( new ast::Attribute( "unused" ) );
+		mutAssert->set_type( addConst( mutAssert->get_type() ) );
+		inferredParams.emplace_back( mutAssert );
 	}
 	mutDecl->assertions.clear();
@@ -1645,9 +1662,7 @@
 	ast::TypeInstType inst( decl->name, decl );
 	std::string typeName = Mangle::mangleType( &inst );
-	ast::Type * layoutType = new ast::BasicType(
-		ast::BasicType::LongUnsignedInt );
 
 	ast::ObjectDecl * sizeDecl = new ast::ObjectDecl( decl->location,
-		sizeofName( typeName ), layoutType,
+		sizeofName( typeName ), makeLayoutCType(),
 		new ast::SingleInit( decl->location,
 			new ast::SizeofExpr( decl->location, deepCopy( base ) )
@@ -1655,5 +1670,5 @@
 	);
 	ast::ObjectDecl * alignDecl = new ast::ObjectDecl( decl->location,
-		alignofName( typeName ), layoutType,
+		alignofName( typeName ), makeLayoutCType(),
 		new ast::SingleInit( decl->location,
 			new ast::AlignofExpr( decl->location, deepCopy( base ) )
@@ -1912,11 +1927,7 @@
 	knownOffsets.insert( offsetName );
 
-	auto baseMembers = type->base->members;
-	ast::Type const * offsetType = new ast::BasicType(
-		ast::BasicType::LongUnsignedInt );
-
 	// Build initializer list for offset array.
 	ast::vector<ast::Init> inits;
-	for ( ast::ptr<ast::Decl> & member : baseMembers ) {
+	for ( ast::ptr<ast::Decl> const & member : type->base->members ) {
 		auto memberDecl = member.as<ast::DeclWithType>();
 		assertf( memberDecl, "Requesting offset of non-DWT member: %s",
@@ -1932,6 +1943,6 @@
 	auto offsetArray = makeVar( expr->location, offsetName,
 		new ast::ArrayType(
-			offsetType,
-			ast::ConstantExpr::from_ulong( expr->location, baseMembers.size() ),
+			makeLayoutType(),
+			ast::ConstantExpr::from_ulong( expr->location, inits.size() ),
 			ast::FixedLen,
 			ast::DynamicDim
@@ -2012,5 +2023,4 @@
 		// parameters to the layout call.
 		knownLayouts.insert( typeName );
-		ast::Type const * layoutType = makeSizeAlignType();
 
 		int memberCount = inst->base->members.size();
@@ -2018,9 +2028,9 @@
 			// All empty structures have the same layout (size 1, align 1).
 			makeVar( location,
-				sizeofName( typeName ), layoutType,
+				sizeofName( typeName ), makeLayoutType(),
 				new ast::SingleInit( location,
 						ast::ConstantExpr::from_ulong( location, 1 ) ) );
 			makeVar( location,
-				alignofName( typeName ), ast::deepCopy( layoutType ),
+				alignofName( typeName ), makeLayoutType(),
 				new ast::SingleInit( location,
 						ast::ConstantExpr::from_ulong( location, 1 ) ) );
@@ -2028,11 +2038,11 @@
 		} else {
 			ast::ObjectDecl const * sizeofVar = makeVar( location,
-				sizeofName( typeName ), deepCopy( layoutType ), nullptr );
+				sizeofName( typeName ), makeLayoutType(), nullptr );
 			ast::ObjectDecl const * alignofVar = makeVar( location,
-				alignofName( typeName ), deepCopy( layoutType ), nullptr );
+				alignofName( typeName ), makeLayoutType(), nullptr );
 			ast::ObjectDecl const * offsetofVar = makeVar( location,
 				offsetofName( typeName ),
 				new ast::ArrayType(
-					layoutType,
+					makeLayoutType(),
 					ast::ConstantExpr::from_int( location, memberCount ),
 					ast::FixedLen,
@@ -2078,10 +2088,9 @@
 		// parameters to the layout call.
 		knownLayouts.insert( typeName );
-		ast::Type const * layoutType = makeSizeAlignType();
 
 		ast::ObjectDecl * sizeofVar = makeVar( location,
-			sizeofName( typeName ), layoutType );
+			sizeofName( typeName ), makeLayoutType() );
 		ast::ObjectDecl * alignofVar = makeVar( location,
-			alignofName( typeName ), ast::deepCopy( layoutType ) );
+			alignofName( typeName ), makeLayoutType() );
 
 		ast::UntypedExpr * layoutCall = new ast::UntypedExpr( location,
Index: tests/.expect/functions.arm64.txt
===================================================================
--- tests/.expect/functions.arm64.txt	(revision c4570af36d5be981e5714c9d730a86bc48ac9d4a)
+++ tests/.expect/functions.arm64.txt	(revision dd900b564c8c9f6b67d2f5484e3ebcedce82b1ee)
@@ -105,5 +105,5 @@
 struct _tuple2_ {
 };
-static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){
+static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, const unsigned long int _alignof_Y15tuple_param_2_1){
     ((void)((*_sizeof__tuple2_)=0));
     ((void)((*_alignof__tuple2_)=1));
@@ -136,5 +136,5 @@
 struct _tuple3_ {
 };
-static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){
+static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, const unsigned long int _alignof_Y15tuple_param_3_2){
     ((void)((*_sizeof__tuple3_)=0));
     ((void)((*_alignof__tuple3_)=1));
Index: tests/.expect/functions.x64.txt
===================================================================
--- tests/.expect/functions.x64.txt	(revision c4570af36d5be981e5714c9d730a86bc48ac9d4a)
+++ tests/.expect/functions.x64.txt	(revision dd900b564c8c9f6b67d2f5484e3ebcedce82b1ee)
@@ -105,5 +105,5 @@
 struct _tuple2_ {
 };
-static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){
+static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, const unsigned long int _alignof_Y15tuple_param_2_1){
     ((void)((*_sizeof__tuple2_)=0));
     ((void)((*_alignof__tuple2_)=1));
@@ -136,5 +136,5 @@
 struct _tuple3_ {
 };
-static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){
+static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, const unsigned long int _alignof_Y15tuple_param_3_2){
     ((void)((*_sizeof__tuple3_)=0));
     ((void)((*_alignof__tuple3_)=1));
Index: tests/.expect/functions.x86.txt
===================================================================
--- tests/.expect/functions.x86.txt	(revision c4570af36d5be981e5714c9d730a86bc48ac9d4a)
+++ tests/.expect/functions.x86.txt	(revision dd900b564c8c9f6b67d2f5484e3ebcedce82b1ee)
@@ -105,5 +105,5 @@
 struct _tuple2_ {
 };
-static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, unsigned long int _sizeof_Y15tuple_param_2_0, unsigned long int _alignof_Y15tuple_param_2_0, unsigned long int _sizeof_Y15tuple_param_2_1, unsigned long int _alignof_Y15tuple_param_2_1){
+static inline void _layoutof__tuple2_(unsigned long int *_sizeof__tuple2_, unsigned long int *_alignof__tuple2_, unsigned long int *_offsetof__tuple2_, const unsigned long int _sizeof_Y15tuple_param_2_0, const unsigned long int _alignof_Y15tuple_param_2_0, const unsigned long int _sizeof_Y15tuple_param_2_1, const unsigned long int _alignof_Y15tuple_param_2_1){
     ((void)((*_sizeof__tuple2_)=0));
     ((void)((*_alignof__tuple2_)=1));
@@ -136,5 +136,5 @@
 struct _tuple3_ {
 };
-static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, unsigned long int _sizeof_Y15tuple_param_3_0, unsigned long int _alignof_Y15tuple_param_3_0, unsigned long int _sizeof_Y15tuple_param_3_1, unsigned long int _alignof_Y15tuple_param_3_1, unsigned long int _sizeof_Y15tuple_param_3_2, unsigned long int _alignof_Y15tuple_param_3_2){
+static inline void _layoutof__tuple3_(unsigned long int *_sizeof__tuple3_, unsigned long int *_alignof__tuple3_, unsigned long int *_offsetof__tuple3_, const unsigned long int _sizeof_Y15tuple_param_3_0, const unsigned long int _alignof_Y15tuple_param_3_0, const unsigned long int _sizeof_Y15tuple_param_3_1, const unsigned long int _alignof_Y15tuple_param_3_1, const unsigned long int _sizeof_Y15tuple_param_3_2, const unsigned long int _alignof_Y15tuple_param_3_2){
     ((void)((*_sizeof__tuple3_)=0));
     ((void)((*_alignof__tuple3_)=1));
