Do not produce expression locations for windows.

This commit is contained in:
Christoffer Lerno
2024-12-04 12:21:12 +01:00
parent ec82ec0426
commit 0ded93ab9b
6 changed files with 26 additions and 18 deletions

View File

@@ -32,6 +32,7 @@
- Crash compiling for arm64 when returning 16 byte and smaller structs by value not a power of 2 #1649.
- Enforce single module compilation for static libraries to make constructors run properly.
- Crash when using --no-obj without compile-only. #1653
- Do not produce expression locations for windows.
### Stdlib changes
- Add `io::MultiReader`, `io::MultiWriter`, and `io::TeeReader` structs.

View File

@@ -145,7 +145,7 @@ static void llvm_emit_debug_declare(GenContext *c, LLVMValueRef var, LLVMMetadat
void llvm_emit_debug_local_var(GenContext *c, Decl *decl)
{
ASSERT0(llvm_is_local_eval(c));
EMIT_LOC(c, decl);
EMIT_EXPR_LOC(c, decl);
uint32_t row = decl->span.row;
uint32_t col = decl->span.col;
if (!row) row = 1;

View File

@@ -1397,7 +1397,7 @@ void llvm_emit_ignored_expr(GenContext *c, Expr *expr)
PUSH_CATCH_VAR_BLOCK(NULL, discard_fail);
llvm_emit_expr(c, &value, expr);
llvm_value_fold_optional(c, &value);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
// We only optimize if there is no instruction the current block
if (!LLVMGetFirstInstruction(c->current_block))
{
@@ -2458,7 +2458,7 @@ static inline LLVMValueRef llvm_emit_inc_dec_value(GenContext *c, SourceSpan spa
static inline void llvm_emit_inc_dec_change(GenContext *c, BEValue *addr, BEValue *after, BEValue *before,
Expr *expr, int diff, bool allow_wrap)
{
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
// Copy the address and make it a value.
BEValue value = *addr;
@@ -3278,7 +3278,7 @@ static void llvm_emit_slice_assign(GenContext *c, BEValue *be_value, Expr *expr)
// We emit a phi here: value is either the start value (start_offset) or the next value (next_offset)
// but we haven't generated the latter yet, so we defer that.
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
LLVMValueRef offset = LLVMBuildPhi(c->builder, llvm_get_type(c, start.type), "");
BEValue offset_val;
llvm_value_set(&offset_val, offset, start.type);
@@ -3289,7 +3289,7 @@ static void llvm_emit_slice_assign(GenContext *c, BEValue *be_value, Expr *expr)
llvm_emit_int_comp_raw(c, &value, start.type, end.type, offset, end.value, op);
// If jump to the assign block if we're not at the end index.
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
llvm_emit_cond_br(c, &value, assign_block, exit_block);
// Emit the assign.
@@ -4377,7 +4377,7 @@ void llvm_emit_binary(GenContext *c, BEValue *be_value, Expr *expr, BEValue *lhs
BEValue rhs;
llvm_emit_expr(c, &rhs, exprptr(expr->binary_expr.right));
llvm_fold_for_compare(c, &rhs);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
// Comparison <=>
if (binary_op >= BINARYOP_GT && binary_op <= BINARYOP_EQ)
{
@@ -4709,7 +4709,7 @@ static inline void llvm_emit_force_unwrap_expr(GenContext *c, BEValue *be_value,
llvm_emit_panic(c, "Force unwrap failed!", loc, "Unexpected fault '%s' was unwrapped!", varargs);
}
llvm_emit_block(c, no_err_block);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
}
@@ -6349,7 +6349,7 @@ static void llvm_emit_call_expr(GenContext *c, BEValue *result_value, Expr *expr
scratch_buffer_printf("No method '%s' could be found on target", dyn_fn->name);
llvm_emit_panic(c, scratch_buffer_to_string(), expr->span, NULL, NULL);
llvm_emit_block(c, match);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
values[0] = result;
}
@@ -6861,7 +6861,7 @@ static inline void llvm_emit_typeid_info(GenContext *c, BEValue *value, Expr *ex
}
llvm_emit_panic(c, "Attempted to access 'inner' on non composite type", expr->span, NULL, NULL);
llvm_emit_block(c, exit);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
}
{
LLVMValueRef val = llvm_emit_struct_gep_raw(c, ref, c->introspect_type, INTROSPECT_INDEX_INNER, align, &alignment);
@@ -6890,7 +6890,7 @@ static inline void llvm_emit_typeid_info(GenContext *c, BEValue *value, Expr *ex
}
llvm_emit_panic(c, "Attempted to access 'names' on non enum/fault type.", expr->span, NULL, NULL);
llvm_emit_block(c, exit);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
}
{
LLVMValueRef len = llvm_emit_struct_gep_raw(c, ref, c->introspect_type, INTROSPECT_INDEX_LEN, align, &alignment);
@@ -6923,7 +6923,7 @@ static inline void llvm_emit_typeid_info(GenContext *c, BEValue *value, Expr *ex
}
llvm_emit_panic(c, "Attempted to access 'len' on non array type", expr->span, NULL, NULL);
llvm_emit_block(c, exit);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
}
{
LLVMValueRef val = llvm_emit_struct_gep_raw(c, ref, c->introspect_type, INTROSPECT_INDEX_LEN, align, &alignment);
@@ -7239,7 +7239,7 @@ void llvm_emit_expr_global_value(GenContext *c, BEValue *value, Expr *expr)
}
void llvm_emit_expr(GenContext *c, BEValue *value, Expr *expr)
{
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
switch (expr->expr_kind)
{
case NON_RUNTIME_EXPR:

View File

@@ -52,9 +52,11 @@ typedef struct DebugScope_
typedef struct
{
unsigned runtime_version : 8;
bool enable_stacktrace : 1;
bool enable_stacktrace;
bool emit_expr_loc;
unsigned runtime_version;
LLVMDIBuilderRef builder;
DebugFile *debug_files;
DebugFile file;
LLVMMetadataRef compile_unit;
@@ -574,7 +576,8 @@ void llvm_emit_debug_local_var(GenContext *c, Decl *var);
#define UWTABLE (compiler.build.arch_os_target == MACOS_AARCH64 ? 1 : 2)
#define EMIT_LOC(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x->span); } while (0)
#define EMIT_SPAN(c, x) do { if (c->debug.builder) llvm_emit_debug_location(c, x); } while (0)
#define EMIT_EXPR_LOC(c, x) do { if (c->debug.emit_expr_loc) llvm_emit_debug_location(c, x->span); } while (0)
#define EMIT_SPAN(c, x) do { if (c->debug.emit_expr_loc) llvm_emit_debug_location(c, x); } while (0)
#define PUSH_DEFER_ERROR(val__) LLVMValueRef def_err__ = c->defer_error_var; c->defer_error_var = val__
#define POP_DEFER_ERROR() c->defer_error_var = def_err__

View File

@@ -127,11 +127,14 @@ void gencontext_begin_module(GenContext *c)
if (c->panic_var) c->panic_var->backend_ref = NULL;
if (c->panicf) c->panicf->backend_ref = NULL;
bool is_win = compiler.build.arch_os_target == WINDOWS_X64 || compiler.build.arch_os_target == WINDOWS_AARCH64;
llvm_set_module_flag(c, LLVMModuleFlagBehaviorWarning, "Dwarf Version", 4, type_uint);
if (is_win)
{
llvm_set_module_flag(c, LLVMModuleFlagBehaviorError, "CodeView", 1, type_uint);
}
else
{
llvm_set_module_flag(c, LLVMModuleFlagBehaviorWarning, "Dwarf Version", 4, type_uint);
}
llvm_set_module_flag(c, LLVMModuleFlagBehaviorWarning, "Debug Info Version", 3, type_uint);
llvm_set_module_flag(c, LLVMModuleFlagBehaviorWarning, "wchar_size", is_win ? 2 : 4, type_uint);
static const char *pic_level = "PIC Level";
@@ -156,7 +159,7 @@ void gencontext_begin_module(GenContext *c)
llvm_set_module_flag(c, LLVMModuleFlagBehaviorError, "uwtable", UWTABLE, type_uint);
if (is_win)
{
llvm_set_module_flag(c, LLVMModuleFlagBehaviorWarning, "MaxTLSAlign", 65536, type_uint);
llvm_set_module_flag(c, LLVMModuleFlagBehaviorError, "MaxTLSAlign", 65536, type_uint);
}
else
{
@@ -172,6 +175,7 @@ void gencontext_begin_module(GenContext *c)
{
c->debug.enable_stacktrace = os_supports_stacktrace(compiler.platform.os);
}
c->debug.emit_expr_loc = !is_win;
}
c->global_builder = LLVMCreateBuilder();
c->builder = c->global_builder;

View File

@@ -1167,7 +1167,7 @@ static inline void llvm_emit_assume(GenContext *c, Expr *expr)
llvm_emit_expr(c, &value, expr);
llvm_value_rvalue(c, &value);
ASSERT0(value.kind == BE_BOOLEAN);
EMIT_LOC(c, expr);
EMIT_EXPR_LOC(c, expr);
llvm_emit_assume_true(c, &value);
}
}