Skip to content

Commit 253a72f

Browse files
authored
Merge pull request odin-lang#5827 from jakubtomsu/5826-fix
[LLVM Backend] Prefer the type pointer over LLVMTypeRef when looking up struct_field_remapping (Fix 5826)
2 parents c51f4da + c21453a commit 253a72f

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/llvm_backend_utility.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,9 +981,12 @@ gb_internal lbStructFieldRemapping lb_get_struct_remapping(lbModule *m, Type *t)
981981

982982
mutex_lock(&m->types_mutex);
983983

984-
auto *field_remapping = map_get(&m->struct_field_remapping, cast(void *)struct_type);
984+
// NOTE(jakub): It's very important to check the type pointer first,
985+
// because two disctinct but similar structs can end up with the same LLVMTypeRef after interning.
986+
// (For example struct{u16,u8} looks identical to LLVM as struct{u16,u8,u8} once padding fields are inserted.)
987+
auto *field_remapping = map_get(&m->struct_field_remapping, cast(void *)t);
985988
if (field_remapping == nullptr) {
986-
field_remapping = map_get(&m->struct_field_remapping, cast(void *)t);
989+
field_remapping = map_get(&m->struct_field_remapping, cast(void *)struct_type);
987990
}
988991

989992
mutex_unlock(&m->types_mutex);

0 commit comments

Comments
 (0)