aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-08-08 01:00:29 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-08-08 01:00:29 -0700
commit1b1921f0e26b9cb8ac78003c9061acac2da5e7ab (patch)
tree4008d0d0e7eecbc32f61af6e36077f01ec1a489a /src/codegen.cpp
parent9f5a7d5922f48170551e7f6938b6de9eadeba0ff (diff)
downloadzig-1b1921f0e26b9cb8ac78003c9061acac2da5e7ab.tar.gz
zig-1b1921f0e26b9cb8ac78003c9061acac2da5e7ab.zip
stage1: deal with WebAssembly not supporting @returnAddress()
This makes `@returnAddress()` return 0 for WebAssembly (when not using the Emscripten OS) and avoids trying to capture stack traces for the general purpose allocator on that target.
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 023c94f245..6941eae466 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5886,6 +5886,12 @@ static LLVMValueRef ir_render_breakpoint(CodeGen *g, IrExecutableGen *executable
static LLVMValueRef ir_render_return_address(CodeGen *g, IrExecutableGen *executable,
IrInstGenReturnAddress *instruction)
{
+ if (target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) {
+ // I got this error from LLVM 10:
+ // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"
+ return LLVMConstNull(get_llvm_type(g, instruction->base.value->type));
+ }
+
LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_i32->llvm_type);
LLVMValueRef ptr_val = LLVMBuildCall(g->builder, get_return_address_fn_val(g), &zero, 1, "");
return LLVMBuildPtrToInt(g->builder, ptr_val, g->builtin_types.entry_usize->llvm_type, "");