From 1999f0daad505f414f97845ecde0a56b3c2fedfd Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 13 Apr 2018 11:10:17 -0400 Subject: [PATCH] fix undefined behavior triggered by fn inline test LLVM destroys the string that we use to test if LLVM deleted the inlined function. Also fixed forgetting to initialize a buffer in std lib path detection. --- src/codegen.cpp | 2 +- src/main.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 2aca143524bf6ed3494d85d6cc4fab62aeb690e0..a58832f983d48a9b8519685066455b67598597d1 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -467,7 +467,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { fn_table_entry->llvm_value, buf_ptr(&fn_export->name)); } } - fn_table_entry->llvm_name = LLVMGetValueName(fn_table_entry->llvm_value); + fn_table_entry->llvm_name = strdup(LLVMGetValueName(fn_table_entry->llvm_value)); switch (fn_table_entry->fn_inline) { case FnInlineAlways: diff --git a/src/main.cpp b/src/main.cpp index 63b077e83322b3a8d9e3b9d41b9863b39f8e4281..37d1c91170ee484b05fa6ac55a28d5d32f011159 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -179,6 +179,7 @@ static int find_zig_lib_dir(Buf *out_path) { Buf self_exe_path = BUF_INIT; if (!(err = os_self_exe_path(&self_exe_path))) { Buf *cur_path = &self_exe_path; + buf_resize(cur_path, 0); for (;;) { Buf *test_dir = buf_alloc(); -- 2.54.0