Skip to content

Commit 96156be

Browse files
committed
[32-bit Linux] Adjust SILLocation Size Assert
The assert currently assumes that the size of SILLocation is 3 pointers big, or 24-bytes as it is on 64-bit platforms. The catch is that this math works because it’s having to make a rough assumption of the size of unsigned and pointer in relation to each other. 4 unsigned + 1 pointer = 3 pointer in this example. This breaks down on 32-bit where 4 unsigned + 1 pointer = 5 unsigned = 20 bytes. It technically doesn’t violate the spirit of the assert, but the way the assert is written simply doesn’t work for 32-bit. It can be written as `sizeof(SILLocation) <= 6*sizeof(unsigned)` without an ifdef, but it means that if someone was to make it even smaller at some point, the assert wouldn’t fail, signaling to the developer that they should update the assert with the new, smaller, value. But it would be cleaner. The way this change is written, if the size changes in either direction, the developer is signaled that they should either update the assert, or fix their regression.
1 parent eddecbf commit 96156be

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/SIL/SILLocation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
using namespace swift;
2222

23-
static_assert(sizeof(SILLocation) == 3*sizeof(void *),
23+
// 64-bit is 24 bytes, 32-bit is 20 bytes.
24+
static_assert(sizeof(SILLocation) == sizeof(void *) + 4*sizeof(unsigned),
2425
"SILLocation must stay small");
2526

2627
SourceLoc SILLocation::getSourceLoc() const {

0 commit comments

Comments
 (0)