authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2022-07-10 22:09:46+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-10 22:59:25-04:00
logf3333a56e8452c16ad30da99f8e4a62a16e58a03
tree84fe45809a5f7fa7955437fe10f73ffc6831c578
parentb9ed07227832a10e5a18667d6c7cbdffd2018da7

stage1/codegen: replace sprintf() with snprintf()

Calling sprintf() is now triggering an error on Xcode 14. Using snprintf() is generally not a bad idea anyway.

1 files changed, 28 insertions(+), 28 deletions(-)

src/stage1/codegen.cpp+28-28
......@@ -776,8 +776,8 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type
776776 };
777777
778778 if (operand_type->id == ZigTypeIdVector) {
779 sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu64 "i%" PRIu32, signed_str,
780 operand_type->data.vector.len, int_type->data.integral.bit_count);
779 snprintf(fn_name, sizeof(fn_name), "llvm.%s.with.overflow.v%" PRIu64 "i%" PRIu32, signed_str,
780 operand_type->data.vector.len, int_type->data.integral.bit_count);
781781
782782 LLVMTypeRef return_elem_types[] = {
783783 get_llvm_type(g, operand_type),
......@@ -789,7 +789,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type
789789 assert(LLVMGetIntrinsicID(fn_val));
790790 return fn_val;
791791 } else {
792 sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, int_type->data.integral.bit_count);
792 snprintf(fn_name, sizeof(fn_name), "llvm.%s.with.overflow.i%" PRIu32, signed_str, int_type->data.integral.bit_count);
793793
794794 LLVMTypeRef return_elem_types[] = {
795795 get_llvm_type(g, operand_type),
......@@ -882,9 +882,9 @@ static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn
882882
883883 char fn_name[64];
884884 if (is_vector)
885 sprintf(fn_name, "llvm.%s.v%" PRIu32 "f%" PRIu32, name, key.data.floating.vector_len, key.data.floating.bit_count);
885 snprintf(fn_name, sizeof(fn_name), "llvm.%s.v%" PRIu32 "f%" PRIu32, name, key.data.floating.vector_len, key.data.floating.bit_count);
886886 else
887 sprintf(fn_name, "llvm.%s.f%" PRIu32, name, key.data.floating.bit_count);
887 snprintf(fn_name, sizeof(fn_name), "llvm.%s.f%" PRIu32, name, key.data.floating.bit_count);
888888 LLVMTypeRef float_type_ref = get_llvm_type(g, type_entry);
889889 LLVMTypeRef return_elem_types[3] = { float_type_ref, float_type_ref, float_type_ref };
890890 LLVMTypeRef fn_type = LLVMFunctionType(float_type_ref, return_elem_types, num_args, false);
......@@ -1677,11 +1677,11 @@ static LLVMValueRef gen_soft_float_widen_or_shorten(CodeGen *g, ZigType *actual_
16771677
16781678 char fn_name[64];
16791679 if (wanted_bits < actual_bits) {
1680 sprintf(fn_name, "__trunc%sf%sf2",
1680 snprintf(fn_name, sizeof(fn_name), "__trunc%sf%sf2",
16811681 get_compiler_rt_type_abbrev(scalar_actual_type),
16821682 get_compiler_rt_type_abbrev(scalar_wanted_type));
16831683 } else {
1684 sprintf(fn_name, "__extend%sf%sf2",
1684 snprintf(fn_name, sizeof(fn_name), "__extend%sf%sf2",
16851685 get_compiler_rt_type_abbrev(scalar_actual_type),
16861686 get_compiler_rt_type_abbrev(scalar_wanted_type));
16871687 }
......@@ -3008,8 +3008,8 @@ static LLVMValueRef gen_soft_float_un_op(CodeGen *g, LLVMValueRef op, ZigType *o
30083008 ZigType *scalar_type = operand_type->id == ZigTypeIdVector ? operand_type->data.vector.elem_type : operand_type;
30093009
30103010 char fn_name[64];
3011 sprintf(fn_name, "%s%s%s", libc_float_prefix(g, scalar_type),
3012 float_un_op_to_name(op_id), libc_float_suffix(g, scalar_type));
3011 snprintf(fn_name, sizeof(fn_name), "%s%s%s", libc_float_prefix(g, scalar_type),
3012 float_un_op_to_name(op_id), libc_float_suffix(g, scalar_type));
30133013 LLVMValueRef func_ref = get_soft_float_fn(g, fn_name, 1, scalar_type->llvm_type, scalar_type->llvm_type);
30143014
30153015 LLVMValueRef result;
......@@ -3389,9 +3389,9 @@ static LLVMValueRef gen_soft_int_to_float_op(CodeGen *g, LLVMValueRef value_ref,
33893389
33903390 char fn_name[64];
33913391 if (is_signed) {
3392 sprintf(fn_name, "__float%si%sf", int_compiler_rt_type_abbrev, float_compiler_rt_type_abbrev);
3392 snprintf(fn_name, sizeof(fn_name), "__float%si%sf", int_compiler_rt_type_abbrev, float_compiler_rt_type_abbrev);
33933393 } else {
3394 sprintf(fn_name, "__floatun%si%sf", int_compiler_rt_type_abbrev, float_compiler_rt_type_abbrev);
3394 snprintf(fn_name, sizeof(fn_name), "__floatun%si%sf", int_compiler_rt_type_abbrev, float_compiler_rt_type_abbrev);
33953395 }
33963396
33973397 int param_count = 1;
......@@ -3439,9 +3439,9 @@ static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref,
34393439
34403440 char fn_name[64];
34413441 if (is_signed) {
3442 sprintf(fn_name, "__fix%sf%si", float_compiler_rt_type_abbrev, int_compiler_rt_type_abbrev);
3442 snprintf(fn_name, sizeof(fn_name), "__fix%sf%si", float_compiler_rt_type_abbrev, int_compiler_rt_type_abbrev);
34433443 } else {
3444 sprintf(fn_name, "__fixuns%sf%si", float_compiler_rt_type_abbrev, int_compiler_rt_type_abbrev);
3444 snprintf(fn_name, sizeof(fn_name), "__fixuns%sf%si", float_compiler_rt_type_abbrev, int_compiler_rt_type_abbrev);
34453445 }
34463446
34473447 int param_count = 1;
......@@ -3512,58 +3512,58 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL
35123512 zig_unreachable();
35133513 case IrBinOpCmpEq:
35143514 return_type = g->builtin_types.entry_i32->llvm_type;
3515 sprintf(fn_name, "__eq%sf2", compiler_rt_type_abbrev);
3515 snprintf(fn_name, sizeof(fn_name), "__eq%sf2", compiler_rt_type_abbrev);
35163516 res_icmp = EQ_ZERO;
35173517 break;
35183518 case IrBinOpCmpNotEq:
35193519 return_type = g->builtin_types.entry_i32->llvm_type;
3520 sprintf(fn_name, "__ne%sf2", compiler_rt_type_abbrev);
3520 snprintf(fn_name, sizeof(fn_name), "__ne%sf2", compiler_rt_type_abbrev);
35213521 res_icmp = NE_ZERO;
35223522 break;
35233523 case IrBinOpCmpLessOrEq:
35243524 return_type = g->builtin_types.entry_i32->llvm_type;
3525 sprintf(fn_name, "__le%sf2", compiler_rt_type_abbrev);
3525 snprintf(fn_name, sizeof(fn_name), "__le%sf2", compiler_rt_type_abbrev);
35263526 res_icmp = LE_ZERO;
35273527 break;
35283528 case IrBinOpCmpLessThan:
35293529 return_type = g->builtin_types.entry_i32->llvm_type;
3530 sprintf(fn_name, "__le%sf2", compiler_rt_type_abbrev);
3530 snprintf(fn_name, sizeof(fn_name), "__le%sf2", compiler_rt_type_abbrev);
35313531 res_icmp = EQ_NEG;
35323532 break;
35333533 case IrBinOpCmpGreaterOrEq:
35343534 return_type = g->builtin_types.entry_i32->llvm_type;
3535 sprintf(fn_name, "__ge%sf2", compiler_rt_type_abbrev);
3535 snprintf(fn_name, sizeof(fn_name), "__ge%sf2", compiler_rt_type_abbrev);
35363536 res_icmp = GE_ZERO;
35373537 break;
35383538 case IrBinOpCmpGreaterThan:
35393539 return_type = g->builtin_types.entry_i32->llvm_type;
3540 sprintf(fn_name, "__ge%sf2", compiler_rt_type_abbrev);
3540 snprintf(fn_name, sizeof(fn_name), "__ge%sf2", compiler_rt_type_abbrev);
35413541 res_icmp = EQ_ONE;
35423542 break;
35433543 case IrBinOpMaximum:
3544 sprintf(fn_name, "%sfmax%s", math_float_prefix, math_float_suffix);
3544 snprintf(fn_name, sizeof(fn_name), "%sfmax%s", math_float_prefix, math_float_suffix);
35453545 break;
35463546 case IrBinOpMinimum:
3547 sprintf(fn_name, "%sfmin%s", math_float_prefix, math_float_suffix);
3547 snprintf(fn_name, sizeof(fn_name), "%sfmin%s", math_float_prefix, math_float_suffix);
35483548 break;
35493549 case IrBinOpMult:
3550 sprintf(fn_name, "__mul%sf3", compiler_rt_type_abbrev);
3550 snprintf(fn_name, sizeof(fn_name), "__mul%sf3", compiler_rt_type_abbrev);
35513551 break;
35523552 case IrBinOpAdd:
3553 sprintf(fn_name, "__add%sf3", compiler_rt_type_abbrev);
3553 snprintf(fn_name, sizeof(fn_name), "__add%sf3", compiler_rt_type_abbrev);
35543554 break;
35553555 case IrBinOpSub:
3556 sprintf(fn_name, "__sub%sf3", compiler_rt_type_abbrev);
3556 snprintf(fn_name, sizeof(fn_name), "__sub%sf3", compiler_rt_type_abbrev);
35573557 break;
35583558 case IrBinOpDivUnspecified:
35593559 case IrBinOpDivExact:
35603560 case IrBinOpDivTrunc:
35613561 case IrBinOpDivFloor:
3562 sprintf(fn_name, "__div%sf3", compiler_rt_type_abbrev);
3562 snprintf(fn_name, sizeof(fn_name), "__div%sf3", compiler_rt_type_abbrev);
35633563 break;
35643564 case IrBinOpRemRem:
35653565 case IrBinOpRemMod:
3566 sprintf(fn_name, "%sfmod%s", math_float_prefix, math_float_suffix);
3566 snprintf(fn_name, sizeof(fn_name), "%sfmod%s", math_float_prefix, math_float_suffix);
35673567 break;
35683568 default:
35693569 zig_unreachable();
......@@ -5815,9 +5815,9 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
58155815
58165816 char llvm_name[64];
58175817 if (is_vector)
5818 sprintf(llvm_name, "llvm.%s.v%" PRIu32 "i%" PRIu32, fn_name, vector_len, int_type->data.integral.bit_count);
5818 snprintf(llvm_name, sizeof(llvm_name), "llvm.%s.v%" PRIu32 "i%" PRIu32, fn_name, vector_len, int_type->data.integral.bit_count);
58195819 else
5820 sprintf(llvm_name, "llvm.%s.i%" PRIu32, fn_name, int_type->data.integral.bit_count);
5820 snprintf(llvm_name, sizeof(llvm_name), "llvm.%s.i%" PRIu32, fn_name, int_type->data.integral.bit_count);
58215821 LLVMTypeRef param_types[] = {
58225822 get_llvm_type(g, expr_type),
58235823 LLVMInt1Type(),