Small fixes

This commit is contained in:
Christoffer Lerno
2020-12-22 21:59:28 +01:00
parent 4da36dfed9
commit 9a0b8aab0b
6 changed files with 16 additions and 11 deletions

View File

@@ -108,7 +108,7 @@ add_executable(c3c
src/utils/whereami.c
src/compiler/llvm_codegen_c_abi_x86.c src/compiler/c_abi_internal.h src/compiler/llvm_codegen_c_abi_x64.c src/compiler/llvm_codegen_c_abi_win64.c src/compiler/llvm_codegen_c_abi_aarch64.c src/compiler/headers.c src/compiler/llvm_codegen_c_abi_riscv.c src/compiler/llvm_codegen_c_abi_wasm.c)
target_compile_options(c3c PRIVATE -Wimplicit-int -Werror -Wall -Wno-unknown-pragmas -Wextra -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter)
target_compile_options(c3c PRIVATE -Wsign-compare -Wimplicit-int -Werror -Wall -Wno-unknown-pragmas -Wextra -Wno-unused-function -Wno-unused-variable -Wno-unused-parameter)
target_link_libraries(c3c m ${llvm_libs})

View File

@@ -1570,7 +1570,7 @@ bool token_is_symbol(TokenType type);
const char *token_type_to_string(TokenType type);
AlignSize type_abi_alignment(Type *type);
unsigned type_alloca_alignment(Type *type);
AlignSize type_alloca_alignment(Type *type);
void type_append_signature_name(Type *type, char *dst, size_t *offset);
static inline bool type_convert_will_trunc(Type *destination, Type *source);
Type *type_find_common_ancestor(Type *left, Type *right);

View File

@@ -5,6 +5,11 @@
#include "llvm_codegen_internal.h"
static inline void llvm_set_alignment(LLVMValueRef alloca, LLVMTypeRef type, AlignSize alignment)
{
LLVMSetAlignment(alloca, alignment ?: llvm_abi_alignment(type));
}
static int get_inlining_threshold(void);
static void diagnostics_handler(LLVMDiagnosticInfoRef ref, void *context)
{
@@ -262,7 +267,7 @@ LLVMValueRef llvm_emit_alloca(GenContext *context, LLVMTypeRef type, unsigned al
LLVMBasicBlockRef current_block = LLVMGetInsertBlock(context->builder);
LLVMPositionBuilderBefore(context->builder, context->alloca_point);
LLVMValueRef alloca = LLVMBuildAlloca(context->builder, type, name);
LLVMSetAlignment(alloca, alignment ?: llvm_abi_alignment(type));
llvm_set_alignment(alloca, type, alignment);
LLVMPositionBuilderAtEnd(context->builder, current_block);
return alloca;
}
@@ -794,7 +799,7 @@ AlignSize llvm_abi_alignment(LLVMTypeRef type)
return (AlignSize)LLVMABIAlignmentOfType(target_data_layout(), type);
}
void llvm_store_bevalue_aligned(GenContext *c, LLVMValueRef destination, BEValue *value, unsigned alignment)
void llvm_store_bevalue_aligned(GenContext *c, LLVMValueRef destination, BEValue *value, AlignSize alignment)
{
// If we have an address but not an aggregate, do a load.
llvm_value_fold_failable(c, value);
@@ -850,7 +855,7 @@ void llvm_store_self_aligned(GenContext *context, LLVMValueRef pointer, LLVMValu
llvm_store_aligned(context, pointer, value, type_abi_alignment(type));
}
void llvm_store_aligned(GenContext *context, LLVMValueRef pointer, LLVMValueRef value, unsigned alignment)
void llvm_store_aligned(GenContext *context, LLVMValueRef pointer, LLVMValueRef value, AlignSize alignment)
{
LLVMValueRef ref = LLVMBuildStore(context->builder, value, pointer);
if (alignment) LLVMSetAlignment(ref, alignment);
@@ -882,7 +887,7 @@ void llvm_emit_memcpy_to_decl(GenContext *c, Decl *decl, LLVMValueRef source, un
LLVMValueRef llvm_emit_load_aligned(GenContext *context, LLVMTypeRef type, LLVMValueRef pointer, unsigned alignment, const char *name)
{
LLVMValueRef value = LLVMBuildLoad2(context->builder, type, pointer, name);
LLVMSetAlignment(value, alignment ?: llvm_abi_alignment(type));
llvm_set_alignment(value, type, alignment);
return value;
}

View File

@@ -256,9 +256,9 @@ unsigned llvm_store_size(LLVMTypeRef type);
void llvm_store_bevalue(GenContext *c, BEValue *destination, BEValue *value);
void llvm_store_bevalue_raw(GenContext *c, BEValue *destination, LLVMValueRef raw_value);
void llvm_store_bevalue_dest_aligned(GenContext *c, LLVMValueRef destination, BEValue *value);
void llvm_store_bevalue_aligned(GenContext *c, LLVMValueRef destination, BEValue *value, unsigned alignment);
void llvm_store_bevalue_aligned(GenContext *c, LLVMValueRef destination, BEValue *value, AlignSize alignment);
void llvm_store_self_aligned(GenContext *context, LLVMValueRef pointer, LLVMValueRef value, Type *type);
void llvm_store_aligned(GenContext *context, LLVMValueRef pointer, LLVMValueRef value, unsigned alignment);
void llvm_store_aligned(GenContext *context, LLVMValueRef pointer, LLVMValueRef value, AlignSize alignment);
void llvm_store_aligned_decl(GenContext *context, Decl *decl, LLVMValueRef value);
LLVMTypeRef llvm_get_twostruct(GenContext *context, LLVMTypeRef lo, LLVMTypeRef hi);

View File

@@ -2383,7 +2383,7 @@ static void debug_dump_const_initializer(ConstInitializer *init, const char *nam
}
case CONST_INIT_ARRAY_VALUE_FRAGMENT:
{
printf(" [%llu] ->\n", init->single_array_index.index);
printf(" [%llu] ->\n", (unsigned long long)init->single_array_index.index);
debug_dump_const_initializer(init->single_array_index.element, "", indent + 1);
return;
}
@@ -2411,7 +2411,7 @@ static void debug_dump_const_initializer(ConstInitializer *init, const char *nam
}
return;
case CONST_INIT_ARRAY_RANGE_ZERO:
printf(" [%llu .. %llu] = 0\n", init->array_range_zero.low, init->array_range_zero.high);
printf(" [%llu .. %llu] = 0\n", (unsigned long long)init->array_range_zero.low, (unsigned long long)init->array_range_zero.high);
return;
}
UNREACHABLE

View File

@@ -567,7 +567,7 @@ bool type_is_homogenous_aggregate(Type *type, Type **base, unsigned *elements)
return type_homogenous_aggregate_small_enough(type, *elements);
}
unsigned int type_alloca_alignment(Type *type)
AlignSize type_alloca_alignment(Type *type)
{
return type_abi_alignment(type);
}