Skip to content

Commit 36257d6

Browse files
committed
[IRGen] NFC: Add static_assert cross references
The metadata visitors note the address start of the metadata, but that is not actually the way the offsets are calculated.
1 parent ec0b560 commit 36257d6

File tree

5 files changed

+15
-0
lines changed

5 files changed

+15
-0
lines changed

lib/IRGen/ClassMetadataVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ template <class Impl> class ClassMetadataVisitor
4949

5050
public:
5151
void layout() {
52+
static_assert(MetadataAdjustmentIndex::Class == 2,
53+
"Adjustment index must be synchronized with this layout");
54+
5255
// HeapMetadata header.
5356
asImpl().addDestructorFunction();
5457

lib/IRGen/EnumMetadataVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ template <class Impl> class EnumMetadataVisitor
4444

4545
public:
4646
void layout() {
47+
static_assert(MetadataAdjustmentIndex::ValueType == 1,
48+
"Adjustment index must be synchronized with this layout");
49+
4750
// Metadata header.
4851
super::layout();
4952

lib/IRGen/IRGenModule.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "ConformanceDescription.h"
5656
#include "GenDecl.h"
5757
#include "GenEnum.h"
58+
#include "GenMeta.h"
5859
#include "GenPointerAuth.h"
5960
#include "GenIntegerLiteral.h"
6061
#include "GenType.h"
@@ -338,6 +339,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
338339
// A full type metadata record is basically just an adjustment to the
339340
// address point of a type metadata. Resilience may cause
340341
// additional data to be laid out prior to this address point.
342+
static_assert(MetadataAdjustmentIndex::ValueType == 1,
343+
"Adjustment index must be synchronized with this layout");
341344
FullTypeMetadataStructTy = createStructType(*this, "swift.full_type", {
342345
WitnessTablePtrTy,
343346
TypeMetadataStructTy
@@ -350,6 +353,8 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
350353
// A full heap metadata is basically just an additional small prefix
351354
// on a full metadata, used for metadata corresponding to heap
352355
// allocations.
356+
static_assert(MetadataAdjustmentIndex::Class == 2,
357+
"Adjustment index must be synchronized with this layout");
353358
FullHeapMetadataStructTy =
354359
createStructType(*this, "swift.full_heapmetadata", {
355360
dtorPtrTy,

lib/IRGen/NominalMetadataVisitor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "GenericRequirement.h"
2222
#include "GenProto.h"
23+
#include "GenMeta.h"
2324
#include "IRGenModule.h"
2425
#include "MetadataVisitor.h"
2526

lib/IRGen/StructMetadataVisitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ template <class Impl> class StructMetadataVisitor
4343

4444
public:
4545
void layout() {
46+
static_assert(MetadataAdjustmentIndex::ValueType == 1,
47+
"Adjustment index must be synchronized with this layout");
48+
4649
// Metadata header.
4750
super::layout();
4851

0 commit comments

Comments
 (0)