From 61a21203f4c7e9188c09f1e9f7ba2ff60d9f06b2 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 1 Aug 2025 10:32:53 +0200 Subject: [PATCH] Assigning string literal to char[<*>] stores pointer rather than characters. #2357 --- releasenotes.md | 1 + src/compiler/llvm_codegen_expr.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/releasenotes.md b/releasenotes.md index 8a506c3de..708f0c4ec 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -89,6 +89,7 @@ - Not setting android-ndk resulted in a "set ndk-path" error. - Lambda deduplication would be incorrect when generated at the global scope. - Disallow accessing parameters in a naked function, as well as `return`, this fixes #1955. +- Assigning string literal to char[<*>] stores pointer rather than characters. #2357 ### Stdlib changes - Improve contract for readline. #2280 diff --git a/src/compiler/llvm_codegen_expr.c b/src/compiler/llvm_codegen_expr.c index b64f0a63c..9322f653c 100644 --- a/src/compiler/llvm_codegen_expr.c +++ b/src/compiler/llvm_codegen_expr.c @@ -4722,7 +4722,7 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr) case CONST_STRING: { Type *str_type = type_lowering(expr->type); - bool is_array = str_type->type_kind == TYPE_ARRAY; + bool is_array = str_type->type_kind == TYPE_ARRAY || str_type->type_kind == TYPE_VECTOR; if (is_array && llvm_is_global_eval(c)) { // In the global alloc case, create the byte array. @@ -4776,7 +4776,7 @@ static void llvm_emit_const_expr(GenContext *c, BEValue *be_value, Expr *expr) LLVMSetInitializer(global_name, data); if (is_array) { - llvm_value_set_address(c, be_value, global_name, type, 1); + llvm_value_set_address(c, be_value, global_name, type, type_alloca_alignment(expr->type)); } else {