aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_stmt.cpp
diff options
context:
space:
mode:
authorBarinzaya <barinzaya@gmail.com>2025-04-24 14:15:22 -0400
committerBarinzaya <barinzaya@gmail.com>2025-04-24 14:21:21 -0400
commitb41a776027b0b4796edc85217c5c607e5498035d (patch)
treea5d494f72254c1590b8c28cca85b3234055a3649 /src/llvm_backend_stmt.cpp
parentcfb478808e7dae48f3a40fe7e40927c5e38a5d1d (diff)
Correctly align global and static variables.
This can be important if matrices or SIMD vectors are being used in global or static variables, as otherwise it may result in crashes due to aligned instructions accessing misaligned variables.
Diffstat (limited to 'src/llvm_backend_stmt.cpp')
-rw-r--r--src/llvm_backend_stmt.cpp1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/llvm_backend_stmt.cpp b/src/llvm_backend_stmt.cpp
index a0b7e8340..31e1ea595 100644
--- a/src/llvm_backend_stmt.cpp
+++ b/src/llvm_backend_stmt.cpp
@@ -1984,6 +1984,7 @@ gb_internal void lb_build_static_variables(lbProcedure *p, AstValueDecl *vd) {
char *c_name = alloc_cstring(permanent_allocator(), mangled_name);
LLVMValueRef global = LLVMAddGlobal(p->module->mod, lb_type(p->module, e->type), c_name);
+ LLVMSetAlignment(global, type_align_of(e->type));
LLVMSetInitializer(global, LLVMConstNull(lb_type(p->module, e->type)));
if (value.value != nullptr) {
LLVMSetInitializer(global, value.value);