mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Removed implicitly created modules. Fix classification of arrays in x64. Fix cast with direct-pair. With test cases.
This commit is contained in:
@@ -419,17 +419,7 @@ Module *global_context_find_module(const char *name)
|
||||
Module *compiler_find_or_create_module(Path *module_name, TokenId *parameters)
|
||||
{
|
||||
Module *module = global_context_find_module(module_name->module);
|
||||
if (module)
|
||||
{
|
||||
// We might have gotten an auto-generated module, if so
|
||||
// update the path here.
|
||||
if (module->name->span.loc.index == INVALID_TOKEN_ID.index && module_name->span.loc.index != INVALID_TOKEN_ID.index)
|
||||
{
|
||||
module->name = module_name;
|
||||
module->parameters = parameters;
|
||||
}
|
||||
return module;
|
||||
}
|
||||
if (module) return module;
|
||||
|
||||
DEBUG_LOG("Creating module %s.", module_name->module);
|
||||
// Set up the module.
|
||||
@@ -448,13 +438,6 @@ Module *compiler_find_or_create_module(Path *module_name, TokenId *parameters)
|
||||
vec_add(global_context.module_list, module);
|
||||
}
|
||||
|
||||
// Now find the possible parent array:
|
||||
Path *parent_path = path_find_parent_path(NULL, module_name);
|
||||
if (parent_path)
|
||||
{
|
||||
// Get the parent
|
||||
compiler_find_or_create_module(parent_path, NULL);
|
||||
}
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
@@ -1616,7 +1616,7 @@ Decl *module_find_symbol(Module *module, const char *symbol);
|
||||
|
||||
bool parse_file(Context *context);
|
||||
Path *path_create_from_string(const char *string, size_t len, SourceSpan span);
|
||||
Path *path_find_parent_path(Context *context, Path *path);
|
||||
Path *path_find_parent_path(Path *path);
|
||||
|
||||
const char *resolve_status_to_string(ResolveStatus status);
|
||||
|
||||
|
||||
@@ -307,7 +307,7 @@ void x64_classify_array(Type *type, ByteSize offset_base, X64Class *current, X64
|
||||
X64Class field_lo;
|
||||
X64Class field_hi;
|
||||
x64_classify(element, offset, &field_lo, &field_hi, named_arg);
|
||||
offset_base += element_size;
|
||||
offset += element_size;
|
||||
*lo_class = x64_merge(*lo_class, field_lo);
|
||||
*hi_class = x64_merge(*hi_class, field_hi);
|
||||
if (*lo_class == CLASS_MEMORY || *hi_class == CLASS_MEMORY) break;
|
||||
|
||||
@@ -2520,7 +2520,7 @@ void llvm_emit_parameter(GenContext *c, LLVMValueRef **args, ABIArgInfo *info, B
|
||||
LLVMTypeRef lo = llvm_abi_type(c, info->direct_pair.lo);
|
||||
LLVMTypeRef hi = llvm_abi_type(c, info->direct_pair.hi);
|
||||
LLVMTypeRef struct_type = llvm_get_coerce_type(c, info);
|
||||
LLVMValueRef cast = LLVMBuildBitCast(c->builder, be_value->value, llvm_get_ptr_type(c, type), "casttemp");
|
||||
LLVMValueRef cast = LLVMBuildBitCast(c->builder, be_value->value, LLVMPointerType(struct_type, 0), "casttemp");
|
||||
// Get the lo value.
|
||||
LLVMValueRef lo_ptr = LLVMBuildStructGEP2(c->builder, struct_type, cast, 0, "lo");
|
||||
vec_add(*args, llvm_emit_load_aligned(c, lo, lo_ptr, llvm_abi_alignment(c, lo), "lo"));
|
||||
|
||||
@@ -174,6 +174,8 @@ static void param_expand(GenContext *context, LLVMTypeRef** params_ref, Type *ty
|
||||
ByteSize largest = 0;
|
||||
Type *largest_type = NULL;
|
||||
Decl **members = type->decl->strukt.members;
|
||||
// Clang: Unions can be here only in degenerative cases - all the fields are same
|
||||
// after flattening. Thus we have to use the "largest" field.
|
||||
VECEACH(members, i)
|
||||
{
|
||||
if (type_size(type) > largest)
|
||||
|
||||
@@ -23,16 +23,3 @@ Path *path_create_from_string(const char *string, size_t len, SourceSpan span)
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
Path *path_find_parent_path(Context *context, Path *path)
|
||||
{
|
||||
const char *last_scope_chars = strrchr(path->module, ':');
|
||||
// No parent
|
||||
if (!last_scope_chars) return NULL;
|
||||
|
||||
Path *parent_path = path_create_from_string(path->module, last_scope_chars - path->module - 1, INVALID_RANGE);
|
||||
|
||||
assert(parent_path && "Didn't we pass in a TOKEN_IDENT? That's the only reason this could fail.");
|
||||
|
||||
return parent_path;
|
||||
}
|
||||
36
test/test_suite/abi/union_x64.c3t
Normal file
36
test/test_suite/abi/union_x64.c3t
Normal file
@@ -0,0 +1,36 @@
|
||||
// #target: x64_darwin
|
||||
|
||||
module unionx64;
|
||||
|
||||
union Foo
|
||||
{
|
||||
long a;
|
||||
char[12] b;
|
||||
}
|
||||
extern func void hello2(Foo f);
|
||||
|
||||
func void hello(Foo f)
|
||||
{
|
||||
hello2(f);
|
||||
}
|
||||
|
||||
// #expect: unionx64.ll
|
||||
|
||||
%unionx64.Foo = type { i64, [8 x i8] }
|
||||
|
||||
declare void @hello2(i64, i64) #0
|
||||
|
||||
define void @unionx64.hello(i64 %0, i64 %1)
|
||||
|
||||
%f = alloca %unionx64.Foo, align 8
|
||||
%pair = bitcast %unionx64.Foo* %f to { i64, i64 }*
|
||||
%lo = getelementptr inbounds { i64, i64 }, { i64, i64 }* %pair, i32 0, i32 0
|
||||
store i64 %0, i64* %lo, align 8
|
||||
%hi = getelementptr inbounds { i64, i64 }, { i64, i64 }* %pair, i32 0, i32 1
|
||||
store i64 %1, i64* %hi, align 8
|
||||
%casttemp = bitcast %unionx64.Foo* %f to { i64, i64 }*
|
||||
%lo1 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %casttemp, i32 0, i32 0
|
||||
%lo2 = load i64, i64* %lo1, align 8
|
||||
%hi3 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %casttemp, i32 0, i32 1
|
||||
%hi4 = load i64, i64* %hi3, align 8
|
||||
call void @hello2(i64 %lo2, i64 %hi4)
|
||||
Reference in New Issue
Block a user