Lines Matching defs:tn

489 ic_expr(const tnode_t *tn)
493 lint_assert(is_integer(tn->tn_type->t_tspec));
495 switch (tn->tn_op) {
497 lc = ic_expr(tn->u.ops.left);
498 rc = ic_expr(tn->u.ops.right);
499 return ic_mult(tn->tn_type, lc, rc);
501 lc = ic_expr(tn->u.ops.left);
502 rc = ic_expr(tn->u.ops.right);
503 return ic_div(tn->tn_type, lc, rc);
505 lc = ic_expr(tn->u.ops.left);
506 rc = ic_expr(tn->u.ops.right);
507 return ic_mod(tn->tn_type, lc, rc);
509 lc = ic_expr(tn->u.ops.left);
510 rc = ic_expr(tn->u.ops.right);
511 return ic_plus(tn->tn_type, lc, rc);
513 if (tn->u.ops.left->tn_type->t_tspec == PTR)
514 return ic_any(tn->tn_type);
515 lc = ic_expr(tn->u.ops.left);
516 rc = ic_expr(tn->u.ops.right);
517 return ic_minus(tn->tn_type, lc, rc);
519 lc = ic_expr(tn->u.ops.left);
520 rc = ic_expr(tn->u.ops.right);
521 return ic_shl(tn->tn_type, lc, rc);
523 lc = ic_expr(tn->u.ops.left);
524 rc = ic_expr(tn->u.ops.right);
525 return ic_shr(tn->tn_type, lc, rc);
527 lc = ic_expr(tn->u.ops.left);
528 rc = ic_expr(tn->u.ops.right);
531 lc = ic_expr(tn->u.ops.left);
532 rc = ic_expr(tn->u.ops.right);
533 return ic_bitxor(tn->tn_type, lc, rc);
535 lc = ic_expr(tn->u.ops.left);
536 rc = ic_expr(tn->u.ops.right);
539 lc = ic_expr(tn->u.ops.right->u.ops.left);
540 rc = ic_expr(tn->u.ops.right->u.ops.right);
543 return ic_con(tn->tn_type, &tn->u.value);
545 if (!is_integer(tn->u.ops.left->tn_type->t_tspec))
546 return ic_any(tn->tn_type);
547 lc = ic_expr(tn->u.ops.left);
548 return ic_cvt(tn->tn_type, tn->u.ops.left->tn_type, lc);
550 return ic_any(tn->tn_type);
555 possible_bits(const tnode_t *tn)
557 return ~ic_expr(tn).bclr;
832 is_out_of_char_range(const tnode_t *tn)
834 return tn->tn_op == CON &&
835 !tn->u.value.v_char_constant &&
836 !(0 <= tn->u.value.u.integer &&
837 tn->u.value.u.integer < 1 << (CHAR_SIZE - 1));
985 apply_usual_arithmetic_conversions(op_t op, tnode_t *tn, tspec_t t)
987 type_t *ntp = expr_dup_type(tn->tn_type);
989 if (tn->tn_op != CON) {
992 type_name(tn->tn_type), type_name(ntp));
994 return convert(op, 0, ntp, tn);
1037 build_address(bool sys, tnode_t *tn, bool force)
1041 if (!force && ((t = tn->tn_type->t_tspec) == ARRAY || t == FUNC)) {
1045 return tn;
1049 if (tn->tn_op == INDIR &&
1050 tn->u.ops.left->tn_type->t_tspec == PTR &&
1051 tn->u.ops.left->tn_type->t_subt == tn->tn_type) {
1052 return tn->u.ops.left;
1055 return build_op(ADDR, sys, expr_derive_type(tn->tn_type, PTR),
1056 tn, NULL);
1220 fold_constant_integer(tnode_t *tn)
1223 lint_assert(has_operands(tn));
1224 tspec_t t = tn->u.ops.left->tn_type->t_tspec;
1225 int64_t l = tn->u.ops.left->u.value.u.integer;
1226 int64_t r = is_binary(tn) ? tn->u.ops.right->u.value.u.integer : 0;
1232 uint64_t u_res = fold_unsigned_integer(tn->tn_op,
1239 if (is_binary(tn)) {
1241 (uintmax_t)l, op_name(tn->tn_op),
1245 op_name(tn->tn_op), (uintmax_t)l);
1248 warning(141, buf, type_name(tn->tn_type));
1253 res = fold_signed_integer(tn->tn_op,
1259 if (is_binary(tn)) {
1261 (intmax_t)l, op_name(tn->tn_op),
1263 } else if (tn->tn_op == UMINUS && l < 0) {
1268 op_name(tn->tn_op), (intmax_t)l);
1271 warning(141, buf, type_name(tn->tn_type));
1276 v->v_tspec = tn->tn_type->t_tspec;
1279 tnode_t *cn = build_constant(tn->tn_type, v);
1280 if (tn->u.ops.left->tn_system_dependent)
1282 if (is_binary(tn) && tn->u.ops.right->tn_system_dependent)
1500 is_null_pointer(const tnode_t *tn)
1502 tspec_t t = tn->tn_type->t_tspec;
1507 return ((t == PTR && tn->tn_type->t_subt->t_tspec == VOID)
1509 && (tn->tn_op == CON && tn->u.value.u.integer == 0);
1591 is_cast_redundant(const tnode_t *tn)
1593 const type_t *ntp = tn->tn_type, *otp = tn->u.ops.left->tn_type;
1784 check_precedence_confusion(tnode_t *tn)
1791 debug_node(tn);
1793 lint_assert(is_binary(tn));
1794 for (ln = tn->u.ops.left; ln->tn_op == CVT; ln = ln->u.ops.left)
1796 for (rn = tn->u.ops.right; rn->tn_op == CVT; rn = rn->u.ops.left)
1800 if (is_confusing_precedence(tn->tn_op, ln, &cop) ||
1801 is_confusing_precedence(tn->tn_op, rn, &cop)) {
1803 warning(169, op_name(tn->tn_op), op_name(cop));
1808 fold_constant_compare_zero(tnode_t *tn)
1812 v->v_tspec = tn->tn_type->t_tspec;
1815 lint_assert(has_operands(tn));
1816 bool l = constant_is_nonzero(tn->u.ops.left);
1817 bool r = is_binary(tn) && constant_is_nonzero(tn->u.ops.right);
1819 switch (tn->tn_op) {
1836 return build_constant(tn->tn_type, v);
1881 fold_constant_floating(tnode_t *tn)
1886 tspec_t t = tn->tn_type->t_tspec;
1892 lint_assert(has_operands(tn));
1893 lint_assert(t == tn->u.ops.left->tn_type->t_tspec);
1894 lint_assert(!is_binary(tn) || t == tn->u.ops.right->tn_type->t_tspec);
1896 long double lv = tn->u.ops.left->u.value.u.floating;
1897 long double rv = is_binary(tn) ? tn->u.ops.right->u.value.u.floating
1900 switch (tn->tn_op) {
1957 warning(142, op_name(tn->tn_op));
1962 return build_constant(tn->tn_type, v);
1966 use(const tnode_t *tn)
1968 if (tn == NULL)
1970 switch (tn->tn_op) {
1972 mark_as_used(tn->u.sym, false /* XXX */, false /* XXX */);
1978 const function_call *call = tn->u.call;
1983 lint_assert(has_operands(tn));
1984 use(tn->u.ops.left);
1985 if (is_binary(tn))
1986 use(tn->u.ops.right);
2147 build_unary(op_t op, bool sys, tnode_t *tn)
2149 return build_binary(tn, op, sys, NULL);
2228 remove_unknown_member(tnode_t *tn, sym_t *msym)
2231 error(101, type_name(tn->tn_type), msym->s_name);
2250 * struct or union specified by 'tn'.
2253 struct_or_union_member(tnode_t *tn, op_t op, sym_t *msym)
2258 if (op == POINT && is_struct_or_union(tn->tn_type->t_tspec))
2259 tp = tn->tn_type;
2260 if (op == ARROW && tn->tn_type->t_tspec == PTR
2261 && is_struct_or_union(tn->tn_type->t_subt->t_tspec))
2262 tp = tn->tn_type->t_subt;
2272 remove_unknown_member(tn, msym);
2296 warning(103, type_name(tn->tn_type));
2299 error(103, type_name(tn->tn_type));
2301 if (!allow_c90 && tn->tn_type->t_tspec == PTR)
2303 warning(104, type_name(tn->tn_type));
2306 error(104, type_name(tn->tn_type));
2347 cconv(tnode_t *tn)
2349 if (tn->tn_type->t_tspec == ARRAY) {
2350 if (!tn->tn_lvalue) {
2355 tn = build_op(ADDR, tn->tn_sys,
2356 expr_derive_type(tn->tn_type->t_subt, PTR), tn, NULL);
2359 if (tn->tn_type->t_tspec == FUNC)
2360 tn = build_address(tn->tn_sys, tn, true);
2362 if (tn->tn_lvalue) {
2363 type_t *tp = expr_dup_type(tn->tn_type);
2366 tn = build_op(LOAD, tn->tn_sys, tp, tn, NULL);
2369 return tn;
2373 before_conversion(const tnode_t *tn)
2375 while (tn->tn_op == CVT && !tn->tn_cast)
2376 tn = tn->u.ops.left;
2377 return tn;
2431 typeok_incdec(op_t op, const tnode_t *tn, const type_t *tp)
2434 if (!tn->tn_lvalue) {
2435 if (tn->tn_op == CVT && tn->tn_cast &&
2436 tn->u.ops.left->tn_op == LOAD)
2450 typeok_address(op_t op, const tnode_t *tn, const type_t *tp, tspec_t t)
2454 } else if (!tn->tn_lvalue) {
2455 if (tn->tn_op == CVT && tn->tn_cast &&
2456 tn->u.ops.left->tn_op == LOAD)
2473 if (tn->tn_op == NAME && tn->u.sym->s_register) {
2475 error(113, tn->u.sym->s_name);
2920 is_direct_function_call(const tnode_t *tn, const char **out_name)
2923 if (tn->tn_op == CALL
2924 && tn->u.call->func->tn_op == ADDR
2925 && tn->u.call->func->u.ops.left->tn_op == NAME) {
2926 *out_name = tn->u.call->func->u.ops.left->u.sym->s_name;
2944 is_const_char_pointer(const tnode_t *tn)
2957 if (tn->tn_op == CVT &&
2958 tn->u.ops.left->tn_op == ADDR &&
2959 tn->u.ops.left->u.ops.left->tn_op == STRING)
2962 const type_t *tp = before_conversion(tn)->tn_type;
2969 is_const_pointer(const tnode_t *tn)
2971 const type_t *tp = before_conversion(tn)->tn_type;
3165 has_side_effect(const tnode_t *tn) /* NOLINT(misc-no-recursion) */
3167 op_t op = tn->tn_op;
3172 if (op == CVT && tn->tn_type->t_tspec == VOID)
3173 return has_side_effect(tn->u.ops.left);
3175 /* XXX: Why not has_side_effect(tn->u.ops.left) as well? */
3177 return has_side_effect(tn->u.ops.right);
3179 /* XXX: Why not has_side_effect(tn->u.ops.left) as well? */
3181 return has_side_effect(tn->u.ops.right);
3184 return has_side_effect(tn->u.ops.left) ||
3185 has_side_effect(tn->u.ops.right);
3192 is_void_cast(const tnode_t *tn)
3195 return tn->tn_op == CVT && tn->tn_cast &&
3196 tn->tn_type->t_tspec == VOID;
3200 is_local_symbol(const tnode_t *tn)
3203 return tn->tn_op == LOAD &&
3204 tn->u.ops.left->tn_op == NAME &&
3205 tn->u.ops.left->u.sym->s_scl == AUTO;
3209 is_int_constant_zero(const tnode_t *tn)
3212 return tn->tn_op == CON &&
3213 tn->tn_type->t_tspec == INT &&
3214 tn->u.value.u.integer == 0;
3218 check_null_effect(const tnode_t *tn)
3222 !has_side_effect(tn) &&
3223 !(is_void_cast(tn) && is_local_symbol(tn->u.ops.left)) &&
3224 !(is_void_cast(tn) && is_int_constant_zero(tn->u.ops.left))) {
3479 promote_c90(const tnode_t *tn, tspec_t t, bool farg)
3481 if (tn->tn_type->t_bitfield) {
3482 unsigned int width = tn->tn_type->t_bit_field_width;
3515 promote(op_t op, bool farg, tnode_t *tn)
3518 const type_t *otp = tn->tn_type;
3521 return tn;
3523 tspec_t nt = allow_c90 ? promote_c90(tn, ot, farg) : promote_trad(ot);
3525 return tn;
3539 return convert(op, 0, ntp, tn);
3544 op_t op, int arg, const type_t *tp, const tnode_t *tn)
3546 long double x = tn->u.value.u.floating;
3562 op_t op, int arg, const type_t *tp, const tnode_t *tn)
3567 query_message(2, type_name(tn->tn_type), type_name(tp));
3570 query_message(1, type_name(tn->tn_type), type_name(tp));
3571 if (tn->tn_op == CON)
3572 check_lossy_floating_to_integer_conversion(op, arg, tp, tn);
3623 tnode_t *tn)
3638 tnode_t *ptn = promote(NOOP, true, tn);
3643 warning(259, arg, type_name(tn->tn_type), type_name(tp));
3653 can_represent(const type_t *tp, const tnode_t *tn)
3659 integer_constraints c = ic_expr(tn);
3671 debug_node(tn);
3699 type_t *tp, tnode_t *tn)
3702 if (tn->tn_op == CON)
3720 (tn->tn_op == PLUS || tn->tn_op == MINUS || tn->tn_op == MULT ||
3721 tn->tn_op == SHL)) {
3724 op_name(tn->tn_op));
3727 if (should_warn_about_integer_conversion(tp, nt, tn, ot)) {
3731 type_name(tn->tn_type), type_name(tp), arg);
3735 type_name(tn->tn_type), type_name(tp));
3741 query_message(3, type_name(tn->tn_type), type_name(tp));
3745 convert_integer_from_pointer(op_t op, tspec_t nt, type_t *tp, tnode_t *tn)
3748 if (tn->tn_op == CON)
3850 convert_pointer_from_pointer(type_t *ntp, tnode_t *tn)
3853 const type_t *otp = tn->tn_type;
3907 convert(op_t op, int arg, type_t *tp, tnode_t *tn)
3910 tspec_t ot = tn->tn_type->t_tspec;
3913 check_prototype_conversion(arg, nt, ot, tp, tn);
3922 convert_integer_from_integer(op, arg, nt, ot, tp, tn);
3924 convert_integer_from_floating(op, arg, tp, tn);
3926 convert_integer_from_pointer(op, nt, tp, tn);
3932 type_name(tn->tn_type), type_name(tp));
3936 if (is_null_pointer(tn)) {
3939 convert_pointer_from_pointer(tp, tn);
3946 ntn->tn_sys |= tn->tn_sys;
3948 if (tn->tn_op != CON || nt == VOID) {
3949 ntn->u.ops.left = tn;
3953 &tn->u.value);
4237 tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, size_in_bytes);
4238 tn->tn_system_dependent = true;
4240 return tn;
4279 tnode_t *tn = build_integer_constant(SIZEOF_TSPEC, offset_in_bytes);
4280 tn->tn_system_dependent = true;
4281 return tn;
4395 null_pointer_offset(tnode_t *tn)
4398 const tnode_t *n = tn;
4412 return tn;
4416 cast(tnode_t *tn, bool sys, type_t *tp)
4419 if (tn == NULL)
4422 tn = cconv(tn);
4426 tspec_t ot = tn->tn_type->t_tspec;
4435 return cast_to_union(tn, sys, tp);
4447 tn = null_pointer_offset(tn);
4453 if (!tp->t_subt->t_const && tn->tn_type->t_subt->t_const) {
4456 warning(275, type_name(tn->tn_type));
4462 && types_compatible(tp, tn->tn_type, false, false, NULL))
4464 query_message(6, type_name(tn->tn_type), type_name(tp));
4466 tn = convert(CVT, 0, tp, tn);
4467 tn->tn_cast = true;
4468 tn->tn_sys = sys;
4470 return tn;
4474 error(147, type_name(tn->tn_type), type_name(tp));
4511 tnode_t *tn) /* argument */
4516 if (typeok(FARG, n, ln, tn)) {
4518 if (!types_compatible(tp, tn->tn_type,
4520 tn = convert(FARG, n, tp, tn);
4523 return tn;
4620 integer_constant(tnode_t *tn, bool required)
4623 if (tn != NULL)
4624 tn = cconv(tn);
4625 if (tn != NULL)
4626 tn = promote(NOOP, false, tn);
4630 if (tn == NULL) {
4638 v->v_tspec = tn->tn_type->t_tspec;
4640 if (tn->tn_op == CON) {
4641 lint_assert(tn->tn_type->t_tspec == tn->u.value.v_tspec);
4642 if (is_integer(tn->u.value.v_tspec)) {
4644 tn->u.value.v_unsigned_since_c90;
4645 v->u.integer = tn->u.value.u.integer;
4648 v->u.integer = (int64_t)tn->u.value.u.floating;
4666 is_constcond_false(const tnode_t *tn, tspec_t t)
4669 tn->tn_op == CON && tn->u.value.u.integer == 0;
4681 expr(tnode_t *tn, bool vctx, bool cond, bool dofreeblk, bool is_do_while,
4685 if (tn == NULL) { /* in case of errors */
4694 check_expr_misc(tn, vctx, cond, !cond, false, false, false);
4695 if (tn->tn_op == ASSIGN && !tn->tn_parenthesized) {
4699 } else if (tn->tn_op == CON) {
4701 !tn->tn_system_dependent &&
4703 is_constcond_false(tn, tn->tn_type->t_tspec)))
4707 if (!modtab[tn->tn_op].m_has_side_effect) {
4711 if (tn->tn_op != COMMA && !vctx && !cond)
4712 check_null_effect(tn);
4714 debug_node(tn);
4813 check_expr_call(const tnode_t *tn, const tnode_t *ln,
4819 outcall(tn, vctx || cond, retval_discarded);
4821 const function_call *call = tn->u.call;
4882 check_expr_misc(const tnode_t *tn, bool vctx, bool cond,
4886 if (tn == NULL)
4888 op_t op = tn->tn_op;
4892 && tn->u.call->func->tn_op == ADDR
4893 && tn->u.call->func->u.ops.left->tn_op == NAME;
4895 const function_call *call = tn->u.call;
4897 check_expr_call(tn, call->func,
4899 bool discard = op == CVT && tn->tn_type->t_tspec == VOID;
4908 lint_assert(has_operands(tn));
4909 tnode_t *ln = tn->u.ops.left;
4910 tnode_t *rn = tn->u.ops.right;
4927 if (op == COLON && tn->tn_type->t_tspec == VOID)
4929 bool discard = op == CVT && tn->tn_type->t_tspec == VOID;
4967 constant_addr(const tnode_t *tn, const sym_t **symp, ptrdiff_t *offsp)
4973 switch (tn->tn_op) {
4975 if (tn->u.ops.right->tn_op == CVT)
4976 return constant_addr(tn->u.ops.right, symp, offsp);
4977 else if (tn->u.ops.right->tn_op != CON)
4982 if (tn->u.ops.left->tn_op == CON) {
4983 offs1 = (ptrdiff_t)tn->u.ops.left->u.value.u.integer;
4984 if (!constant_addr(tn->u.ops.right, &sym, &offs2))
4986 } else if (tn->u.ops.right->tn_op == CON) {
4987 offs2 = (ptrdiff_t)tn->u.ops.right->u.value.u.integer;
4988 if (tn->tn_op == MINUS)
4990 if (!constant_addr(tn->u.ops.left, &sym, &offs1))
4999 if (tn->u.ops.left->tn_op == NAME) {
5000 *symp = tn->u.ops.left->u.sym;
5007 * 'tn->u.ops.left->tn_op == STRING'.
5014 t = tn->tn_type->t_tspec;
5015 ot = tn->u.ops.left->tn_type->t_tspec;
5035 return constant_addr(tn->u.ops.left, symp, offsp);
5087 do_statement_expr(tnode_t *tn)
5091 stmt_exprs->se_sym = tn != NULL
5092 ? mktempsym(block_dup_type(tn->tn_type))
5103 tnode_t *tn;
5107 tn = NULL; /* after a syntax error */
5111 tn = build_name(se->se_sym, false);
5119 return tn;