# Possible bug in SIL

**URL:** <https://forums.swift.org/t/possible-bug-in-sil/21896>\
**Category:** Compiler\
**Created:** [March 21, 2019, 9:45pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896 "2019-03-21T21:45:33Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ebup](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@ebup](https://forums.swift.org/u/ebup)\
**Post date:** [March 21, 2019, 9:45pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/1 "2019-03-21T21:45:33Z")

</div>

I'm seeing an error in SIL:

```
include/swift/SIL/SILConstants.h:356:1: error: static_assert failed "SymbolicValue should stay small"
static_assert(sizeof(SymbolicValue) == 2 * sizeof(void *),
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.

```

This is from a clean git clone done yesterday.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [March 21, 2019, 10:06pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/2 "2019-03-21T22:06:03Z")

</div>

Nothing seems to have changed there recently, so

- are you compiling for a 32-bit system? (i.e. do you want to run the compiler itself on a 32-bit host)
- are you using MSVC to compile? (probably not; that looks like a Clang error)

---

<div class="post-metadata">

**Author:** ![ebup](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@ebup](https://forums.swift.org/u/ebup)\
**Post date:** [March 22, 2019, 12:50am UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/3 "2019-03-22T00:50:57Z")

</div>

Yes, I'm compiling on a 32-bit host for the same host.  
No, it's clang.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [March 22, 2019, 1:19am UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/4 "2019-03-22T01:19:44Z")

</div>

Okay. I don't think we regularly test the compiler for 32-bit hosts, so you may find places you need to tweak the code to get that to work. In this case I think it'd be fine to change the static assert to say `sizeof(SymbolicValue) <= 2 * sizeof(uint32_t) + sizeof(void *), …)` (and we would accept a PR to that effect).

---

<div class="post-metadata">

**Author:** ![ebup](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@ebup](https://forums.swift.org/u/ebup)\
**Post date:** [March 22, 2019, 6:22pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/5 "2019-03-22T18:22:55Z")

</div>

Actually that causes an error as well.

> swift-source/swift/include/swift/SIL/SILConstants.h:356:1: error: static\_assert failed "SymbolicValue should stay small"  
> static\_assert(sizeof(SymbolicValue) == 2 \* sizeof(uint32\_t) + sizeof(void \*),  
> ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~  
> 1 error generated.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [March 22, 2019, 6:24pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/6 "2019-03-22T18:24:56Z")

</div>

That `<=` was deliberate, although I'm a little surprised that that's _not_ the final size of the type. It seems to me like alignment would force it into that.

---

<div class="post-metadata">

**Author:** ![ebup](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@ebup](https://forums.swift.org/u/ebup)\
**Post date:** [March 22, 2019, 6:56pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/7 "2019-03-22T18:56:28Z")

</div>

Oops I didn't see the \<=. I've commented this line out and the build is continuing.

> [@jrose](#):
>
> I'm a little surprised

But this is an object, so on top of the ivars, which are at least 10 bytes, there is also an is\_a pointer.

---

<div class="post-metadata">

**Author:** ![ebup](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@ebup](https://forums.swift.org/u/ebup)\
**Post date:** [March 22, 2019, 8:45pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/8 "2019-03-22T20:45:32Z")

</div>

Another compilation error:

> swift: ...swift-source/llvm/include/llvm/ADT/PointerIntPair.h:165: static intptr\_t llvm::PointerIntPairInfo\<swift::AvailableAttr \*, 2, llvm::PointerLikeTypeTraits\<swift::AvailableAttr \*\> \>::updatePointer(intptr\_t, PointerT) [PointerT = swift::AvailableAttr \*, IntBits = 2, PtrTraits = llvm::PointerLikeTypeTraits\<swift::AvailableAttr \*\>]: Assertion `(PtrWord & ~PointerBitMask) == 0 && "Pointer is not sufficiently aligned"' failed.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [March 22, 2019, 9:46pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/9 "2019-03-22T21:46:42Z")

</div>

swiftc compiles with -fno-rtti, so only classes with virtual methods will have the extra pointer. (Unless you're somehow _not_ getting an -fno-rtti build?)

In general I suspect you'll get a bunch of these static assertions, and maybe some runtime ones as well. For the alignment cases, feel free to use `alignas` where necessary to provide the alignment that's expected. For the static assertions, figure out what the equivalent rule would be in a 32-bit world. (For example, I think it's worth figuring out what the size of SymbolicValue actually is and why.)

---

<div class="post-metadata">

**Author:** ![ebup](https://avatars.discourse-cdn.com/v4/letter/e/f0a364/32.png) [@ebup](https://forums.swift.org/u/ebup)\
**Post date:** [March 23, 2019, 3:20pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/10 "2019-03-23T15:20:47Z")

</div>

Why does the pointer pair type have to be 16-byte aligned in the first place? That seems like a minuscule optimization, if that's what it's for.

Also, if Swift isn't really intended for 32-bit systems, can it really be said to be a cross platform language? 32-bit systems will be around for years.

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [March 25, 2019, 3:38pm UTC](https://forums.swift.org/t/possible-bug-in-sil/21896/11 "2019-03-25T15:38:33Z")

</div>

The compiler implementation overaligns certain types (even in 64-bit mode) in order to store flags in the same word as a pointer. Is it an important optimization? Sometimes yes, sometimes we're probably being overzealous. It is a balance against wasting alignment padding, and we haven't measured that specifically, and particularly not for a 32-bit host.
