diff --git a/CMakeLists.txt b/CMakeLists.txt index 43d6be5d6..6a8cff96a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/src/compiler/compiler_internal.h b/src/compiler/compiler_internal.h index 1cbd69c66..8bf63318f 100644 --- a/src/compiler/compiler_internal.h +++ b/src/compiler/compiler_internal.h @@ -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); diff --git a/src/compiler/llvm_codegen.c b/src/compiler/llvm_codegen.c index 11cb9ec04..c647b21ab 100644 --- a/src/compiler/llvm_codegen.c +++ b/src/compiler/llvm_codegen.c @@ -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; } diff --git a/src/compiler/llvm_codegen_internal.h b/src/compiler/llvm_codegen_internal.h index 8ffec04ef..2994bd437 100644 --- a/src/compiler/llvm_codegen_internal.h +++ b/src/compiler/llvm_codegen_internal.h @@ -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); diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index bd9f52a5f..7fa5d5f0c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -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 diff --git a/src/compiler/types.c b/src/compiler/types.c index 658083860..4f047bc0a 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -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); }