From 2a41fa6281b657e735f4aa0e5423e35ba73b8e66 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 18 Nov 2025 18:25:07 +0100 Subject: [PATCH] Passing a single value to `@wasm` would ignore the renaming --- releasenotes.md | 1 + src/compiler/sema_decls.c | 15 +++++++------ test/test_suite/abi/wasm_attribute.c3t | 31 ++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 test/test_suite/abi/wasm_attribute.c3t diff --git a/releasenotes.md b/releasenotes.md index 7bdc2699a..09c46ce3a 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -32,6 +32,7 @@ - Regression vector ABI: npot vectors would load incorrectly from pointers and other things. #2576 - Using `defer catch` with a (void), would cause an assertion. #2580 - Fix decl attribute in the wrong place causing an assertion. #2581 +- Passing a single value to `@wasm` would ignore the renaming. ### Stdlib changes diff --git a/src/compiler/sema_decls.c b/src/compiler/sema_decls.c index a968dc06d..d3a537dc2 100755 --- a/src/compiler/sema_decls.c +++ b/src/compiler/sema_decls.c @@ -3326,14 +3326,15 @@ static bool sema_analyse_attribute(SemaContext *context, ResolvedAttrData *attr_ RETURN_SEMA_ERROR(module, "Expected a constant string value as argument."); } attr_data->wasm_module = module->const_expr.bytes.ptr; - if (!sema_analyse_expr_rvalue(context, expr)) return false; - if (!expr_is_const_string(expr)) - { - RETURN_SEMA_ERROR(expr, "Expected a constant string value as argument."); - } - decl->extname = expr->const_expr.bytes.ptr; - decl->has_extname = true; } + + if (!sema_analyse_expr_rvalue(context, expr)) return false; + if (!expr_is_const_string(expr)) + { + RETURN_SEMA_ERROR(expr, "Expected a constant string value as argument."); + } + decl->extname = expr->const_expr.bytes.ptr; + decl->has_extname = true; return true; case ATTRIBUTE_EXPORT: if (context->unit->module->is_generic) diff --git a/test/test_suite/abi/wasm_attribute.c3t b/test/test_suite/abi/wasm_attribute.c3t new file mode 100644 index 000000000..fad4ad66e --- /dev/null +++ b/test/test_suite/abi/wasm_attribute.c3t @@ -0,0 +1,31 @@ +// #target: wasm32 +module test; + +fn int testexport(int num) @export("test_export") +{ + return num * 100; +} + +fn int testwasm(int num) @wasm("test_wasm") +{ + return num * 100; +} +fn int main() +{ + return 0; +} + +/* #expect: test.ll + +define i32 @test_export(i32 %0) #0 { +entry: + %mul = mul i32 %0, 100 + ret i32 %mul +} + +define i32 @test_wasm(i32 %0) #1 { +entry: + %mul = mul i32 %0, 100 + ret i32 %mul +} +