Fix void* <=> protocol casts. Fix of tests.

This commit is contained in:
Christoffer Lerno
2023-10-13 12:44:58 +02:00
parent 9b714e1dbb
commit e81e91be93
12 changed files with 69 additions and 35 deletions

View File

@@ -1968,8 +1968,8 @@ CastRule cast_rules[CONV_LAST + 1][CONV_LAST + 1] = {
{REXPL, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RARVC, RARBS, RXXDI, RARAR, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RVAFE}, // ARRAY
{REXPL, _NO__, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTDI, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, RSTST, _NO__}, // STRUCT
{REXPL, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // UNION
{REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, _NA__, REXPL, _NO__, _NO__, _NO__, _NO__, REXPL, REXPL, _NO__}, // ANY
{REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, ROKOK, RPCPC, _NO__, _NO__, _NO__, _NO__, REXPL, REXPL, _NO__}, // PROTOCOL
{REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, _NA__, REXPL, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, _NO__}, // ANY
{REXPL, _NO__, REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, RXXDI, _NO__, _NO__, _NO__, ROKOK, RPCPC, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, _NO__}, // PROTOCOL
{REXPL, _NO__, REXPL, RPTIN, _NO__, REXPL, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, ROKOK, REXPL, REXPL, _NO__}, // FAULT
{REXPL, _NO__, _NO__, REXPL, _NO__, _NO__, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__}, // ENUM
{REXPL, _NO__, REXPL, RPTIN, _NO__, REXPL, _NO__, ROKOK, _NO__, RXXDI, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NO__, _NA__, _NO__, REXPL, REXPL, _NO__}, // TYPEID

View File

@@ -1672,12 +1672,12 @@ static bool arch_os_pic_default_forced(ArchType arch, OsType os)
LLVMInitialize ## X ## TargetMC(); \
} while(0)
INLINE const char *llvm_macos_target_triple(void)
INLINE const char *llvm_macos_target_triple(const char *triple)
{
if (active_target.macos.min_version)
{
scratch_buffer_clear();
scratch_buffer_append(platform_target.target_triple);
scratch_buffer_append(triple);
scratch_buffer_append(active_target.macos.min_version);
return scratch_buffer_to_string();
}
@@ -1686,12 +1686,12 @@ INLINE const char *llvm_macos_target_triple(void)
if (!mac_sdk)
{
scratch_buffer_clear();
scratch_buffer_append(platform_target.target_triple);
scratch_buffer_append(triple);
scratch_buffer_append("10.15.0");
return scratch_buffer_to_string();
}
scratch_buffer_clear();
scratch_buffer_append(platform_target.target_triple);
scratch_buffer_append(triple);
scratch_buffer_printf("%d.%d.0", mac_sdk->macos_min_deploy_target.major, mac_sdk->macos_min_deploy_target.minor);
return scratch_buffer_to_string();
}
@@ -1735,12 +1735,7 @@ void *llvm_target_machine_create(void)
}
DEBUG_LOG("CPU: %s", platform_target.cpu);
DEBUG_LOG("Features: %s", platform_target.features);
const char *target_triple = platform_target.target_triple;
if (platform_target.os == OS_TYPE_MACOSX)
{
target_triple = llvm_macos_target_triple();
}
void *result = LLVMCreateTargetMachine(target, target_triple,
void *result = LLVMCreateTargetMachine(target, platform_target.target_triple,
platform_target.cpu ? platform_target.cpu : "", platform_target.features ? platform_target.features : "",
(LLVMCodeGenOptLevel)platform_target.llvm_opt_level,
reloc_mode, LLVMCodeModelDefault);
@@ -1950,10 +1945,11 @@ void target_setup(BuildTarget *target)
DEBUG_LOG("Macos SDK: %s", sysroot);
active_target.macos.sdk = macos_sysroot_sdk_information(sysroot);
}
platform_target.target_triple = strdup(llvm_macos_target_triple(platform_target.target_triple));
}
assert(platform_target.reloc_model != RELOC_DEFAULT);
// TODO remove
type_setup(&platform_target);

View File

@@ -2059,6 +2059,7 @@ Type *type_find_max_type(Type *type, Type *other)
other = temp;
}
// The following relies on type kind ordering
switch (type->type_kind)
{
case TYPE_INFERRED_ARRAY:
@@ -2070,12 +2071,6 @@ Type *type_find_max_type(Type *type, Type *other)
case TYPE_PROTOCOL:
case TYPE_ANY:
return NULL;
case TYPE_ANYPTR:
// any + protocol => any
return other->type_kind == TYPE_PROPTR ? type : NULL;
case TYPE_PROPTR:
// protocol + protocol => any
return other->type_kind == TYPE_PROPTR ? type_any : NULL;
case TYPE_VOID:
case TYPE_BOOL:
case TYPE_TYPEINFO:
@@ -2091,6 +2086,13 @@ Type *type_find_max_type(Type *type, Type *other)
if (other->type_kind == TYPE_DISTINCT && type_is_float(other->decl->distinct->type)) return other;
if (other->type_kind == TYPE_VECTOR) return other;
return type_find_max_num_type(type, other);
case TYPE_ANYPTR:
// any + protocol => any
if (other == type_voidptr) return other;
return other->type_kind == TYPE_PROPTR ? type : NULL;
case TYPE_PROPTR:
// protocol + void* => void*
return other == type_voidptr ? type_voidptr : NULL;
case TYPE_POINTER:
if (type->pointer->type_kind == TYPE_ARRAY)
{
@@ -2121,7 +2123,6 @@ Type *type_find_max_type(Type *type, Type *other)
type = type_decay_array_pointer(type);
// And possibly the other pointer as well
if (other->type_kind == TYPE_POINTER) other = type_decay_array_pointer(other);
return type_find_max_ptr_type(type, other);
case TYPE_ENUM:
// IMPROVE: should there be implicit conversion between one enum and the other in

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.678"
#define COMPILER_VERSION "0.4.679"

View File

@@ -6,8 +6,8 @@ fn bool[2] get() { return { false, false }; }
/* #expect: test.ll
source_filename = "test"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
@.__const = private unnamed_addr constant [2 x i8] zeroinitializer, align 1
define i16 @test.get() #0 {
entry:

View File

@@ -31,8 +31,8 @@ fn int main()
/* #expect: test.ll
source_filename = "test"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
@test.oeoekgokege = local_unnamed_addr global i32 343432, align 4
@.str = private unnamed_addr constant [7 x i8] c"Hello\0A\00", align 1

View File

@@ -0,0 +1,37 @@
module test;
import std::io;
import std::time;
protocol Test {}
fn void main()
{
Test* a;
bool x = a == null;
a = null;
any* z = a;
z = null;
}
/* #expect: test.ll
%"any*" = type { ptr, i64 }
@"$ct.void" = linkonce global %.introspect { i8 0, i64 0, ptr null, i64 1, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8
define void @test.main() #0 {
entry:
%a = alloca %"any*", align 8
%x = alloca i8, align 1
%z = alloca %"any*", align 8
store %"any*" zeroinitializer, ptr %a, align 8
%0 = getelementptr inbounds %"any*", ptr %a, i32 0, i32 0
%1 = load ptr, ptr %0, align 8
%eq = icmp eq ptr %1, null
%2 = zext i1 %eq to i8
store i8 %2, ptr %x, align 1
store %"any*" { ptr null, i64 ptrtoint (ptr @"$ct.void" to i64) }, ptr %a, align 8
%3 = load %"any*", ptr %a, align 8
store %"any*" %3, ptr %z, align 8
store %"any*" { ptr null, i64 ptrtoint (ptr @"$ct.void" to i64) }, ptr %z, align 8
ret void
}

View File

@@ -57,8 +57,8 @@ fn void main()
/* expect: test.ll
source_filename = "test"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
%.fault = type { i64, %"char[]" }
%"char[]" = type { i8*, i64 }

View File

@@ -49,8 +49,8 @@ fn void main()
/* #expect: foo.ll
source_filename = "foo"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
@.str = private unnamed_addr constant [5 x i8] c"1-3\0A\00", align 1
@.str.1 = private unnamed_addr constant [10 x i8] c"7-277 %d\0A\00", align 1

View File

@@ -27,8 +27,8 @@ fn void main()
/* #expect: foo.ll
source_filename = "foo"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
@test.x = internal unnamed_addr global i32 0, align 4
@.str = private unnamed_addr constant [4 x i8] c"%d\0A\00", align 1

View File

@@ -31,8 +31,8 @@ fn int main()
/* #expect: test.ll
source_filename = "test"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
@.str = private unnamed_addr constant [2 x i8] c"3\00", align 1
@.str.1 = private unnamed_addr constant [2 x i8] c"4\00", align 1

View File

@@ -682,8 +682,8 @@ fn void test()
; ModuleID = 'lexer_test'
source_filename = "lexer_test"
target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx"
target datalayout = "e-m:o-p270:32:32-p271:32
target triple = "x86_64-apple
%.introspect = type { i8, i64, ptr, i64, i64, i64, [0 x i64] }
%"char[]" = type { ptr, i64 }
%"UintTest[]" = type { ptr, i64 }