📄 c-common.c
字号:
&& TYPE_NAME (cur_type) != 0 && TREE_CODE (TYPE_NAME (cur_type)) == TYPE_DECL) that = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (cur_type))); if (strcmp (this, that) != 0) { sprintf (message, "%s format, %s arg (arg %d)", this, that, arg_num); warning (message); } } }}/* Print a warning if a constant expression had overflow in folding. Invoke this function on every expression that the language requires to be a constant expression. Note the ANSI C standard says it is erroneous for a constant expression to overflow. */voidconstant_expression_warning (value) tree value;{ if ((TREE_CODE (value) == INTEGER_CST || TREE_CODE (value) == REAL_CST || TREE_CODE (value) == COMPLEX_CST) && TREE_CONSTANT_OVERFLOW (value) && pedantic) pedwarn ("overflow in constant expression");}/* Print a warning if an expression had overflow in folding. Invoke this function on every expression that (1) appears in the source code, and (2) might be a constant expression that overflowed, and (3) is not already checked by convert_and_check; however, do not invoke this function on operands of explicit casts. */voidoverflow_warning (value) tree value;{ if ((TREE_CODE (value) == INTEGER_CST || (TREE_CODE (value) == COMPLEX_CST && TREE_CODE (TREE_REALPART (value)) == INTEGER_CST)) && TREE_OVERFLOW (value)) { TREE_OVERFLOW (value) = 0; warning ("integer overflow in expression"); } else if ((TREE_CODE (value) == REAL_CST || (TREE_CODE (value) == COMPLEX_CST && TREE_CODE (TREE_REALPART (value)) == REAL_CST)) && TREE_OVERFLOW (value)) { TREE_OVERFLOW (value) = 0; warning ("floating-pointer overflow in expression"); }}/* Print a warning if a large constant is truncated to unsigned, or if -Wconversion is used and a constant < 0 is converted to unsigned. Invoke this function on every expression that might be implicitly converted to an unsigned type. */voidunsigned_conversion_warning (result, operand) tree result, operand;{ if (TREE_CODE (operand) == INTEGER_CST && TREE_CODE (TREE_TYPE (result)) == INTEGER_TYPE && TREE_UNSIGNED (TREE_TYPE (result)) && !int_fits_type_p (operand, TREE_TYPE (result))) { if (!int_fits_type_p (operand, signed_type (TREE_TYPE (result)))) /* This detects cases like converting -129 or 256 to unsigned char. */ warning ("large integer implicitly truncated to unsigned type"); else if (warn_conversion) warning ("negative integer implicitly converted to unsigned type"); }}/* Convert EXPR to TYPE, warning about conversion problems with constants. Invoke this function on every expression that is converted implicitly, i.e. because of language rules and not because of an explicit cast. */treeconvert_and_check (type, expr) tree type, expr;{ tree t = convert (type, expr); if (TREE_CODE (t) == INTEGER_CST) { if (TREE_OVERFLOW (t)) { TREE_OVERFLOW (t) = 0; /* Do not diagnose overflow in a constant expression merely because a conversion overflowed. */ TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (expr); /* No warning for converting 0x80000000 to int. */ if (!(TREE_UNSIGNED (type) < TREE_UNSIGNED (TREE_TYPE (expr)) && TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE && TYPE_PRECISION (type) == TYPE_PRECISION (TREE_TYPE (expr)))) /* If EXPR fits in the unsigned version of TYPE, don't warn unless pedantic. */ if (pedantic || TREE_UNSIGNED (type) || ! int_fits_type_p (expr, unsigned_type (type))) warning ("overflow in implicit constant conversion"); } else unsigned_conversion_warning (t, expr); } return t;}voidc_expand_expr_stmt (expr) tree expr;{ /* Do default conversion if safe and possibly important, in case within ({...}). */ if ((TREE_CODE (TREE_TYPE (expr)) == ARRAY_TYPE && lvalue_p (expr)) || TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE) expr = default_conversion (expr); if (TREE_TYPE (expr) != error_mark_node && TYPE_SIZE (TREE_TYPE (expr)) == 0 && TREE_CODE (TREE_TYPE (expr)) != ARRAY_TYPE) error ("expression statement has incomplete type"); expand_expr_stmt (expr);}/* Validate the expression after `case' and apply default promotions. */treecheck_case_value (value) tree value;{ if (value == NULL_TREE) return value; /* Strip NON_LVALUE_EXPRs since we aren't using as an lvalue. */ STRIP_TYPE_NOPS (value); if (TREE_CODE (value) != INTEGER_CST && value != error_mark_node) { error ("case label does not reduce to an integer constant"); value = error_mark_node; } else /* Promote char or short to int. */ value = default_conversion (value); constant_expression_warning (value); return value;}/* Return an integer type with BITS bits of precision, that is unsigned if UNSIGNEDP is nonzero, otherwise signed. */treetype_for_size (bits, unsignedp) unsigned bits; int unsignedp;{ if (bits == TYPE_PRECISION (integer_type_node)) return unsignedp ? unsigned_type_node : integer_type_node; if (bits == TYPE_PRECISION (signed_char_type_node)) return unsignedp ? unsigned_char_type_node : signed_char_type_node; if (bits == TYPE_PRECISION (short_integer_type_node)) return unsignedp ? short_unsigned_type_node : short_integer_type_node; if (bits == TYPE_PRECISION (long_integer_type_node)) return unsignedp ? long_unsigned_type_node : long_integer_type_node; if (bits == TYPE_PRECISION (long_long_integer_type_node)) return (unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node); if (bits <= TYPE_PRECISION (intQI_type_node)) return unsignedp ? unsigned_intQI_type_node : intQI_type_node; if (bits <= TYPE_PRECISION (intHI_type_node)) return unsignedp ? unsigned_intHI_type_node : intHI_type_node; if (bits <= TYPE_PRECISION (intSI_type_node)) return unsignedp ? unsigned_intSI_type_node : intSI_type_node; if (bits <= TYPE_PRECISION (intDI_type_node)) return unsignedp ? unsigned_intDI_type_node : intDI_type_node; return 0;}/* Return a data type that has machine mode MODE. If the mode is an integer, then UNSIGNEDP selects between signed and unsigned types. */treetype_for_mode (mode, unsignedp) enum machine_mode mode; int unsignedp;{ if (mode == TYPE_MODE (integer_type_node)) return unsignedp ? unsigned_type_node : integer_type_node; if (mode == TYPE_MODE (signed_char_type_node)) return unsignedp ? unsigned_char_type_node : signed_char_type_node; if (mode == TYPE_MODE (short_integer_type_node)) return unsignedp ? short_unsigned_type_node : short_integer_type_node; if (mode == TYPE_MODE (long_integer_type_node)) return unsignedp ? long_unsigned_type_node : long_integer_type_node; if (mode == TYPE_MODE (long_long_integer_type_node)) return unsignedp ? long_long_unsigned_type_node : long_long_integer_type_node; if (mode == TYPE_MODE (intQI_type_node)) return unsignedp ? unsigned_intQI_type_node : intQI_type_node; if (mode == TYPE_MODE (intHI_type_node)) return unsignedp ? unsigned_intHI_type_node : intHI_type_node; if (mode == TYPE_MODE (intSI_type_node)) return unsignedp ? unsigned_intSI_type_node : intSI_type_node; if (mode == TYPE_MODE (intDI_type_node)) return unsignedp ? unsigned_intDI_type_node : intDI_type_node; if (mode == TYPE_MODE (float_type_node)) return float_type_node; if (mode == TYPE_MODE (double_type_node)) return double_type_node; if (mode == TYPE_MODE (long_double_type_node)) return long_double_type_node; if (mode == TYPE_MODE (build_pointer_type (char_type_node))) return build_pointer_type (char_type_node); if (mode == TYPE_MODE (build_pointer_type (integer_type_node))) return build_pointer_type (integer_type_node); return 0;}/* Return the minimum number of bits needed to represent VALUE in a signed or unsigned type, UNSIGNEDP says which. */intmin_precision (value, unsignedp) tree value; int unsignedp;{ int log; /* If the value is negative, compute its negative minus 1. The latter adjustment is because the absolute value of the largest negative value is one larger than the largest positive value. This is equivalent to a bit-wise negation, so use that operation instead. */ if (tree_int_cst_sgn (value) < 0) value = fold (build1 (BIT_NOT_EXPR, TREE_TYPE (value), value)); /* Return the number of bits needed, taking into account the fact that we need one more bit for a signed than unsigned type. */ if (integer_zerop (value)) log = 0; else if (TREE_INT_CST_HIGH (value) != 0) log = HOST_BITS_PER_WIDE_INT + floor_log2 (TREE_INT_CST_HIGH (value)); else log = floor_log2 (TREE_INT_CST_LOW (value)); return log + 1 + ! unsignedp;}/* Print an error message for invalid operands to arith operation CODE. NOP_EXPR is used as a special case (see truthvalue_conversion). */voidbinary_op_error (code) enum tree_code code;{ register char *opname = "unknown"; switch (code) { case NOP_EXPR: error ("invalid truth-value expression"); return; case PLUS_EXPR: opname = "+"; break; case MINUS_EXPR: opname = "-"; break; case MULT_EXPR: opname = "*"; break; case MAX_EXPR: opname = "max"; break; case MIN_EXPR: opname = "min"; break; case EQ_EXPR: opname = "=="; break; case NE_EXPR: opname = "!="; break; case LE_EXPR: opname = "<="; break; case GE_EXPR: opname = ">="; break; case LT_EXPR: opname = "<"; break; case GT_EXPR: opname = ">"; break; case LSHIFT_EXPR: opname = "<<"; break; case RSHIFT_EXPR: opname = ">>"; break; case TRUNC_MOD_EXPR: case FLOOR_MOD_EXPR: opname = "%"; break; case TRUNC_DIV_EXPR: case FLOOR_DIV_EXPR: opname = "/"; break; case BIT_AND_EXPR: opname = "&"; break; case BIT_IOR_EXPR: opname = "|"; break; case TRUTH_ANDIF_EXPR: opname = "&&"; break; case TRUTH_ORIF_EXPR: opname = "||"; break; case BIT_XOR_EXPR: opname = "^"; break; case LROTATE_EXPR: case RROTATE_EXPR: opname = "rotate"; break; } error ("invalid operands to binary %s", opname);}/* Subroutine of build_binary_op, used for comparison operations. See if the operands have both been converted from subword integer types and, if so, perhaps change them both back to their original type. This function is also responsible for converting the two operands to the proper common type for comparison. The arguments of this function are all pointers to local variables of build_binary_op: OP0_PTR is &OP0, OP1_PTR is &OP1, RESTYPE_PTR is &RESULT_TYPE and RESCODE_PTR is &RESULTCODE. If this function returns nonzero, it means that the comparison has a constant value. What this function returns is an expression for that value. */treeshorten_compare (op0_ptr, op1_ptr, restype_ptr, rescode_ptr) tree *op0_ptr, *op1_ptr; tree *restype_ptr; enum tree_code *rescode_ptr;{ register tree type; tree op0 = *op0_ptr; tree op1 = *op1_ptr; int unsignedp0, unsignedp1; int real1, real2; tree primop0, primop1; enum tree_code code = *rescode_ptr; /* Throw away any conversions to wider types already present in the operands. */ primop0 = get_narrower (op0, &unsignedp0); primop1 = get_narrower (op1, &unsignedp1); /* Handle the case that OP0 does not *contain* a conversion but it *requires* conversion to FINAL_TYPE. */ if (op0 == primop0 && TREE_TYPE (op0) != *restype_ptr) unsignedp0 = TREE_UNSIGNED (TREE_TYPE (op0)); if (op1 == primop1 && TREE_TYPE (op1) != *restype_ptr) unsignedp1 = TREE_UNSIGNED (TREE_TYPE (op1)); /* If one of the operands must be floated, we cannot optimize. */ real1 = TREE_CODE (TREE_TYPE (primop0)) == REAL_TYPE; real2 = TREE_CODE (TREE_TYPE (primop1)) == REAL_TYPE; /* If first arg is constant, swap the args (changing operation so value is preserved), for canonicalization. Don't do this if the second arg is 0. */ if (TREE_CONSTANT (primop0) && ! integer_zerop (primop1) && ! real_zerop (primop1)) { register tree tem = primop0; register int temi = unsignedp0; primop0 = primop1; primop1 = tem; tem = op0; op0 = op1; op1 = tem; *op0_ptr = op0; *op1_ptr = op1; unsignedp0 = unsignedp1; unsignedp1 = temi; temi = real1; real1 = real2; real2 = temi; switch (code) { case LT_EXPR: code = GT_EXPR; break; case GT_EXPR: code = LT_EXPR; break; case LE_EXPR: code = GE_EXPR; break; case GE_EXPR:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -