Home | History | Annotate | Download | only in lint1

Lines Matching defs:tn

510 ic_expr(const tnode_t *tn)
514 lint_assert(is_integer(tn->tn_type->t_tspec));
516 switch (tn->tn_op) {
518 lc = ic_expr(tn->u.ops.left);
519 rc = ic_expr(tn->u.ops.right);
520 return ic_mult(tn->tn_type, lc, rc);
522 lc = ic_expr(tn->u.ops.left);
523 rc = ic_expr(tn->u.ops.right);
524 return ic_div(tn->tn_type, lc, rc);
526 lc = ic_expr(tn->u.ops.left);
527 rc = ic_expr(tn->u.ops.right);
528 return ic_mod(tn->tn_type, lc, rc);
530 lc = ic_expr(tn->u.ops.left);
531 rc = ic_expr(tn->u.ops.right);
532 return ic_plus(tn->tn_type, lc, rc);
534 if (tn->u.ops.left->tn_type->t_tspec == PTR)
535 return ic_any(tn->tn_type);
536 lc = ic_expr(tn->u.ops.left);
537 rc = ic_expr(tn->u.ops.right);
538 return ic_minus(tn->tn_type, lc, rc);
540 lc = ic_expr(tn->u.ops.left);
541 rc = ic_expr(tn->u.ops.right);
542 return ic_shl(tn->tn_type, lc, rc);
544 lc = ic_expr(tn->u.ops.left);
545 rc = ic_expr(tn->u.ops.right);
546 return ic_shr(tn->tn_type, lc, rc);
548 lc = ic_expr(tn->u.ops.left);
549 rc = ic_expr(tn->u.ops.right);
552 lc = ic_expr(tn->u.ops.left);
553 rc = ic_expr(tn->u.ops.right);
554 return ic_bitxor(tn->tn_type, lc, rc);
556 lc = ic_expr(tn->u.ops.left);
557 rc = ic_expr(tn->u.ops.right);
560 lc = ic_expr(tn->u.ops.right->u.ops.left);
561 rc = ic_expr(tn->u.ops.right->u.ops.right);
564 return ic_con(tn->tn_type, &tn->u.value);
566 if (!is_integer(tn->u.ops.left->tn_type->t_tspec))
567 return ic_any(tn->tn_type);
568 lc = ic_expr(tn->u.ops.left);
569 return ic_cvt(tn->tn_type, tn->u.ops.left->tn_type, lc);
571 return ic_any(tn->tn_type);
576 possible_bits(const tnode_t *tn)
578 return ~ic_expr(tn).bclr;
627 str_len(const tnode_t *tn)
629 const buffer *buf = tn->u.str_literals;
630 if (tn->tn_type->t_subt->t_tspec != CHAR)
875 is_out_of_char_range(const tnode_t *tn)
877 return tn->tn_op == CON &&
878 !tn->u.value.v_char_constant &&
879 !(0 <= tn->u.value.u.integer &&
880 tn->u.value.u.integer < 1 << (CHAR_SIZE - 1));
1028 apply_usual_arithmetic_conversions(op_t op, tnode_t *tn, tspec_t t)
1030 type_t *ntp = expr_dup_type(tn->tn_type);
1032 if (tn->tn_op != CON) {
1035 expr_type_name(tn), type_name(ntp));
1037 return convert(op, 0, ntp, tn);
1080 build_address(bool sys, tnode_t *tn)
1083 if (tn->tn_op == INDIR &&
1084 tn->u.ops.left->tn_type->t_tspec == PTR &&
1085 tn->u.ops.left->tn_type->t_subt == tn->tn_type) {
1086 return tn->u.ops.left;
1089 return build_op(ADDR, sys, expr_derive_type(tn->tn_type, PTR),
1090 tn, NULL);
1254 fold_constant_integer(tnode_t *tn)
1257 lint_assert(has_operands(tn));
1258 tspec_t t = tn->u.ops.left->tn_type->t_tspec;
1259 int64_t l = tn->u.ops.left->u.value.u.integer;
1260 int64_t r = is_binary(tn) ? tn->u.ops.right->u.value.u.integer : 0;
1266 uint64_t u_res = fold_unsigned_integer(tn->tn_op,
1273 if (is_binary(tn)) {
1275 (uintmax_t)l, op_name(tn->tn_op),
1279 op_name(tn->tn_op), (uintmax_t)l);
1282 warning(141, buf, expr_type_name(tn));
1287 res = fold_signed_integer(tn->tn_op,
1293 if (is_binary(tn)) {
1295 (intmax_t)l, op_name(tn->tn_op),
1297 } else if (tn->tn_op == UMINUS && l < 0) {
1302 op_name(tn->tn_op), (intmax_t)l);
1305 warning(141, buf, expr_type_name(tn));
1310 v->v_tspec = tn->tn_type->t_tspec;
1313 tnode_t *cn = build_constant(tn->tn_type, v);
1314 if (tn->u.ops.left->tn_system_dependent)
1316 if (is_binary(tn) && tn->u.ops.right->tn_system_dependent)
1542 is_null_pointer(const tnode_t *tn)
1544 tspec_t t = tn->tn_type->t_tspec;
1549 return ((t == PTR && tn->tn_type->t_subt->t_tspec == VOID)
1551 && (tn->tn_op == CON && tn->u.value.u.integer == 0);
1633 is_cast_redundant(const tnode_t *tn)
1635 const type_t *ntp = tn->tn_type, *otp = tn->u.ops.left->tn_type;
1826 check_precedence_confusion(tnode_t *tn)
1833 debug_node(tn);
1835 lint_assert(is_binary(tn));
1836 for (ln = tn->u.ops.left; ln->tn_op == CVT; ln = ln->u.ops.left)
1838 for (rn = tn->u.ops.right; rn->tn_op == CVT; rn = rn->u.ops.left)
1842 if (is_confusing_precedence(tn->tn_op, ln, &cop) ||
1843 is_confusing_precedence(tn->tn_op, rn, &cop)) {
1845 warning(169, op_name(tn->tn_op), op_name(cop));
1850 fold_constant_compare_zero(tnode_t *tn)
1854 v->v_tspec = tn->tn_type->t_tspec;
1857 lint_assert(has_operands(tn));
1858 bool l = constant_is_nonzero(tn->u.ops.left);
1859 bool r = is_binary(tn) && constant_is_nonzero(tn->u.ops.right);
1861 switch (tn->tn_op) {
1875 return build_constant(tn->tn_type, v);
1920 fold_constant_floating(tnode_t *tn)
1925 tspec_t t = tn->tn_type->t_tspec;
1931 lint_assert(has_operands(tn));
1932 lint_assert(t == tn->u.ops.left->tn_type->t_tspec);
1933 lint_assert(!is_binary(tn) || t == tn->u.ops.right->tn_type->t_tspec);
1935 long double lv = tn->u.ops.left->u.value.u.floating;
1936 long double rv = is_binary(tn) ? tn->u.ops.right->u.value.u.floating
1939 switch (tn->tn_op) {
1996 warning(142, op_name(tn->tn_op));
2001 return build_constant(tn->tn_type, v);
2005 use(const tnode_t *tn)
2007 if (tn == NULL)
2009 switch (tn->tn_op) {
2011 mark_as_used(tn->u.sym, false /* XXX */, false /* XXX */);
2017 const function_call *call = tn->u.call;
2022 lint_assert(has_operands(tn));
2023 use(tn->u.ops.left);
2024 if (is_binary(tn))
2025 use(tn->u.ops.right);
2182 build_unary(op_t op, bool sys, tnode_t *tn)
2184 return build_binary(tn, op, sys, NULL);
2263 remove_unknown_member(tnode_t *tn, sym_t *msym)
2266 error(101, type_name(tn->tn_type), msym->s_name);
2285 * struct or union specified by 'tn'.
2288 struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym)
2293 if (op == POINT && is_struct_or_union(tn->tn_type->t_tspec))
2294 tp = tn->tn_type;
2295 if (op == ARROW && tn->tn_type->t_tspec == PTR
2296 && is_struct_or_union(tn->tn_type->t_subt->t_tspec))
2297 tp = tn->tn_type->t_subt;
2307 remove_unknown_member(tn, msym);
2331 warning(103, expr_type_name(tn));
2334 error(103, expr_type_name(tn));
2336 if (!allow_c90 && tn->tn_type->t_tspec == PTR)
2338 warning(104, expr_type_name(tn));
2341 error(104, expr_type_name(tn));
2382 cconv(tnode_t *tn)
2384 if (tn->tn_type->t_tspec == ARRAY) {
2385 if (!tn->tn_lvalue) {
2390 tn = build_op(ADDR, tn->tn_sys,
2391 expr_derive_type(tn->tn_type->t_subt, PTR), tn, NULL);
2394 if (tn->tn_type->t_tspec == FUNC)
2395 tn = build_address(tn->tn_sys, tn);
2397 if (tn->tn_lvalue) {
2398 type_t *tp = expr_dup_type(tn->tn_type);
2401 tn = build_op(LOAD, tn->tn_sys, tp, tn, NULL);
2404 return tn;
2408 before_conversion(const tnode_t *tn)
2410 while (tn->tn_op == CVT && !tn->tn_cast)
2411 tn = tn->u.ops.left;
2412 return tn;
2466 typeok_incdec(op_t op, const tnode_t *tn, const type_t *tp)
2469 if (!tn->tn_lvalue) {
2470 if (tn->tn_op == CVT && tn->tn_cast &&
2471 tn->u.ops.left->tn_op == LOAD)
2485 typeok_address(op_t op, const tnode_t *tn, const type_t *tp, tspec_t t)
2489 } else if (!tn->tn_lvalue) {
2490 if (tn->tn_op == CVT && tn->tn_cast &&
2491 tn->u.ops.left->tn_op == LOAD)
2508 if (tn->tn_op == NAME && tn->u.sym->s_register) {
2510 error(113, tn->u.sym->s_name);
2972 is_direct_function_call(const tnode_t *tn, const char **out_name)
2975 if (tn->tn_op == CALL
2976 && tn->u.call->func->tn_op == ADDR
2977 && tn->u.call->func->u.ops.left->tn_op == NAME) {
2978 *out_name = tn->u.call->func->u.ops.left->u.sym->s_name;
2996 is_const_char_pointer(const tnode_t *tn)
3009 if (tn->tn_op == CVT &&
3010 tn->u.ops.left->tn_op == ADDR &&
3011 tn->u.ops.left->u.ops.left->tn_op == STRING)
3014 const type_t *tp = before_conversion(tn)->tn_type;
3021 is_const_pointer(const tnode_t *tn)
3023 const type_t *tp = before_conversion(tn)->tn_type;
3219 has_side_effect(const tnode_t *tn) /* NOLINT(misc-no-recursion) */
3221 op_t op = tn->tn_op;
3226 if (op == CVT && tn->tn_type->t_tspec == VOID)
3227 return has_side_effect(tn->u.ops.left);
3230 return has_side_effect(tn->u.ops.right);
3233 return has_side_effect(tn->u.ops.right);
3236 return has_side_effect(tn->u.ops.left) ||
3237 has_side_effect(tn
3244 is_void_cast(const tnode_t *tn)
3247 return tn->tn_op == CVT && tn->tn_cast &&
3248 tn->tn_type->t_tspec == VOID;
3252 is_local_symbol(const tnode_t *tn)
3255 return tn->tn_op == LOAD &&
3256 tn->u.ops.left->tn_op == NAME &&
3257 tn->u.ops.left->u.sym->s_scl == AUTO;
3261 is_int_constant_zero(const tnode_t *tn)
3264 return tn->tn_op == CON &&
3265 tn->tn_type->t_tspec == INT &&
3266 tn->u.value.u.integer == 0;
3270 check_null_effect(const tnode_t *tn)
3274 !has_side_effect(tn) &&
3275 !(is_void_cast(tn) && is_local_symbol(tn->u.ops.left)) &&
3276 !(is_void_cast(tn) && is_int_constant_zero(tn->u.ops.left))) {
3533 promote_c90(const tnode_t *tn, tspec_t t, bool farg)
3535 if (tn->tn_type->t_bitfield) {
3536 unsigned int width = tn->tn_type->t_bit_field_width;
3569 promote(op_t op, bool farg, tnode_t *tn)
3572 const type_t *otp = tn->tn_type;
3575 return tn;
3577 tspec_t nt = allow_c90 ? promote_c90(tn, ot, farg) : promote_trad(ot);
3579 return tn;
3586 return convert(op, 0, ntp, tn);
3591 op_t op, int arg, const type_t *tp, const tnode_t *tn)
3593 long double x = tn->u.value.u.floating;
3609 op_t op, int arg, const type_t *tp, const tnode_t *tn)
3614 query_message(2, type_name(tn->tn_type), type_name(tp));
3617 query_message(1, type_name(tn->tn_type), type_name(tp));
3618 if (tn->tn_op == CON)
3619 check_lossy_floating_to_integer_conversion(op, arg, tp, tn);
3670 tnode_t *tn)
3685 tnode_t *ptn = promote(NOOP, true, tn);
3690 warning(259, arg, expr_type_name(tn), type_name(tp));
3700 can_represent(const type_t *tp, const tnode_t *tn)
3706 integer_constraints c = ic_expr(tn);
3718 debug_node(tn);
3746 type_t *tp, tnode_t *tn)
3749 if (tn->tn_op == CON)
3767 (tn->tn_op == PLUS || tn->tn_op == MINUS || tn->tn_op == MULT ||
3768 tn->tn_op == SHL)) {
3771 op_name(tn->tn_op));
3774 if (should_warn_about_integer_conversion(tp, nt, tn, ot)) {
3777 warning(298, expr_type_name(tn), type_name(tp), arg);
3780 warning(132, expr_type_name(tn), type_name(tp));
3785 query_message(3, expr_type_name(tn), type_name(tp));
3789 convert_integer_from_pointer(op_t op, tspec_t nt, type_t *tp, tnode_t *tn)
3792 if (tn->tn_op == CON)
3894 convert_pointer_from_pointer(type_t *ntp, tnode_t *tn)
3897 const type_t *otp = tn->tn_type;
3950 convert(op_t op, int arg, type_t *tp, tnode_t *tn)
3953 tspec_t ot = tn->tn_type->t_tspec;
3956 check_prototype_conversion(arg, nt, ot, tp, tn);
3965 convert_integer_from_integer(op, arg, nt, ot, tp, tn);
3967 convert_integer_from_floating(op, arg, tp, tn);
3969 convert_integer_from_pointer(op, nt, tp, tn);
3975 type_name(tn->tn_type), type_name(tp));
3979 if (is_null_pointer(tn)) {
3982 convert_pointer_from_pointer(tp, tn);
3989 ntn->tn_sys |= tn->tn_sys;
3991 if (tn->tn_op != CON || nt == VOID) {
3992 ntn->u.ops.left = tn;
3996 &tn->u.value);
4287 tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, size_in_bytes);
4288 tn->tn_system_dependent = true;
4290 return tn;
4329 tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes);
4330 tn->tn_system_dependent = true;
4331 return tn;
4445 null_pointer_offset(tnode_t *tn)
4448 const tnode_t *n = tn;
4462 return tn;
4466 cast(tnode_t *tn, bool sys, type_t *tp)
4469 if (tn == NULL)
4472 tn = cconv(tn);
4476 tspec_t ot = tn->tn_type->t_tspec;
4485 return cast_to_union(tn, sys, tp);
4497 tn = null_pointer_offset(tn);
4503 if (!tp->t_subt->t_const && tn->tn_type->t_subt->t_const) {
4506 warning(275, type_name(tn->tn_type));
4512 && types_compatible(tp, tn->tn_type, false, false, NULL))
4514 query_message(6, expr_type_name(tn), type_name(tp));
4516 tn = convert(CVT, 0, tp, tn);
4517 tn->tn_cast = true;
4518 tn->tn_sys = sys;
4520 return tn;
4524 error(147, expr_type_name(tn), type_name(tp));
4559 type_t *tp, tnode_t *tn)
4564 if (typeok(FARG, call, arg, ln, tn)) {
4566 if (!types_compatible(tp, tn->tn_type,
4568 tn = convert(FARG, arg, tp, tn);
4571 return tn;
4702 integer_constant(tnode_t *tn, bool required)
4705 if (tn != NULL)
4706 tn = cconv(tn);
4707 if (tn != NULL)
4708 tn = promote(NOOP, false, tn);
4712 if (tn == NULL) {
4720 v->v_tspec = tn->tn_type->t_tspec;
4722 if (tn->tn_op == CON) {
4723 lint_assert(tn->tn_type->t_tspec == tn->u.value.v_tspec);
4724 if (is_integer(tn->u.value.v_tspec)) {
4726 tn->u.value.v_unsigned_since_c90;
4727 v->u.integer = tn->u.value.u.integer;
4730 v->u.integer = (int64_t)tn->u.value.u.floating;
4756 expr(tnode_t *tn, bool used, bool cond, bool free_expr, bool is_do_while,
4760 if (tn == NULL) { /* in case of errors */
4769 check_expr_misc(tn, used, cond, !cond, false, false, false);
4770 if (tn->tn_op == ASSIGN && !tn->tn_parenthesized) {
4775 if (!modtab[tn->tn_op].m_has_side_effect) {
4779 if (tn->tn_op != COMMA && !used && !cond)
4780 check_null_effect(tn);
4782 debug_node(tn);
4881 check_expr_call(const tnode_t *tn, const tnode_t *ln,
4887 outcall(tn, vctx || cond, retval_discarded);
4889 const function_call *call = tn->u.call;
4950 check_expr_misc(const tnode_t *tn, bool vctx, bool cond,
4954 if (tn == NULL)
4956 op_t op = tn->tn_op;
4960 && tn->u.call->func->tn_op == ADDR
4961 && tn->u.call->func->u.ops.left->tn_op == NAME;
4963 const function_call *call = tn->u.call;
4965 check_expr_call(tn, call->func,
4967 bool discard = op == CVT && tn->tn_type->t_tspec == VOID;
4976 lint_assert(has_operands(tn));
4977 tnode_t *ln = tn->u.ops.left;
4978 tnode_t *rn = tn->u.ops.right;
4995 if (op == COLON && tn->tn_type->t_tspec == VOID)
4997 bool discard = op == CVT && tn->tn_type->t_tspec == VOID;
5035 constant_addr(const tnode_t *tn, const sym_t **symp, ptrdiff_t *offsp)
5041 switch (tn->tn_op) {
5043 if (tn->u.ops.right->tn_op == CVT)
5044 return constant_addr(tn->u.ops.right, symp, offsp);
5045 if (tn->u.ops.right->tn_op != CON)
5050 if (tn->u.ops.left->tn_op == CON) {
5051 offs1 = (ptrdiff_t)tn->u.ops.left->u.value.u.integer;
5052 if (!constant_addr(tn->u.ops.right, &sym, &offs2))
5054 } else if (tn->u.ops.right->tn_op == CON) {
5055 offs2 = (ptrdiff_t)tn->u.ops.right->u.value.u.integer;
5056 if (tn->tn_op == MINUS)
5058 tn->u.ops.left, &sym, &offs1))
5067 if (tn->u.ops.left->tn_op == NAME) {
5068 *symp = tn->u.ops.left->u.sym;
5076 t = tn->tn_type->t_tspec;
5077 ot = tn->u.ops.left->tn_type->t_tspec;
5097 return constant_addr(tn->u.ops.left, symp, offsp);
5149 do_statement_expr(tnode_t *tn)
5153 stmt_exprs->se_sym = tn != NULL
5154 ? mktempsym(block_dup_type(tn->tn_type))
5165 tnode_t *tn;
5169 tn = NULL; /* after a syntax error */
5173 tn = build_name(se->se_sym, false);
5181 return tn;