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...@@ -776,8 +776,8 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type
776 };776 };
777777
778 if (operand_type->id == ZigTypeIdVector) {778 if (operand_type->id == ZigTypeIdVector) {
779 sprintf(fn_name, "llvm.%s.with.overflow.v%" PRIu64 "i%" PRIu32, signed_str,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);780 operand_type->data.vector.len, int_type->data.integral.bit_count);
781781
782 LLVMTypeRef return_elem_types[] = {782 LLVMTypeRef return_elem_types[] = {
783 get_llvm_type(g, operand_type),783 get_llvm_type(g, operand_type),
...@@ -789,7 +789,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type...@@ -789,7 +789,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *operand_type
789 assert(LLVMGetIntrinsicID(fn_val));789 assert(LLVMGetIntrinsicID(fn_val));
790 return fn_val;790 return fn_val;
791 } else {791 } 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
794 LLVMTypeRef return_elem_types[] = {794 LLVMTypeRef return_elem_types[] = {
795 get_llvm_type(g, operand_type),795 get_llvm_type(g, operand_type),
...@@ -882,9 +882,9 @@ static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn...@@ -882,9 +882,9 @@ static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn
882882
883 char fn_name[64];883 char fn_name[64];
884 if (is_vector)884 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);
886 else886 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);
888 LLVMTypeRef float_type_ref = get_llvm_type(g, type_entry);888 LLVMTypeRef float_type_ref = get_llvm_type(g, type_entry);
889 LLVMTypeRef return_elem_types[3] = { float_type_ref, float_type_ref, float_type_ref };889 LLVMTypeRef return_elem_types[3] = { float_type_ref, float_type_ref, float_type_ref };
890 LLVMTypeRef fn_type = LLVMFunctionType(float_type_ref, return_elem_types, num_args, false);890 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_...@@ -1677,11 +1677,11 @@ static LLVMValueRef gen_soft_float_widen_or_shorten(CodeGen *g, ZigType *actual_
16771677
1678 char fn_name[64];1678 char fn_name[64];
1679 if (wanted_bits < actual_bits) {1679 if (wanted_bits < actual_bits) {
1680 sprintf(fn_name, "__trunc%sf%sf2",1680 snprintf(fn_name, sizeof(fn_name), "__trunc%sf%sf2",
1681 get_compiler_rt_type_abbrev(scalar_actual_type),1681 get_compiler_rt_type_abbrev(scalar_actual_type),
1682 get_compiler_rt_type_abbrev(scalar_wanted_type));1682 get_compiler_rt_type_abbrev(scalar_wanted_type));
1683 } else {1683 } else {
1684 sprintf(fn_name, "__extend%sf%sf2",1684 snprintf(fn_name, sizeof(fn_name), "__extend%sf%sf2",
1685 get_compiler_rt_type_abbrev(scalar_actual_type),1685 get_compiler_rt_type_abbrev(scalar_actual_type),
1686 get_compiler_rt_type_abbrev(scalar_wanted_type));1686 get_compiler_rt_type_abbrev(scalar_wanted_type));
1687 }1687 }
...@@ -3008,8 +3008,8 @@ static LLVMValueRef gen_soft_float_un_op(CodeGen *g, LLVMValueRef op, ZigType *o...@@ -3008,8 +3008,8 @@ static LLVMValueRef gen_soft_float_un_op(CodeGen *g, LLVMValueRef op, ZigType *o
3008 ZigType *scalar_type = operand_type->id == ZigTypeIdVector ? operand_type->data.vector.elem_type : operand_type;3008 ZigType *scalar_type = operand_type->id == ZigTypeIdVector ? operand_type->data.vector.elem_type : operand_type;
30093009
3010 char fn_name[64];3010 char fn_name[64];
3011 sprintf(fn_name, "%s%s%s", libc_float_prefix(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));3012 float_un_op_to_name(op_id), libc_float_suffix(g, scalar_type));
3013 LLVMValueRef func_ref = get_soft_float_fn(g, fn_name, 1, scalar_type->llvm_type, scalar_type->llvm_type);3013 LLVMValueRef func_ref = get_soft_float_fn(g, fn_name, 1, scalar_type->llvm_type, scalar_type->llvm_type);
30143014
3015 LLVMValueRef result;3015 LLVMValueRef result;
...@@ -3389,9 +3389,9 @@ static LLVMValueRef gen_soft_int_to_float_op(CodeGen *g, LLVMValueRef value_ref,...@@ -3389,9 +3389,9 @@ static LLVMValueRef gen_soft_int_to_float_op(CodeGen *g, LLVMValueRef value_ref,
33893389
3390 char fn_name[64];3390 char fn_name[64];
3391 if (is_signed) {3391 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);
3393 } else {3393 } 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);
3395 }3395 }
33963396
3397 int param_count = 1;3397 int param_count = 1;
...@@ -3439,9 +3439,9 @@ static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref,...@@ -3439,9 +3439,9 @@ static LLVMValueRef gen_soft_float_to_int_op(CodeGen *g, LLVMValueRef value_ref,
34393439
3440 char fn_name[64];3440 char fn_name[64];
3441 if (is_signed) {3441 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);
3443 } else {3443 } 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);
3445 }3445 }
34463446
3447 int param_count = 1;3447 int param_count = 1;
...@@ -3512,58 +3512,58 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL...@@ -3512,58 +3512,58 @@ static LLVMValueRef gen_soft_float_bin_op(CodeGen *g, LLVMValueRef op1_value, LL
3512 zig_unreachable();3512 zig_unreachable();
3513 case IrBinOpCmpEq:3513 case IrBinOpCmpEq:
3514 return_type = g->builtin_types.entry_i32->llvm_type;3514 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);
3516 res_icmp = EQ_ZERO;3516 res_icmp = EQ_ZERO;
3517 break;3517 break;
3518 case IrBinOpCmpNotEq:3518 case IrBinOpCmpNotEq:
3519 return_type = g->builtin_types.entry_i32->llvm_type;3519 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);
3521 res_icmp = NE_ZERO;3521 res_icmp = NE_ZERO;
3522 break;3522 break;
3523 case IrBinOpCmpLessOrEq:3523 case IrBinOpCmpLessOrEq:
3524 return_type = g->builtin_types.entry_i32->llvm_type;3524 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);
3526 res_icmp = LE_ZERO;3526 res_icmp = LE_ZERO;
3527 break;3527 break;
3528 case IrBinOpCmpLessThan:3528 case IrBinOpCmpLessThan:
3529 return_type = g->builtin_types.entry_i32->llvm_type;3529 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);
3531 res_icmp = EQ_NEG;3531 res_icmp = EQ_NEG;
3532 break;3532 break;
3533 case IrBinOpCmpGreaterOrEq:3533 case IrBinOpCmpGreaterOrEq:
3534 return_type = g->builtin_types.entry_i32->llvm_type;3534 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);
3536 res_icmp = GE_ZERO;3536 res_icmp = GE_ZERO;
3537 break;3537 break;
3538 case IrBinOpCmpGreaterThan:3538 case IrBinOpCmpGreaterThan:
3539 return_type = g->builtin_types.entry_i32->llvm_type;3539 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);
3541 res_icmp = EQ_ONE;3541 res_icmp = EQ_ONE;
3542 break;3542 break;
3543 case IrBinOpMaximum:3543 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);
3545 break;3545 break;
3546 case IrBinOpMinimum:3546 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);
3548 break;3548 break;
3549 case IrBinOpMult:3549 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);
3551 break;3551 break;
3552 case IrBinOpAdd:3552 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);
3554 break;3554 break;
3555 case IrBinOpSub:3555 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);
3557 break;3557 break;
3558 case IrBinOpDivUnspecified:3558 case IrBinOpDivUnspecified:
3559 case IrBinOpDivExact:3559 case IrBinOpDivExact:
3560 case IrBinOpDivTrunc:3560 case IrBinOpDivTrunc:
3561 case IrBinOpDivFloor:3561 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);
3563 break;3563 break;
3564 case IrBinOpRemRem:3564 case IrBinOpRemRem:
3565 case IrBinOpRemMod:3565 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);
3567 break;3567 break;
3568 default:3568 default:
3569 zig_unreachable();3569 zig_unreachable();
...@@ -5815,9 +5815,9 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn...@@ -5815,9 +5815,9 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *expr_type, BuiltinFn
58155815
5816 char llvm_name[64];5816 char llvm_name[64];
5817 if (is_vector)5817 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);
5819 else5819 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);
5821 LLVMTypeRef param_types[] = {5821 LLVMTypeRef param_types[] = {
5822 get_llvm_type(g, expr_type),5822 get_llvm_type(g, expr_type),
5823 LLVMInt1Type(),5823 LLVMInt1Type(),