Mercurial > hg > CbC > CbC_gcc
comparison gcc/calls.c @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children | 351920fa3827 |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* Convert function calls to rtl insns, for GNU C compiler. | 1 /* Convert function calls to rtl insns, for GNU C compiler. |
2 Copyright (C) 1989-2018 Free Software Foundation, Inc. | 2 Copyright (C) 1989-2020 Free Software Foundation, Inc. |
3 | 3 |
4 This file is part of GCC. | 4 This file is part of GCC. |
5 | 5 |
6 GCC is free software; you can redistribute it and/or modify it under | 6 GCC is free software; you can redistribute it and/or modify it under |
7 the terms of the GNU General Public License as published by the Free | 7 the terms of the GNU General Public License as published by the Free |
50 #include "tree-vrp.h" | 50 #include "tree-vrp.h" |
51 #include "tree-ssanames.h" | 51 #include "tree-ssanames.h" |
52 #include "tree-ssa-strlen.h" | 52 #include "tree-ssa-strlen.h" |
53 #include "intl.h" | 53 #include "intl.h" |
54 #include "stringpool.h" | 54 #include "stringpool.h" |
55 #include "hash-map.h" | |
56 #include "hash-traits.h" | |
55 #include "attribs.h" | 57 #include "attribs.h" |
56 #include "builtins.h" | 58 #include "builtins.h" |
57 #include "gimple-fold.h" | 59 #include "gimple-fold.h" |
58 | 60 |
59 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */ | 61 /* Like PREFERRED_STACK_BOUNDARY but in units of bytes, not bits. */ |
80 register windows. */ | 82 register windows. */ |
81 rtx tail_call_reg; | 83 rtx tail_call_reg; |
82 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct | 84 /* If REG is a PARALLEL, this is a copy of VALUE pulled into the correct |
83 form for emit_group_move. */ | 85 form for emit_group_move. */ |
84 rtx parallel_value; | 86 rtx parallel_value; |
85 /* If value is passed in neither reg nor stack, this field holds a number | |
86 of a special slot to be used. */ | |
87 rtx special_slot; | |
88 /* For pointer bounds hold an index of parm bounds are bound to. -1 if | |
89 there is no such pointer. */ | |
90 int pointer_arg; | |
91 /* If pointer_arg refers a structure, then pointer_offset holds an offset | |
92 of a pointer in this structure. */ | |
93 int pointer_offset; | |
94 /* If REG was promoted from the actual mode of the argument expression, | 87 /* If REG was promoted from the actual mode of the argument expression, |
95 indicates whether the promotion is sign- or zero-extended. */ | 88 indicates whether the promotion is sign- or zero-extended. */ |
96 int unsignedp; | 89 int unsignedp; |
97 /* Number of bytes to put in registers. 0 means put the whole arg | 90 /* Number of bytes to put in registers. 0 means put the whole arg |
98 in registers. Also 0 if not passed in registers. */ | 91 in registers. Also 0 if not passed in registers. */ |
353 | 346 |
354 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value. | 347 STRUCT_VALUE_SIZE is the number of bytes wanted in a structure value. |
355 It is zero if this call doesn't want a structure value. | 348 It is zero if this call doesn't want a structure value. |
356 | 349 |
357 NEXT_ARG_REG is the rtx that results from executing | 350 NEXT_ARG_REG is the rtx that results from executing |
358 targetm.calls.function_arg (&args_so_far, VOIDmode, void_type_node, true) | 351 targetm.calls.function_arg (&args_so_far, |
352 function_arg_info::end_marker ()); | |
359 just after all the args have had their registers assigned. | 353 just after all the args have had their registers assigned. |
360 This could be whatever you like, but normally it is the first | 354 This could be whatever you like, but normally it is the first |
361 arg-register beyond those used for args in this call, | 355 arg-register beyond those used for args in this call, |
362 or 0 if all the arg-registers are used in this call. | 356 or 0 if all the arg-registers are used in this call. |
363 It is passed on to `gen_call' so you can put this info in the call insn. | 357 It is passed on to `gen_call' so you can put this info in the call insn. |
590 static int | 584 static int |
591 special_function_p (const_tree fndecl, int flags) | 585 special_function_p (const_tree fndecl, int flags) |
592 { | 586 { |
593 tree name_decl = DECL_NAME (fndecl); | 587 tree name_decl = DECL_NAME (fndecl); |
594 | 588 |
595 if (fndecl && name_decl | 589 if (maybe_special_function_p (fndecl) |
596 && IDENTIFIER_LENGTH (name_decl) <= 11 | 590 && IDENTIFIER_LENGTH (name_decl) <= 11) |
597 /* Exclude functions not at the file scope, or not `extern', | |
598 since they are not the magic functions we would otherwise | |
599 think they are. | |
600 FIXME: this should be handled with attributes, not with this | |
601 hacky imitation of DECL_ASSEMBLER_NAME. It's (also) wrong | |
602 because you can declare fork() inside a function if you | |
603 wish. */ | |
604 && (DECL_CONTEXT (fndecl) == NULL_TREE | |
605 || TREE_CODE (DECL_CONTEXT (fndecl)) == TRANSLATION_UNIT_DECL) | |
606 && TREE_PUBLIC (fndecl)) | |
607 { | 591 { |
608 const char *name = IDENTIFIER_POINTER (name_decl); | 592 const char *name = IDENTIFIER_POINTER (name_decl); |
609 const char *tname = name; | 593 const char *tname = name; |
610 | 594 |
611 /* We assume that alloca will always be called by name. It | 595 /* We assume that alloca will always be called by name. It |
904 } | 888 } |
905 | 889 |
906 return flags; | 890 return flags; |
907 } | 891 } |
908 | 892 |
909 /* Return true if TYPE should be passed by invisible reference. */ | 893 /* Return true if ARG should be passed by invisible reference. */ |
910 | 894 |
911 bool | 895 bool |
912 pass_by_reference (CUMULATIVE_ARGS *ca, machine_mode mode, | 896 pass_by_reference (CUMULATIVE_ARGS *ca, function_arg_info arg) |
913 tree type, bool named_arg) | |
914 { | 897 { |
915 if (type) | 898 if (tree type = arg.type) |
916 { | 899 { |
917 /* If this type contains non-trivial constructors, then it is | 900 /* If this type contains non-trivial constructors, then it is |
918 forbidden for the middle-end to create any new copies. */ | 901 forbidden for the middle-end to create any new copies. */ |
919 if (TREE_ADDRESSABLE (type)) | 902 if (TREE_ADDRESSABLE (type)) |
920 return true; | 903 return true; |
921 | 904 |
922 /* GCC post 3.4 passes *all* variable sized types by reference. */ | 905 /* GCC post 3.4 passes *all* variable sized types by reference. */ |
923 if (!TYPE_SIZE (type) || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) | 906 if (!TYPE_SIZE (type) || !poly_int_tree_p (TYPE_SIZE (type))) |
924 return true; | 907 return true; |
925 | 908 |
926 /* If a record type should be passed the same as its first (and only) | 909 /* If a record type should be passed the same as its first (and only) |
927 member, use the type and mode of that member. */ | 910 member, use the type and mode of that member. */ |
928 if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type)) | 911 if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type)) |
929 { | 912 { |
930 type = TREE_TYPE (first_field (type)); | 913 arg.type = TREE_TYPE (first_field (type)); |
931 mode = TYPE_MODE (type); | 914 arg.mode = TYPE_MODE (arg.type); |
932 } | 915 } |
933 } | 916 } |
934 | 917 |
935 return targetm.calls.pass_by_reference (pack_cumulative_args (ca), mode, | 918 return targetm.calls.pass_by_reference (pack_cumulative_args (ca), arg); |
936 type, named_arg); | |
937 } | 919 } |
938 | 920 |
939 /* Return true if TYPE, which is passed by reference, should be callee | 921 /* Return true if TYPE should be passed by reference when passed to |
922 the "..." arguments of a function. */ | |
923 | |
924 bool | |
925 pass_va_arg_by_reference (tree type) | |
926 { | |
927 return pass_by_reference (NULL, function_arg_info (type, /*named=*/false)); | |
928 } | |
929 | |
930 /* Decide whether ARG, which occurs in the state described by CA, | |
931 should be passed by reference. Return true if so and update | |
932 ARG accordingly. */ | |
933 | |
934 bool | |
935 apply_pass_by_reference_rules (CUMULATIVE_ARGS *ca, function_arg_info &arg) | |
936 { | |
937 if (pass_by_reference (ca, arg)) | |
938 { | |
939 arg.type = build_pointer_type (arg.type); | |
940 arg.mode = TYPE_MODE (arg.type); | |
941 arg.pass_by_reference = true; | |
942 return true; | |
943 } | |
944 return false; | |
945 } | |
946 | |
947 /* Return true if ARG, which is passed by reference, should be callee | |
940 copied instead of caller copied. */ | 948 copied instead of caller copied. */ |
941 | 949 |
942 bool | 950 bool |
943 reference_callee_copied (CUMULATIVE_ARGS *ca, machine_mode mode, | 951 reference_callee_copied (CUMULATIVE_ARGS *ca, const function_arg_info &arg) |
944 tree type, bool named_arg) | |
945 { | 952 { |
946 if (type && TREE_ADDRESSABLE (type)) | 953 if (arg.type && TREE_ADDRESSABLE (arg.type)) |
947 return false; | 954 return false; |
948 return targetm.calls.callee_copies (pack_cumulative_args (ca), mode, type, | 955 return targetm.calls.callee_copies (pack_cumulative_args (ca), arg); |
949 named_arg); | |
950 } | 956 } |
951 | 957 |
952 | 958 |
953 /* Precompute all register parameters as described by ARGS, storing values | 959 /* Precompute all register parameters as described by ARGS, storing values |
954 into fields within the ARGS array. | 960 into fields within the ARGS array. |
1242 functions like memset. */ | 1248 functions like memset. */ |
1243 | 1249 |
1244 bool | 1250 bool |
1245 get_size_range (tree exp, tree range[2], bool allow_zero /* = false */) | 1251 get_size_range (tree exp, tree range[2], bool allow_zero /* = false */) |
1246 { | 1252 { |
1253 if (!exp) | |
1254 return false; | |
1255 | |
1247 if (tree_fits_uhwi_p (exp)) | 1256 if (tree_fits_uhwi_p (exp)) |
1248 { | 1257 { |
1249 /* EXP is a constant. */ | 1258 /* EXP is a constant. */ |
1250 range[0] = range[1] = exp; | 1259 range[0] = range[1] = exp; |
1251 return true; | 1260 return true; |
1340 } | 1349 } |
1341 | 1350 |
1342 /* Diagnose a call EXP to function FN decorated with attribute alloc_size | 1351 /* Diagnose a call EXP to function FN decorated with attribute alloc_size |
1343 whose argument numbers given by IDX with values given by ARGS exceed | 1352 whose argument numbers given by IDX with values given by ARGS exceed |
1344 the maximum object size or cause an unsigned oveflow (wrapping) when | 1353 the maximum object size or cause an unsigned oveflow (wrapping) when |
1345 multiplied. When ARGS[0] is null the function does nothing. ARGS[1] | 1354 multiplied. FN is null when EXP is a call via a function pointer. |
1346 may be null for functions like malloc, and non-null for those like | 1355 When ARGS[0] is null the function does nothing. ARGS[1] may be null |
1347 calloc that are decorated with a two-argument attribute alloc_size. */ | 1356 for functions like malloc, and non-null for those like calloc that |
1357 are decorated with a two-argument attribute alloc_size. */ | |
1348 | 1358 |
1349 void | 1359 void |
1350 maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2]) | 1360 maybe_warn_alloc_args_overflow (tree fn, tree exp, tree args[2], int idx[2]) |
1351 { | 1361 { |
1352 /* The range each of the (up to) two arguments is known to be in. */ | 1362 /* The range each of the (up to) two arguments is known to be in. */ |
1355 /* Maximum object size set by -Walloc-size-larger-than= or SIZE_MAX / 2. */ | 1365 /* Maximum object size set by -Walloc-size-larger-than= or SIZE_MAX / 2. */ |
1356 tree maxobjsize = alloc_max_size (); | 1366 tree maxobjsize = alloc_max_size (); |
1357 | 1367 |
1358 location_t loc = EXPR_LOCATION (exp); | 1368 location_t loc = EXPR_LOCATION (exp); |
1359 | 1369 |
1370 tree fntype = fn ? TREE_TYPE (fn) : TREE_TYPE (TREE_TYPE (exp)); | |
1360 bool warned = false; | 1371 bool warned = false; |
1361 | 1372 |
1362 /* Validate each argument individually. */ | 1373 /* Validate each argument individually. */ |
1363 for (unsigned i = 0; i != 2 && args[i]; ++i) | 1374 for (unsigned i = 0; i != 2 && args[i]; ++i) |
1364 { | 1375 { |
1380 returns_nonnull because there's no portability risk. This | 1391 returns_nonnull because there's no portability risk. This |
1381 avoids warning for such calls to libiberty's xmalloc and | 1392 avoids warning for such calls to libiberty's xmalloc and |
1382 friends. | 1393 friends. |
1383 Also avoid issuing the warning for calls to function named | 1394 Also avoid issuing the warning for calls to function named |
1384 "alloca". */ | 1395 "alloca". */ |
1385 if ((DECL_FUNCTION_CODE (fn) == BUILT_IN_ALLOCA | 1396 if (fn && fndecl_built_in_p (fn, BUILT_IN_ALLOCA) |
1386 && IDENTIFIER_LENGTH (DECL_NAME (fn)) != 6) | 1397 ? IDENTIFIER_LENGTH (DECL_NAME (fn)) != 6 |
1387 || (DECL_FUNCTION_CODE (fn) != BUILT_IN_ALLOCA | 1398 : !lookup_attribute ("returns_nonnull", |
1388 && !lookup_attribute ("returns_nonnull", | 1399 TYPE_ATTRIBUTES (fntype))) |
1389 TYPE_ATTRIBUTES (TREE_TYPE (fn))))) | |
1390 warned = warning_at (loc, OPT_Walloc_zero, | 1400 warned = warning_at (loc, OPT_Walloc_zero, |
1391 "%Kargument %i value is zero", | 1401 "%Kargument %i value is zero", |
1392 exp, idx[i] + 1); | 1402 exp, idx[i] + 1); |
1393 } | 1403 } |
1394 else if (tree_int_cst_lt (maxobjsize, args[i])) | 1404 else if (tree_int_cst_lt (maxobjsize, args[i])) |
1396 /* G++ emits calls to ::operator new[](SIZE_MAX) in C++98 | 1406 /* G++ emits calls to ::operator new[](SIZE_MAX) in C++98 |
1397 mode and with -fno-exceptions as a way to indicate array | 1407 mode and with -fno-exceptions as a way to indicate array |
1398 size overflow. There's no good way to detect C++98 here | 1408 size overflow. There's no good way to detect C++98 here |
1399 so avoid diagnosing these calls for all C++ modes. */ | 1409 so avoid diagnosing these calls for all C++ modes. */ |
1400 if (i == 0 | 1410 if (i == 0 |
1411 && fn | |
1401 && !args[1] | 1412 && !args[1] |
1402 && lang_GNU_CXX () | 1413 && lang_GNU_CXX () |
1403 && DECL_IS_OPERATOR_NEW (fn) | 1414 && DECL_IS_OPERATOR_NEW_P (fn) |
1404 && integer_all_onesp (args[i])) | 1415 && integer_all_onesp (args[i])) |
1405 continue; | 1416 continue; |
1406 | 1417 |
1407 warned = warning_at (loc, OPT_Walloc_size_larger_than_, | 1418 warned = warning_at (loc, OPT_Walloc_size_larger_than_, |
1408 "%Kargument %i value %qE exceeds " | 1419 "%Kargument %i value %qE exceeds " |
1479 inform (loc, "argument %i in the range [%E, %E]", | 1490 inform (loc, "argument %i in the range [%E, %E]", |
1480 idx[1] + 1, argrange[1][0], argrange[1][1]); | 1491 idx[1] + 1, argrange[1][0], argrange[1][1]); |
1481 } | 1492 } |
1482 } | 1493 } |
1483 | 1494 |
1484 if (warned) | 1495 if (warned && fn) |
1485 { | 1496 { |
1486 location_t fnloc = DECL_SOURCE_LOCATION (fn); | 1497 location_t fnloc = DECL_SOURCE_LOCATION (fn); |
1487 | 1498 |
1488 if (DECL_IS_BUILTIN (fn)) | 1499 if (DECL_IS_BUILTIN (fn)) |
1489 inform (loc, | 1500 inform (loc, |
1501 | 1512 |
1502 tree | 1513 tree |
1503 get_attr_nonstring_decl (tree expr, tree *ref) | 1514 get_attr_nonstring_decl (tree expr, tree *ref) |
1504 { | 1515 { |
1505 tree decl = expr; | 1516 tree decl = expr; |
1517 tree var = NULL_TREE; | |
1506 if (TREE_CODE (decl) == SSA_NAME) | 1518 if (TREE_CODE (decl) == SSA_NAME) |
1507 { | 1519 { |
1508 gimple *def = SSA_NAME_DEF_STMT (decl); | 1520 gimple *def = SSA_NAME_DEF_STMT (decl); |
1509 | 1521 |
1510 if (is_gimple_assign (def)) | 1522 if (is_gimple_assign (def)) |
1513 if (code == ADDR_EXPR | 1525 if (code == ADDR_EXPR |
1514 || code == COMPONENT_REF | 1526 || code == COMPONENT_REF |
1515 || code == VAR_DECL) | 1527 || code == VAR_DECL) |
1516 decl = gimple_assign_rhs1 (def); | 1528 decl = gimple_assign_rhs1 (def); |
1517 } | 1529 } |
1518 else if (tree var = SSA_NAME_VAR (decl)) | 1530 else |
1519 decl = var; | 1531 var = SSA_NAME_VAR (decl); |
1520 } | 1532 } |
1521 | 1533 |
1522 if (TREE_CODE (decl) == ADDR_EXPR) | 1534 if (TREE_CODE (decl) == ADDR_EXPR) |
1523 decl = TREE_OPERAND (decl, 0); | 1535 decl = TREE_OPERAND (decl, 0); |
1524 | 1536 |
1537 /* To simplify calling code, store the referenced DECL regardless of | |
1538 the attribute determined below, but avoid storing the SSA_NAME_VAR | |
1539 obtained above (it's not useful for dataflow purposes). */ | |
1525 if (ref) | 1540 if (ref) |
1526 *ref = decl; | 1541 *ref = decl; |
1527 | 1542 |
1528 if (TREE_CODE (decl) == ARRAY_REF) | 1543 /* Use the SSA_NAME_VAR that was determined above to see if it's |
1544 declared nonstring. Otherwise drill down into the referenced | |
1545 DECL. */ | |
1546 if (var) | |
1547 decl = var; | |
1548 else if (TREE_CODE (decl) == ARRAY_REF) | |
1529 decl = TREE_OPERAND (decl, 0); | 1549 decl = TREE_OPERAND (decl, 0); |
1530 else if (TREE_CODE (decl) == COMPONENT_REF) | 1550 else if (TREE_CODE (decl) == COMPONENT_REF) |
1531 decl = TREE_OPERAND (decl, 1); | 1551 decl = TREE_OPERAND (decl, 1); |
1532 else if (TREE_CODE (decl) == MEM_REF) | 1552 else if (TREE_CODE (decl) == MEM_REF) |
1533 return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref); | 1553 return get_attr_nonstring_decl (TREE_OPERAND (decl, 0), ref); |
1549 return; | 1569 return; |
1550 | 1570 |
1551 if (TREE_NO_WARNING (exp) || !warn_stringop_overflow) | 1571 if (TREE_NO_WARNING (exp) || !warn_stringop_overflow) |
1552 return; | 1572 return; |
1553 | 1573 |
1574 /* Avoid clearly invalid calls (more checking done below). */ | |
1554 unsigned nargs = call_expr_nargs (exp); | 1575 unsigned nargs = call_expr_nargs (exp); |
1576 if (!nargs) | |
1577 return; | |
1555 | 1578 |
1556 /* The bound argument to a bounded string function like strncpy. */ | 1579 /* The bound argument to a bounded string function like strncpy. */ |
1557 tree bound = NULL_TREE; | 1580 tree bound = NULL_TREE; |
1558 | 1581 |
1559 /* The range of lengths of a string argument to one of the comparison | 1582 /* The longest known or possible string argument to one of the comparison |
1560 functions. If the length is less than the bound it is used instead. */ | 1583 functions. If the length is less than the bound it is used instead. |
1561 tree lenrng[2] = { NULL_TREE, NULL_TREE }; | 1584 Since the length is only used for warning and not for code generation |
1585 disable strict mode in the calls to get_range_strlen below. */ | |
1586 tree maxlen = NULL_TREE; | |
1562 | 1587 |
1563 /* It's safe to call "bounded" string functions with a non-string | 1588 /* It's safe to call "bounded" string functions with a non-string |
1564 argument since the functions provide an explicit bound for this | 1589 argument since the functions provide an explicit bound for this |
1565 purpose. The exception is strncat where the bound may refer to | 1590 purpose. The exception is strncat where the bound may refer to |
1566 either the destination or the source. */ | 1591 either the destination or the source. */ |
1576 the range of their known or possible lengths and use it | 1601 the range of their known or possible lengths and use it |
1577 conservatively as the bound for the unbounded function, | 1602 conservatively as the bound for the unbounded function, |
1578 and to adjust the range of the bound of the bounded ones. */ | 1603 and to adjust the range of the bound of the bounded ones. */ |
1579 for (unsigned argno = 0; | 1604 for (unsigned argno = 0; |
1580 argno < MIN (nargs, 2) | 1605 argno < MIN (nargs, 2) |
1581 && !(lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST); argno++) | 1606 && !(maxlen && TREE_CODE (maxlen) == INTEGER_CST); argno++) |
1582 { | 1607 { |
1583 tree arg = CALL_EXPR_ARG (exp, argno); | 1608 tree arg = CALL_EXPR_ARG (exp, argno); |
1584 if (!get_attr_nonstring_decl (arg)) | 1609 if (!get_attr_nonstring_decl (arg)) |
1585 get_range_strlen (arg, lenrng); | 1610 { |
1611 c_strlen_data lendata = { }; | |
1612 /* Set MAXBOUND to an arbitrary non-null non-integer | |
1613 node as a request to have it set to the length of | |
1614 the longest string in a PHI. */ | |
1615 lendata.maxbound = arg; | |
1616 get_range_strlen (arg, &lendata, /* eltsize = */ 1); | |
1617 maxlen = lendata.maxbound; | |
1618 } | |
1586 } | 1619 } |
1587 } | 1620 } |
1588 /* Fall through. */ | 1621 /* Fall through. */ |
1589 | 1622 |
1590 case BUILT_IN_STRNCAT: | 1623 case BUILT_IN_STRNCAT: |
1601 | 1634 |
1602 case BUILT_IN_STRNLEN: | 1635 case BUILT_IN_STRNLEN: |
1603 { | 1636 { |
1604 tree arg = CALL_EXPR_ARG (exp, 0); | 1637 tree arg = CALL_EXPR_ARG (exp, 0); |
1605 if (!get_attr_nonstring_decl (arg)) | 1638 if (!get_attr_nonstring_decl (arg)) |
1606 get_range_strlen (arg, lenrng); | 1639 { |
1607 | 1640 c_strlen_data lendata = { }; |
1641 /* Set MAXBOUND to an arbitrary non-null non-integer | |
1642 node as a request to have it set to the length of | |
1643 the longest string in a PHI. */ | |
1644 lendata.maxbound = arg; | |
1645 get_range_strlen (arg, &lendata, /* eltsize = */ 1); | |
1646 maxlen = lendata.maxbound; | |
1647 } | |
1608 if (nargs > 1) | 1648 if (nargs > 1) |
1609 bound = CALL_EXPR_ARG (exp, 1); | 1649 bound = CALL_EXPR_ARG (exp, 1); |
1610 break; | 1650 break; |
1611 } | 1651 } |
1612 | 1652 |
1643 exp, fndecl, bndrng[0], bndrng[1], maxobjsize); | 1683 exp, fndecl, bndrng[0], bndrng[1], maxobjsize); |
1644 return; | 1684 return; |
1645 } | 1685 } |
1646 } | 1686 } |
1647 | 1687 |
1648 if (lenrng[1] && TREE_CODE (lenrng[1]) == INTEGER_CST) | 1688 if (maxlen && !integer_all_onesp (maxlen)) |
1649 { | 1689 { |
1650 /* Add one for the nul. */ | 1690 /* Add one for the nul. */ |
1651 lenrng[1] = const_binop (PLUS_EXPR, TREE_TYPE (lenrng[1]), | 1691 maxlen = const_binop (PLUS_EXPR, TREE_TYPE (maxlen), maxlen, |
1652 lenrng[1], size_one_node); | 1692 size_one_node); |
1653 | 1693 |
1654 if (!bndrng[0]) | 1694 if (!bndrng[0]) |
1655 { | 1695 { |
1656 /* Conservatively use the upper bound of the lengths for | 1696 /* Conservatively use the upper bound of the lengths for |
1657 both the lower and the upper bound of the operation. */ | 1697 both the lower and the upper bound of the operation. */ |
1658 bndrng[0] = lenrng[1]; | 1698 bndrng[0] = maxlen; |
1659 bndrng[1] = lenrng[1]; | 1699 bndrng[1] = maxlen; |
1660 bound = void_type_node; | 1700 bound = void_type_node; |
1661 } | 1701 } |
1662 else | 1702 else if (maxlen) |
1663 { | 1703 { |
1664 /* Replace the bound on the operation with the upper bound | 1704 /* Replace the bound on the operation with the upper bound |
1665 of the length of the string if the latter is smaller. */ | 1705 of the length of the string if the latter is smaller. */ |
1666 if (tree_int_cst_lt (lenrng[1], bndrng[0])) | 1706 if (tree_int_cst_lt (maxlen, bndrng[0])) |
1667 bndrng[0] = lenrng[1]; | 1707 bndrng[0] = maxlen; |
1668 else if (tree_int_cst_lt (lenrng[1], bndrng[1])) | 1708 else if (tree_int_cst_lt (maxlen, bndrng[1])) |
1669 bndrng[1] = lenrng[1]; | 1709 bndrng[1] = maxlen; |
1670 } | 1710 } |
1671 } | 1711 } |
1672 | 1712 |
1673 /* Iterate over the built-in function's formal arguments and check | 1713 /* Iterate over the built-in function's formal arguments and check |
1674 each const char* against the actual argument. If the actual | 1714 each const char* against the actual argument. If the actual |
1823 return; | 1863 return; |
1824 | 1864 |
1825 error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); | 1865 error_at (EXPR_LOCATION (call_expr), "cannot tail-call: %s", reason); |
1826 } | 1866 } |
1827 | 1867 |
1868 /* Used to define rdwr_map below. */ | |
1869 struct rdwr_access_hash: int_hash<int, -1> { }; | |
1870 | |
1871 /* A mapping between argument number corresponding to attribute access | |
1872 mode (read_only, write_only, or read_write) and operands. */ | |
1873 typedef hash_map<rdwr_access_hash, attr_access> rdwr_map; | |
1874 | |
1875 /* Initialize a mapping for a call to function FNDECL declared with | |
1876 attribute access. Each attribute poisitional operand inserts one | |
1877 entry into the mapping with the operand number as the key. */ | |
1878 | |
1879 static void | |
1880 init_attr_rdwr_indices (rdwr_map *rwm, tree fntype) | |
1881 { | |
1882 if (!fntype) | |
1883 return; | |
1884 | |
1885 tree access = TYPE_ATTRIBUTES (fntype); | |
1886 /* If the function's type has no attributes there's nothing to do. */ | |
1887 if (!access) | |
1888 return; | |
1889 | |
1890 access = lookup_attribute ("access", access); | |
1891 if (!access) | |
1892 return; | |
1893 | |
1894 tree mode = TREE_VALUE (access); | |
1895 gcc_assert (TREE_CODE (mode) == STRING_CST); | |
1896 const char *modestr = TREE_STRING_POINTER (mode); | |
1897 for (const char *m = modestr; *m; ) | |
1898 { | |
1899 attr_access acc = { }; | |
1900 | |
1901 switch (*m) | |
1902 { | |
1903 case 'r': acc.mode = acc.read_only; break; | |
1904 case 'w': acc.mode = acc.write_only; break; | |
1905 default: acc.mode = acc.read_write; break; | |
1906 } | |
1907 | |
1908 char *end; | |
1909 acc.ptrarg = strtoul (++m, &end, 10); | |
1910 m = end; | |
1911 if (*m == ',') | |
1912 { | |
1913 acc.sizarg = strtoul (++m, &end, 10); | |
1914 m = end; | |
1915 } | |
1916 else | |
1917 acc.sizarg = UINT_MAX; | |
1918 | |
1919 acc.ptr = NULL_TREE; | |
1920 acc.size = NULL_TREE; | |
1921 | |
1922 /* Unconditionally add an entry for the required pointer | |
1923 operand of the attribute, and one for the optional size | |
1924 operand when it's specified. */ | |
1925 rwm->put (acc.ptrarg, acc); | |
1926 if (acc.sizarg != UINT_MAX) | |
1927 rwm->put (acc.sizarg, acc); | |
1928 } | |
1929 } | |
1930 | |
1931 /* Returns the type of the argument ARGNO to function with type FNTYPE | |
1932 or null when the typoe cannot be determined or no such argument exists. */ | |
1933 | |
1934 static tree | |
1935 fntype_argno_type (tree fntype, unsigned argno) | |
1936 { | |
1937 if (!prototype_p (fntype)) | |
1938 return NULL_TREE; | |
1939 | |
1940 tree argtype; | |
1941 function_args_iterator it; | |
1942 FOREACH_FUNCTION_ARGS (fntype, argtype, it) | |
1943 if (argno-- == 0) | |
1944 return argtype; | |
1945 | |
1946 return NULL_TREE; | |
1947 } | |
1948 | |
1949 /* Helper to append the "rdwr" attribute specification described | |
1950 by ACCESS to the array ATTRSTR with size STRSIZE. Used in | |
1951 diagnostics. */ | |
1952 | |
1953 static inline void | |
1954 append_attrname (const std::pair<int, attr_access> &access, | |
1955 char *attrstr, size_t strsize) | |
1956 { | |
1957 /* Append the relevant attribute to the string. This (deliberately) | |
1958 appends the attribute pointer operand even when none was specified. */ | |
1959 size_t len = strlen (attrstr); | |
1960 | |
1961 const char *atname | |
1962 = (access.second.mode == attr_access::read_only | |
1963 ? "read_only" | |
1964 : (access.second.mode == attr_access::write_only | |
1965 ? "write_only" : "read_write")); | |
1966 | |
1967 const char *sep = len ? ", " : ""; | |
1968 | |
1969 if (access.second.sizarg == UINT_MAX) | |
1970 snprintf (attrstr + len, strsize - len, | |
1971 "%s%s (%i)", sep, atname, | |
1972 access.second.ptrarg + 1); | |
1973 else | |
1974 snprintf (attrstr + len, strsize - len, | |
1975 "%s%s (%i, %i)", sep, atname, | |
1976 access.second.ptrarg + 1, access.second.sizarg + 1); | |
1977 } | |
1978 | |
1979 /* Iterate over attribute access read-only, read-write, and write-only | |
1980 arguments and diagnose past-the-end accesses and related problems | |
1981 in the function call EXP. */ | |
1982 | |
1983 static void | |
1984 maybe_warn_rdwr_sizes (rdwr_map *rwm, tree exp) | |
1985 { | |
1986 tree fndecl = NULL_TREE; | |
1987 tree fntype = NULL_TREE; | |
1988 if (tree fnaddr = CALL_EXPR_FN (exp)) | |
1989 { | |
1990 if (TREE_CODE (fnaddr) == ADDR_EXPR) | |
1991 { | |
1992 fndecl = TREE_OPERAND (fnaddr, 0); | |
1993 fntype = TREE_TYPE (fndecl); | |
1994 } | |
1995 else | |
1996 fntype = TREE_TYPE (TREE_TYPE (fnaddr)); | |
1997 } | |
1998 | |
1999 if (!fntype) | |
2000 return; | |
2001 | |
2002 /* A string describing the attributes that the warnings issued by this | |
2003 function apply to. Used to print one informational note per function | |
2004 call, rather than one per warning. That reduces clutter. */ | |
2005 char attrstr[80]; | |
2006 attrstr[0] = 0; | |
2007 | |
2008 for (rdwr_map::iterator it = rwm->begin (); it != rwm->end (); ++it) | |
2009 { | |
2010 std::pair<int, attr_access> access = *it; | |
2011 | |
2012 /* Get the function call arguments corresponding to the attribute's | |
2013 positional arguments. When both arguments have been specified | |
2014 there will be two entries in *RWM, one for each. They are | |
2015 cross-referenced by their respective argument numbers in | |
2016 ACCESS.PTRARG and ACCESS.SIZARG. */ | |
2017 const int ptridx = access.second.ptrarg; | |
2018 const int sizidx = access.second.sizarg; | |
2019 | |
2020 gcc_assert (ptridx != -1); | |
2021 gcc_assert (access.first == ptridx || access.first == sizidx); | |
2022 | |
2023 /* The pointer is set to null for the entry corresponding to | |
2024 the size argument. Skip it. It's handled when the entry | |
2025 corresponding to the pointer argument comes up. */ | |
2026 if (!access.second.ptr) | |
2027 continue; | |
2028 | |
2029 tree argtype = fntype_argno_type (fntype, ptridx); | |
2030 argtype = TREE_TYPE (argtype); | |
2031 | |
2032 tree size; | |
2033 if (sizidx == -1) | |
2034 { | |
2035 /* If only the pointer attribute operand was specified | |
2036 and not size, set SIZE to the size of one element of | |
2037 the pointed to type to detect smaller objects (null | |
2038 pointers are diagnosed in this case only if | |
2039 the pointer is also declared with attribute nonnull. */ | |
2040 size = size_one_node; | |
2041 } | |
2042 else | |
2043 size = rwm->get (sizidx)->size; | |
2044 | |
2045 tree ptr = access.second.ptr; | |
2046 tree sizrng[2] = { size_zero_node, build_all_ones_cst (sizetype) }; | |
2047 if (get_size_range (size, sizrng, true) | |
2048 && tree_int_cst_sgn (sizrng[0]) < 0 | |
2049 && tree_int_cst_sgn (sizrng[1]) < 0) | |
2050 { | |
2051 /* Warn about negative sizes. */ | |
2052 bool warned = false; | |
2053 location_t loc = EXPR_LOCATION (exp); | |
2054 if (tree_int_cst_equal (sizrng[0], sizrng[1])) | |
2055 warned = warning_at (loc, OPT_Wstringop_overflow_, | |
2056 "%Kargument %i value %E is negative", | |
2057 exp, sizidx + 1, size); | |
2058 else | |
2059 warned = warning_at (loc, OPT_Wstringop_overflow_, | |
2060 "%Kargument %i range [%E, %E] is negative", | |
2061 exp, sizidx + 1, sizrng[0], sizrng[1]); | |
2062 if (warned) | |
2063 { | |
2064 append_attrname (access, attrstr, sizeof attrstr); | |
2065 /* Avoid warning again for the same attribute. */ | |
2066 continue; | |
2067 } | |
2068 } | |
2069 | |
2070 if (tree_int_cst_sgn (sizrng[0]) >= 0) | |
2071 { | |
2072 if (COMPLETE_TYPE_P (argtype)) | |
2073 { | |
2074 /* Multiple SIZE by the size of the type the pointer | |
2075 argument points to. If it's incomplete the size | |
2076 is used as is. */ | |
2077 size = NULL_TREE; | |
2078 if (tree argsize = TYPE_SIZE_UNIT (argtype)) | |
2079 if (TREE_CODE (argsize) == INTEGER_CST) | |
2080 { | |
2081 const int prec = TYPE_PRECISION (sizetype); | |
2082 wide_int minsize = wi::to_wide (sizrng[0], prec); | |
2083 minsize *= wi::to_wide (argsize, prec); | |
2084 size = wide_int_to_tree (sizetype, minsize); | |
2085 } | |
2086 } | |
2087 } | |
2088 else | |
2089 size = NULL_TREE; | |
2090 | |
2091 if (sizidx >= 0 | |
2092 && integer_zerop (ptr) | |
2093 && tree_int_cst_sgn (sizrng[0]) > 0) | |
2094 { | |
2095 /* Warn about null pointers with positive sizes. This is | |
2096 different from also declaring the pointer argument with | |
2097 attribute nonnull when the function accepts null pointers | |
2098 only when the corresponding size is zero. */ | |
2099 bool warned = false; | |
2100 location_t loc = EXPR_LOCATION (exp); | |
2101 if (tree_int_cst_equal (sizrng[0], sizrng[1])) | |
2102 warned = warning_at (loc, OPT_Wnonnull, | |
2103 "%Kargument %i is null but the corresponding " | |
2104 "size argument %i value is %E", | |
2105 exp, ptridx + 1, sizidx + 1, size); | |
2106 else | |
2107 warned = warning_at (loc, OPT_Wnonnull, | |
2108 "%Kargument %i is null but the corresponding " | |
2109 "size argument %i range is [%E, %E]", | |
2110 exp, ptridx + 1, sizidx + 1, | |
2111 sizrng[0], sizrng[1]); | |
2112 if (warned) | |
2113 { | |
2114 append_attrname (access, attrstr, sizeof attrstr); | |
2115 /* Avoid warning again for the same attribute. */ | |
2116 continue; | |
2117 } | |
2118 } | |
2119 | |
2120 tree objsize = compute_objsize (ptr, 0); | |
2121 | |
2122 tree srcsize; | |
2123 if (access.second.mode == attr_access::write_only) | |
2124 { | |
2125 /* For a write-only argument there is no source. */ | |
2126 srcsize = NULL_TREE; | |
2127 } | |
2128 else | |
2129 { | |
2130 /* For read-only and read-write attributes also set the source | |
2131 size. */ | |
2132 srcsize = objsize; | |
2133 if (access.second.mode == attr_access::read_only) | |
2134 { | |
2135 /* For a read-only attribute there is no destination so | |
2136 clear OBJSIZE. This emits "reading N bytes" kind of | |
2137 diagnostics instead of the "writing N bytes" kind. */ | |
2138 objsize = NULL_TREE; | |
2139 } | |
2140 } | |
2141 | |
2142 /* Clear the no-warning bit in case it was set in a prior | |
2143 iteration so that accesses via different arguments are | |
2144 diagnosed. */ | |
2145 TREE_NO_WARNING (exp) = false; | |
2146 check_access (exp, NULL_TREE, NULL_TREE, size, /*maxread=*/ NULL_TREE, | |
2147 srcsize, objsize); | |
2148 | |
2149 if (TREE_NO_WARNING (exp)) | |
2150 /* If check_access issued a warning above, append the relevant | |
2151 attribute to the string. */ | |
2152 append_attrname (access, attrstr, sizeof attrstr); | |
2153 } | |
2154 | |
2155 if (!*attrstr) | |
2156 return; | |
2157 | |
2158 if (fndecl) | |
2159 inform (DECL_SOURCE_LOCATION (fndecl), | |
2160 "in a call to function %qD declared with attribute %qs", | |
2161 fndecl, attrstr); | |
2162 else | |
2163 inform (EXPR_LOCATION (fndecl), | |
2164 "in a call with type %qT and attribute %qs", | |
2165 fntype, attrstr); | |
2166 | |
2167 /* Set the bit in case if was cleared and not set above. */ | |
2168 TREE_NO_WARNING (exp) = true; | |
2169 } | |
2170 | |
1828 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in | 2171 /* Fill in ARGS_SIZE and ARGS array based on the parameters found in |
1829 CALL_EXPR EXP. | 2172 CALL_EXPR EXP. |
1830 | 2173 |
1831 NUM_ACTUALS is the total number of parameters. | 2174 NUM_ACTUALS is the total number of parameters. |
1832 | 2175 |
1922 BITMAP_FREE (slots); | 2265 BITMAP_FREE (slots); |
1923 } | 2266 } |
1924 | 2267 |
1925 bitmap_obstack_release (NULL); | 2268 bitmap_obstack_release (NULL); |
1926 | 2269 |
1927 /* Extract attribute alloc_size and if set, store the indices of | 2270 /* Extract attribute alloc_size from the type of the called expression |
1928 the corresponding arguments in ALLOC_IDX, and then the actual | 2271 (which could be a function or a function pointer) and if set, store |
1929 argument(s) at those indices in ALLOC_ARGS. */ | 2272 the indices of the corresponding arguments in ALLOC_IDX, and then |
2273 the actual argument(s) at those indices in ALLOC_ARGS. */ | |
1930 int alloc_idx[2] = { -1, -1 }; | 2274 int alloc_idx[2] = { -1, -1 }; |
1931 if (tree alloc_size | 2275 if (tree alloc_size = lookup_attribute ("alloc_size", |
1932 = (fndecl ? lookup_attribute ("alloc_size", | 2276 TYPE_ATTRIBUTES (fntype))) |
1933 TYPE_ATTRIBUTES (TREE_TYPE (fndecl))) | |
1934 : NULL_TREE)) | |
1935 { | 2277 { |
1936 tree args = TREE_VALUE (alloc_size); | 2278 tree args = TREE_VALUE (alloc_size); |
1937 alloc_idx[0] = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1; | 2279 alloc_idx[0] = TREE_INT_CST_LOW (TREE_VALUE (args)) - 1; |
1938 if (TREE_CHAIN (args)) | 2280 if (TREE_CHAIN (args)) |
1939 alloc_idx[1] = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1; | 2281 alloc_idx[1] = TREE_INT_CST_LOW (TREE_VALUE (TREE_CHAIN (args))) - 1; |
1940 } | 2282 } |
1941 | 2283 |
1942 /* Array for up to the two attribute alloc_size arguments. */ | 2284 /* Array for up to the two attribute alloc_size arguments. */ |
1943 tree alloc_args[] = { NULL_TREE, NULL_TREE }; | 2285 tree alloc_args[] = { NULL_TREE, NULL_TREE }; |
1944 | 2286 |
2287 /* Map of attribute read_only, write_only, or read_write specifications | |
2288 for function arguments. */ | |
2289 rdwr_map rdwr_idx; | |
2290 init_attr_rdwr_indices (&rdwr_idx, fntype); | |
2291 | |
1945 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */ | 2292 /* I counts args in order (to be) pushed; ARGPOS counts in order written. */ |
1946 for (argpos = 0; argpos < num_actuals; i--, argpos++) | 2293 for (argpos = 0; argpos < num_actuals; i--, argpos++) |
1947 { | 2294 { |
1948 tree type = TREE_TYPE (args[i].tree_value); | 2295 tree type = TREE_TYPE (args[i].tree_value); |
1949 int unsignedp; | 2296 int unsignedp; |
1950 machine_mode mode; | |
1951 | 2297 |
1952 /* Replace erroneous argument with constant zero. */ | 2298 /* Replace erroneous argument with constant zero. */ |
1953 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) | 2299 if (type == error_mark_node || !COMPLETE_TYPE_P (type)) |
1954 args[i].tree_value = integer_zero_node, type = integer_type_node; | 2300 args[i].tree_value = integer_zero_node, type = integer_type_node; |
1955 | 2301 |
1956 /* If TYPE is a transparent union or record, pass things the way | 2302 /* If TYPE is a transparent union or record, pass things the way |
1957 we would pass the first field of the union or record. We have | 2303 we would pass the first field of the union or record. We have |
1958 already verified that the modes are the same. */ | 2304 already verified that the modes are the same. */ |
1959 if ((TREE_CODE (type) == UNION_TYPE || TREE_CODE (type) == RECORD_TYPE) | 2305 if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type)) |
1960 && TYPE_TRANSPARENT_AGGR (type)) | |
1961 type = TREE_TYPE (first_field (type)); | 2306 type = TREE_TYPE (first_field (type)); |
1962 | 2307 |
1963 /* Decide where to pass this arg. | 2308 /* Decide where to pass this arg. |
1964 | 2309 |
1965 args[i].reg is nonzero if all or part is passed in registers. | 2310 args[i].reg is nonzero if all or part is passed in registers. |
1973 | 2318 |
1974 These decisions are driven by the FUNCTION_... macros and must agree | 2319 These decisions are driven by the FUNCTION_... macros and must agree |
1975 with those made by function.c. */ | 2320 with those made by function.c. */ |
1976 | 2321 |
1977 /* See if this argument should be passed by invisible reference. */ | 2322 /* See if this argument should be passed by invisible reference. */ |
1978 if (pass_by_reference (args_so_far_pnt, TYPE_MODE (type), | 2323 function_arg_info arg (type, argpos < n_named_args); |
1979 type, argpos < n_named_args)) | 2324 if (pass_by_reference (args_so_far_pnt, arg)) |
1980 { | 2325 { |
1981 bool callee_copies; | 2326 bool callee_copies; |
1982 tree base = NULL_TREE; | 2327 tree base = NULL_TREE; |
1983 | 2328 |
1984 callee_copies | 2329 callee_copies = reference_callee_copied (args_so_far_pnt, arg); |
1985 = reference_callee_copied (args_so_far_pnt, TYPE_MODE (type), | |
1986 type, argpos < n_named_args); | |
1987 | 2330 |
1988 /* If we're compiling a thunk, pass through invisible references | 2331 /* If we're compiling a thunk, pass through invisible references |
1989 instead of making a copy. */ | 2332 instead of making a copy. */ |
1990 if (call_from_thunk_p | 2333 if (call_from_thunk_p |
1991 || (callee_copies | 2334 || (callee_copies |
2091 *may_tailcall = false; | 2434 *may_tailcall = false; |
2092 maybe_complain_about_tail_call (exp, | 2435 maybe_complain_about_tail_call (exp, |
2093 "argument must be passed" | 2436 "argument must be passed" |
2094 " by copying"); | 2437 " by copying"); |
2095 } | 2438 } |
2439 arg.pass_by_reference = true; | |
2096 } | 2440 } |
2097 | 2441 |
2098 unsignedp = TYPE_UNSIGNED (type); | 2442 unsignedp = TYPE_UNSIGNED (type); |
2099 mode = promote_function_mode (type, TYPE_MODE (type), &unsignedp, | 2443 arg.type = type; |
2100 fndecl ? TREE_TYPE (fndecl) : fntype, 0); | 2444 arg.mode |
2445 = promote_function_mode (type, TYPE_MODE (type), &unsignedp, | |
2446 fndecl ? TREE_TYPE (fndecl) : fntype, 0); | |
2101 | 2447 |
2102 args[i].unsignedp = unsignedp; | 2448 args[i].unsignedp = unsignedp; |
2103 args[i].mode = mode; | 2449 args[i].mode = arg.mode; |
2104 | 2450 |
2105 targetm.calls.warn_parameter_passing_abi (args_so_far, type); | 2451 targetm.calls.warn_parameter_passing_abi (args_so_far, type); |
2106 | 2452 |
2107 args[i].reg = targetm.calls.function_arg (args_so_far, mode, type, | 2453 args[i].reg = targetm.calls.function_arg (args_so_far, arg); |
2108 argpos < n_named_args); | |
2109 | 2454 |
2110 if (args[i].reg && CONST_INT_P (args[i].reg)) | 2455 if (args[i].reg && CONST_INT_P (args[i].reg)) |
2111 { | 2456 args[i].reg = NULL; |
2112 args[i].special_slot = args[i].reg; | |
2113 args[i].reg = NULL; | |
2114 } | |
2115 | 2457 |
2116 /* If this is a sibling call and the machine has register windows, the | 2458 /* If this is a sibling call and the machine has register windows, the |
2117 register window has to be unwinded before calling the routine, so | 2459 register window has to be unwinded before calling the routine, so |
2118 arguments have to go into the incoming registers. */ | 2460 arguments have to go into the incoming registers. */ |
2119 if (targetm.calls.function_incoming_arg != targetm.calls.function_arg) | 2461 if (targetm.calls.function_incoming_arg != targetm.calls.function_arg) |
2120 args[i].tail_call_reg | 2462 args[i].tail_call_reg |
2121 = targetm.calls.function_incoming_arg (args_so_far, mode, type, | 2463 = targetm.calls.function_incoming_arg (args_so_far, arg); |
2122 argpos < n_named_args); | |
2123 else | 2464 else |
2124 args[i].tail_call_reg = args[i].reg; | 2465 args[i].tail_call_reg = args[i].reg; |
2125 | 2466 |
2126 if (args[i].reg) | 2467 if (args[i].reg) |
2127 args[i].partial | 2468 args[i].partial = targetm.calls.arg_partial_bytes (args_so_far, arg); |
2128 = targetm.calls.arg_partial_bytes (args_so_far, mode, type, | 2469 |
2129 argpos < n_named_args); | 2470 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (arg); |
2130 | |
2131 args[i].pass_on_stack = targetm.calls.must_pass_in_stack (mode, type); | |
2132 | 2471 |
2133 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]), | 2472 /* If FUNCTION_ARG returned a (parallel [(expr_list (nil) ...) ...]), |
2134 it means that we are to pass this arg in the register(s) designated | 2473 it means that we are to pass this arg in the register(s) designated |
2135 by the PARALLEL, but also to pass it in the stack. */ | 2474 by the PARALLEL, but also to pass it in the stack. */ |
2136 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL | 2475 if (args[i].reg && GET_CODE (args[i].reg) == PARALLEL |
2148 | 2487 |
2149 /* Compute the stack-size of this argument. */ | 2488 /* Compute the stack-size of this argument. */ |
2150 if (args[i].reg == 0 || args[i].partial != 0 | 2489 if (args[i].reg == 0 || args[i].partial != 0 |
2151 || reg_parm_stack_space > 0 | 2490 || reg_parm_stack_space > 0 |
2152 || args[i].pass_on_stack) | 2491 || args[i].pass_on_stack) |
2153 locate_and_pad_parm (mode, type, | 2492 locate_and_pad_parm (arg.mode, type, |
2154 #ifdef STACK_PARMS_IN_REG_PARM_AREA | 2493 #ifdef STACK_PARMS_IN_REG_PARM_AREA |
2155 1, | 2494 1, |
2156 #else | 2495 #else |
2157 args[i].reg != 0, | 2496 args[i].reg != 0, |
2158 #endif | 2497 #endif |
2162 #ifdef BLOCK_REG_PADDING | 2501 #ifdef BLOCK_REG_PADDING |
2163 else | 2502 else |
2164 /* The argument is passed entirely in registers. See at which | 2503 /* The argument is passed entirely in registers. See at which |
2165 end it should be padded. */ | 2504 end it should be padded. */ |
2166 args[i].locate.where_pad = | 2505 args[i].locate.where_pad = |
2167 BLOCK_REG_PADDING (mode, type, | 2506 BLOCK_REG_PADDING (arg.mode, type, |
2168 int_size_in_bytes (type) <= UNITS_PER_WORD); | 2507 int_size_in_bytes (type) <= UNITS_PER_WORD); |
2169 #endif | 2508 #endif |
2170 | 2509 |
2171 /* Update ARGS_SIZE, the total stack space for args so far. */ | 2510 /* Update ARGS_SIZE, the total stack space for args so far. */ |
2172 | 2511 |
2175 ADD_PARM_SIZE (*args_size, args[i].locate.size.var); | 2514 ADD_PARM_SIZE (*args_size, args[i].locate.size.var); |
2176 | 2515 |
2177 /* Increment ARGS_SO_FAR, which has info about which arg-registers | 2516 /* Increment ARGS_SO_FAR, which has info about which arg-registers |
2178 have been used, etc. */ | 2517 have been used, etc. */ |
2179 | 2518 |
2180 targetm.calls.function_arg_advance (args_so_far, TYPE_MODE (type), | 2519 /* ??? Traditionally we've passed TYPE_MODE here, instead of the |
2181 type, argpos < n_named_args); | 2520 promoted_mode used for function_arg above. However, the |
2521 corresponding handling of incoming arguments in function.c | |
2522 does pass the promoted mode. */ | |
2523 arg.mode = TYPE_MODE (type); | |
2524 targetm.calls.function_arg_advance (args_so_far, arg); | |
2182 | 2525 |
2183 /* Store argument values for functions decorated with attribute | 2526 /* Store argument values for functions decorated with attribute |
2184 alloc_size. */ | 2527 alloc_size. */ |
2185 if (argpos == alloc_idx[0]) | 2528 if (argpos == alloc_idx[0]) |
2186 alloc_args[0] = args[i].tree_value; | 2529 alloc_args[0] = args[i].tree_value; |
2187 else if (argpos == alloc_idx[1]) | 2530 else if (argpos == alloc_idx[1]) |
2188 alloc_args[1] = args[i].tree_value; | 2531 alloc_args[1] = args[i].tree_value; |
2532 | |
2533 /* Save the actual argument that corresponds to the access attribute | |
2534 operand for later processing. */ | |
2535 if (attr_access *access = rdwr_idx.get (argpos)) | |
2536 { | |
2537 if (POINTER_TYPE_P (type)) | |
2538 { | |
2539 access->ptr = args[i].tree_value; | |
2540 gcc_assert (access->size == NULL_TREE); | |
2541 } | |
2542 else | |
2543 { | |
2544 access->size = args[i].tree_value; | |
2545 gcc_assert (access->ptr == NULL_TREE); | |
2546 } | |
2547 } | |
2189 } | 2548 } |
2190 | 2549 |
2191 if (alloc_args[0]) | 2550 if (alloc_args[0]) |
2192 { | 2551 { |
2193 /* Check the arguments of functions decorated with attribute | 2552 /* Check the arguments of functions decorated with attribute |
2196 } | 2555 } |
2197 | 2556 |
2198 /* Detect passing non-string arguments to functions expecting | 2557 /* Detect passing non-string arguments to functions expecting |
2199 nul-terminated strings. */ | 2558 nul-terminated strings. */ |
2200 maybe_warn_nonstring_arg (fndecl, exp); | 2559 maybe_warn_nonstring_arg (fndecl, exp); |
2560 | |
2561 /* Check read_only, write_only, and read_write arguments. */ | |
2562 maybe_warn_rdwr_sizes (&rdwr_idx, exp); | |
2201 } | 2563 } |
2202 | 2564 |
2203 /* Update ARGS_SIZE to contain the total size for the argument block. | 2565 /* Update ARGS_SIZE to contain the total size for the argument block. |
2204 Return the original constant component of the argument block's size. | 2566 Return the original constant component of the argument block's size. |
2205 | 2567 |
2736 int partial = args[i].partial; | 3098 int partial = args[i].partial; |
2737 int nregs; | 3099 int nregs; |
2738 poly_int64 size = 0; | 3100 poly_int64 size = 0; |
2739 HOST_WIDE_INT const_size = 0; | 3101 HOST_WIDE_INT const_size = 0; |
2740 rtx_insn *before_arg = get_last_insn (); | 3102 rtx_insn *before_arg = get_last_insn (); |
3103 tree type = TREE_TYPE (args[i].tree_value); | |
3104 if (RECORD_OR_UNION_TYPE_P (type) && TYPE_TRANSPARENT_AGGR (type)) | |
3105 type = TREE_TYPE (first_field (type)); | |
2741 /* Set non-negative if we must move a word at a time, even if | 3106 /* Set non-negative if we must move a word at a time, even if |
2742 just one word (e.g, partial == 4 && mode == DFmode). Set | 3107 just one word (e.g, partial == 4 && mode == DFmode). Set |
2743 to -1 if we just use a normal move insn. This value can be | 3108 to -1 if we just use a normal move insn. This value can be |
2744 zero if the argument is a zero size structure. */ | 3109 zero if the argument is a zero size structure. */ |
2745 nregs = -1; | 3110 nregs = -1; |
2748 else if (partial) | 3113 else if (partial) |
2749 { | 3114 { |
2750 gcc_assert (partial % UNITS_PER_WORD == 0); | 3115 gcc_assert (partial % UNITS_PER_WORD == 0); |
2751 nregs = partial / UNITS_PER_WORD; | 3116 nregs = partial / UNITS_PER_WORD; |
2752 } | 3117 } |
2753 else if (TYPE_MODE (TREE_TYPE (args[i].tree_value)) == BLKmode) | 3118 else if (TYPE_MODE (type) == BLKmode) |
2754 { | 3119 { |
2755 /* Variable-sized parameters should be described by a | 3120 /* Variable-sized parameters should be described by a |
2756 PARALLEL instead. */ | 3121 PARALLEL instead. */ |
2757 const_size = int_size_in_bytes (TREE_TYPE (args[i].tree_value)); | 3122 const_size = int_size_in_bytes (type); |
2758 gcc_assert (const_size >= 0); | 3123 gcc_assert (const_size >= 0); |
2759 nregs = (const_size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD; | 3124 nregs = (const_size + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD; |
2760 size = const_size; | 3125 size = const_size; |
2761 } | 3126 } |
2762 else | 3127 else |
2879 /* Handle calls that pass values in multiple non-contiguous | 3244 /* Handle calls that pass values in multiple non-contiguous |
2880 locations. The Irix 6 ABI has examples of this. */ | 3245 locations. The Irix 6 ABI has examples of this. */ |
2881 if (GET_CODE (reg) == PARALLEL) | 3246 if (GET_CODE (reg) == PARALLEL) |
2882 use_group_regs (call_fusage, reg); | 3247 use_group_regs (call_fusage, reg); |
2883 else if (nregs == -1) | 3248 else if (nregs == -1) |
2884 use_reg_mode (call_fusage, reg, | 3249 use_reg_mode (call_fusage, reg, TYPE_MODE (type)); |
2885 TYPE_MODE (TREE_TYPE (args[i].tree_value))); | |
2886 else if (nregs > 0) | 3250 else if (nregs > 0) |
2887 use_regs (call_fusage, REGNO (reg), nregs); | 3251 use_regs (call_fusage, REGNO (reg), nregs); |
2888 } | 3252 } |
2889 } | 3253 } |
2890 } | 3254 } |
3122 maybe_complain_about_tail_call (exp, "callee returns a structure"); | 3486 maybe_complain_about_tail_call (exp, "callee returns a structure"); |
3123 return false; | 3487 return false; |
3124 } | 3488 } |
3125 | 3489 |
3126 #ifdef REG_PARM_STACK_SPACE | 3490 #ifdef REG_PARM_STACK_SPACE |
3127 /* If outgoing reg parm stack space changes, we can not do sibcall. */ | 3491 /* If outgoing reg parm stack space changes, we cannot do sibcall. */ |
3128 if (OUTGOING_REG_PARM_STACK_SPACE (funtype) | 3492 if (OUTGOING_REG_PARM_STACK_SPACE (funtype) |
3129 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)) | 3493 != OUTGOING_REG_PARM_STACK_SPACE (TREE_TYPE (current_function_decl)) |
3130 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))) | 3494 || (reg_parm_stack_space != REG_PARM_STACK_SPACE (current_function_decl))) |
3131 { | 3495 { |
3132 maybe_complain_about_tail_call (exp, | 3496 maybe_complain_about_tail_call (exp, |
3210 return false; | 3574 return false; |
3211 } | 3575 } |
3212 | 3576 |
3213 /* All checks passed. */ | 3577 /* All checks passed. */ |
3214 return true; | 3578 return true; |
3579 } | |
3580 | |
3581 /* Update stack alignment when the parameter is passed in the stack | |
3582 since the outgoing parameter requires extra alignment on the calling | |
3583 function side. */ | |
3584 | |
3585 static void | |
3586 update_stack_alignment_for_call (struct locate_and_pad_arg_data *locate) | |
3587 { | |
3588 if (crtl->stack_alignment_needed < locate->boundary) | |
3589 crtl->stack_alignment_needed = locate->boundary; | |
3590 if (crtl->preferred_stack_boundary < locate->boundary) | |
3591 crtl->preferred_stack_boundary = locate->boundary; | |
3215 } | 3592 } |
3216 | 3593 |
3217 /* Generate all the code for a CALL_EXPR exp | 3594 /* Generate all the code for a CALL_EXPR exp |
3218 and return an rtx for its value. | 3595 and return an rtx for its value. |
3219 Store the value in TARGET (specified as an rtx) if convenient. | 3596 Store the value in TARGET (specified as an rtx) if convenient. |
3614 || (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp)) | 3991 || (!flag_optimize_sibling_calls && !CALL_FROM_THUNK_P (exp)) |
3615 || args_size.var | 3992 || args_size.var |
3616 || dbg_cnt (tail_call) == false) | 3993 || dbg_cnt (tail_call) == false) |
3617 try_tail_call = 0; | 3994 try_tail_call = 0; |
3618 | 3995 |
3996 /* Workaround buggy C/C++ wrappers around Fortran routines with | |
3997 character(len=constant) arguments if the hidden string length arguments | |
3998 are passed on the stack; if the callers forget to pass those arguments, | |
3999 attempting to tail call in such routines leads to stack corruption. | |
4000 Avoid tail calls in functions where at least one such hidden string | |
4001 length argument is passed (partially or fully) on the stack in the | |
4002 caller and the callee needs to pass any arguments on the stack. | |
4003 See PR90329. */ | |
4004 if (try_tail_call && maybe_ne (args_size.constant, 0)) | |
4005 for (tree arg = DECL_ARGUMENTS (current_function_decl); | |
4006 arg; arg = DECL_CHAIN (arg)) | |
4007 if (DECL_HIDDEN_STRING_LENGTH (arg) && DECL_INCOMING_RTL (arg)) | |
4008 { | |
4009 subrtx_iterator::array_type array; | |
4010 FOR_EACH_SUBRTX (iter, array, DECL_INCOMING_RTL (arg), NONCONST) | |
4011 if (MEM_P (*iter)) | |
4012 { | |
4013 try_tail_call = 0; | |
4014 break; | |
4015 } | |
4016 } | |
4017 | |
3619 /* If the user has marked the function as requiring tail-call | 4018 /* If the user has marked the function as requiring tail-call |
3620 optimization, attempt it. */ | 4019 optimization, attempt it. */ |
3621 if (must_tail_call) | 4020 if (must_tail_call) |
3622 try_tail_call = 1; | 4021 try_tail_call = 1; |
3623 | 4022 |
3667 } | 4066 } |
3668 | 4067 |
3669 /* Ensure current function's preferred stack boundary is at least | 4068 /* Ensure current function's preferred stack boundary is at least |
3670 what we need. Stack alignment may also increase preferred stack | 4069 what we need. Stack alignment may also increase preferred stack |
3671 boundary. */ | 4070 boundary. */ |
4071 for (i = 0; i < num_actuals; i++) | |
4072 if (reg_parm_stack_space > 0 | |
4073 || args[i].reg == 0 | |
4074 || args[i].partial != 0 | |
4075 || args[i].pass_on_stack) | |
4076 update_stack_alignment_for_call (&args[i].locate); | |
3672 if (crtl->preferred_stack_boundary < preferred_stack_boundary) | 4077 if (crtl->preferred_stack_boundary < preferred_stack_boundary) |
3673 crtl->preferred_stack_boundary = preferred_stack_boundary; | 4078 crtl->preferred_stack_boundary = preferred_stack_boundary; |
3674 else | 4079 else |
3675 preferred_stack_boundary = crtl->preferred_stack_boundary; | 4080 preferred_stack_boundary = crtl->preferred_stack_boundary; |
3676 | 4081 |
3677 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT; | 4082 preferred_unit_stack_boundary = preferred_stack_boundary / BITS_PER_UNIT; |
4083 | |
4084 if (flag_callgraph_info) | |
4085 record_final_call (fndecl, EXPR_LOCATION (exp)); | |
3678 | 4086 |
3679 /* We want to make two insn chains; one for a sibling call, the other | 4087 /* We want to make two insn chains; one for a sibling call, the other |
3680 for a normal call. We will select one of the two chains after | 4088 for a normal call. We will select one of the two chains after |
3681 initial RTL generation is complete. */ | 4089 initial RTL generation is complete. */ |
3682 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++) | 4090 for (pass = try_tail_call ? 0 : 1; pass < 2; pass++) |
4185 before_call = get_last_insn (); | 4593 before_call = get_last_insn (); |
4186 | 4594 |
4187 /* Set up next argument register. For sibling calls on machines | 4595 /* Set up next argument register. For sibling calls on machines |
4188 with register windows this should be the incoming register. */ | 4596 with register windows this should be the incoming register. */ |
4189 if (pass == 0) | 4597 if (pass == 0) |
4190 next_arg_reg = targetm.calls.function_incoming_arg (args_so_far, | 4598 next_arg_reg = targetm.calls.function_incoming_arg |
4191 VOIDmode, | 4599 (args_so_far, function_arg_info::end_marker ()); |
4192 void_type_node, | |
4193 true); | |
4194 else | 4600 else |
4195 next_arg_reg = targetm.calls.function_arg (args_so_far, | 4601 next_arg_reg = targetm.calls.function_arg |
4196 VOIDmode, void_type_node, | 4602 (args_so_far, function_arg_info::end_marker ()); |
4197 true); | |
4198 | 4603 |
4199 if (pass == 1 && (return_flags & ERF_RETURNS_ARG)) | 4604 if (pass == 1 && (return_flags & ERF_RETURNS_ARG)) |
4200 { | 4605 { |
4201 int arg_nr = return_flags & ERF_RETURN_ARG_MASK; | 4606 int arg_nr = return_flags & ERF_RETURN_ARG_MASK; |
4202 arg_nr = num_actuals - arg_nr - 1; | 4607 arg_nr = num_actuals - arg_nr - 1; |
4271 if (TREE_CODE (rettype) == POINTER_TYPE) | 4676 if (TREE_CODE (rettype) == POINTER_TYPE) |
4272 mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT); | 4677 mark_reg_pointer (temp, MALLOC_ABI_ALIGNMENT); |
4273 | 4678 |
4274 emit_move_insn (temp, valreg); | 4679 emit_move_insn (temp, valreg); |
4275 | 4680 |
4276 /* The return value from a malloc-like function can not alias | 4681 /* The return value from a malloc-like function cannot alias |
4277 anything else. */ | 4682 anything else. */ |
4278 last = get_last_insn (); | 4683 last = get_last_insn (); |
4279 add_reg_note (last, REG_NOALIAS, temp); | 4684 add_reg_note (last, REG_NOALIAS, temp); |
4280 | 4685 |
4281 /* Write out the sequence. */ | 4686 /* Write out the sequence. */ |
4809 | 5214 |
4810 argvec[count].value = addr; | 5215 argvec[count].value = addr; |
4811 argvec[count].mode = Pmode; | 5216 argvec[count].mode = Pmode; |
4812 argvec[count].partial = 0; | 5217 argvec[count].partial = 0; |
4813 | 5218 |
4814 argvec[count].reg = targetm.calls.function_arg (args_so_far, | 5219 function_arg_info ptr_arg (Pmode, /*named=*/true); |
4815 Pmode, NULL_TREE, true); | 5220 argvec[count].reg = targetm.calls.function_arg (args_so_far, ptr_arg); |
4816 gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, Pmode, | 5221 gcc_assert (targetm.calls.arg_partial_bytes (args_so_far, ptr_arg) == 0); |
4817 NULL_TREE, 1) == 0); | |
4818 | 5222 |
4819 locate_and_pad_parm (Pmode, NULL_TREE, | 5223 locate_and_pad_parm (Pmode, NULL_TREE, |
4820 #ifdef STACK_PARMS_IN_REG_PARM_AREA | 5224 #ifdef STACK_PARMS_IN_REG_PARM_AREA |
4821 1, | 5225 1, |
4822 #else | 5226 #else |
4827 | 5231 |
4828 if (argvec[count].reg == 0 || argvec[count].partial != 0 | 5232 if (argvec[count].reg == 0 || argvec[count].partial != 0 |
4829 || reg_parm_stack_space > 0) | 5233 || reg_parm_stack_space > 0) |
4830 args_size.constant += argvec[count].locate.size.constant; | 5234 args_size.constant += argvec[count].locate.size.constant; |
4831 | 5235 |
4832 targetm.calls.function_arg_advance (args_so_far, Pmode, (tree) 0, true); | 5236 targetm.calls.function_arg_advance (args_so_far, ptr_arg); |
4833 | 5237 |
4834 count++; | 5238 count++; |
4835 } | 5239 } |
4836 | 5240 |
4837 for (unsigned int i = 0; count < nargs; i++, count++) | 5241 for (unsigned int i = 0; count < nargs; i++, count++) |
4838 { | 5242 { |
4839 rtx val = args[i].first; | 5243 rtx val = args[i].first; |
4840 machine_mode mode = args[i].second; | 5244 function_arg_info arg (args[i].second, /*named=*/true); |
4841 int unsigned_p = 0; | 5245 int unsigned_p = 0; |
4842 | 5246 |
4843 /* We cannot convert the arg value to the mode the library wants here; | 5247 /* We cannot convert the arg value to the mode the library wants here; |
4844 must do it earlier where we know the signedness of the arg. */ | 5248 must do it earlier where we know the signedness of the arg. */ |
4845 gcc_assert (mode != BLKmode | 5249 gcc_assert (arg.mode != BLKmode |
4846 && (GET_MODE (val) == mode || GET_MODE (val) == VOIDmode)); | 5250 && (GET_MODE (val) == arg.mode |
5251 || GET_MODE (val) == VOIDmode)); | |
4847 | 5252 |
4848 /* Make sure it is a reasonable operand for a move or push insn. */ | 5253 /* Make sure it is a reasonable operand for a move or push insn. */ |
4849 if (!REG_P (val) && !MEM_P (val) | 5254 if (!REG_P (val) && !MEM_P (val) |
4850 && !(CONSTANT_P (val) && targetm.legitimate_constant_p (mode, val))) | 5255 && !(CONSTANT_P (val) |
5256 && targetm.legitimate_constant_p (arg.mode, val))) | |
4851 val = force_operand (val, NULL_RTX); | 5257 val = force_operand (val, NULL_RTX); |
4852 | 5258 |
4853 if (pass_by_reference (&args_so_far_v, mode, NULL_TREE, 1)) | 5259 if (pass_by_reference (&args_so_far_v, arg)) |
4854 { | 5260 { |
4855 rtx slot; | 5261 rtx slot; |
4856 int must_copy | 5262 int must_copy = !reference_callee_copied (&args_so_far_v, arg); |
4857 = !reference_callee_copied (&args_so_far_v, mode, NULL_TREE, 1); | |
4858 | 5263 |
4859 /* If this was a CONST function, it is now PURE since it now | 5264 /* If this was a CONST function, it is now PURE since it now |
4860 reads memory. */ | 5265 reads memory. */ |
4861 if (flags & ECF_CONST) | 5266 if (flags & ECF_CONST) |
4862 { | 5267 { |
4871 mark_addressable (val_expr); | 5276 mark_addressable (val_expr); |
4872 slot = val; | 5277 slot = val; |
4873 } | 5278 } |
4874 else | 5279 else |
4875 { | 5280 { |
4876 slot = assign_temp (lang_hooks.types.type_for_mode (mode, 0), | 5281 slot = assign_temp (lang_hooks.types.type_for_mode (arg.mode, 0), |
4877 1, 1); | 5282 1, 1); |
4878 emit_move_insn (slot, val); | 5283 emit_move_insn (slot, val); |
4879 } | 5284 } |
4880 | 5285 |
4881 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, | 5286 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, |
4885 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, | 5290 call_fusage = gen_rtx_EXPR_LIST (VOIDmode, |
4886 gen_rtx_CLOBBER (VOIDmode, | 5291 gen_rtx_CLOBBER (VOIDmode, |
4887 slot), | 5292 slot), |
4888 call_fusage); | 5293 call_fusage); |
4889 | 5294 |
4890 mode = Pmode; | 5295 arg.mode = Pmode; |
5296 arg.pass_by_reference = true; | |
4891 val = force_operand (XEXP (slot, 0), NULL_RTX); | 5297 val = force_operand (XEXP (slot, 0), NULL_RTX); |
4892 } | 5298 } |
4893 | 5299 |
4894 mode = promote_function_mode (NULL_TREE, mode, &unsigned_p, NULL_TREE, 0); | 5300 arg.mode = promote_function_mode (NULL_TREE, arg.mode, &unsigned_p, |
4895 argvec[count].mode = mode; | 5301 NULL_TREE, 0); |
4896 argvec[count].value = convert_modes (mode, GET_MODE (val), val, unsigned_p); | 5302 argvec[count].mode = arg.mode; |
4897 argvec[count].reg = targetm.calls.function_arg (args_so_far, mode, | 5303 argvec[count].value = convert_modes (arg.mode, GET_MODE (val), val, |
4898 NULL_TREE, true); | 5304 unsigned_p); |
5305 argvec[count].reg = targetm.calls.function_arg (args_so_far, arg); | |
4899 | 5306 |
4900 argvec[count].partial | 5307 argvec[count].partial |
4901 = targetm.calls.arg_partial_bytes (args_so_far, mode, NULL_TREE, 1); | 5308 = targetm.calls.arg_partial_bytes (args_so_far, arg); |
4902 | 5309 |
4903 if (argvec[count].reg == 0 | 5310 if (argvec[count].reg == 0 |
4904 || argvec[count].partial != 0 | 5311 || argvec[count].partial != 0 |
4905 || reg_parm_stack_space > 0) | 5312 || reg_parm_stack_space > 0) |
4906 { | 5313 { |
4907 locate_and_pad_parm (mode, NULL_TREE, | 5314 locate_and_pad_parm (arg.mode, NULL_TREE, |
4908 #ifdef STACK_PARMS_IN_REG_PARM_AREA | 5315 #ifdef STACK_PARMS_IN_REG_PARM_AREA |
4909 1, | 5316 1, |
4910 #else | 5317 #else |
4911 argvec[count].reg != 0, | 5318 argvec[count].reg != 0, |
4912 #endif | 5319 #endif |
4918 #ifdef BLOCK_REG_PADDING | 5325 #ifdef BLOCK_REG_PADDING |
4919 else | 5326 else |
4920 /* The argument is passed entirely in registers. See at which | 5327 /* The argument is passed entirely in registers. See at which |
4921 end it should be padded. */ | 5328 end it should be padded. */ |
4922 argvec[count].locate.where_pad = | 5329 argvec[count].locate.where_pad = |
4923 BLOCK_REG_PADDING (mode, NULL_TREE, | 5330 BLOCK_REG_PADDING (arg.mode, NULL_TREE, |
4924 known_le (GET_MODE_SIZE (mode), UNITS_PER_WORD)); | 5331 known_le (GET_MODE_SIZE (arg.mode), |
5332 UNITS_PER_WORD)); | |
4925 #endif | 5333 #endif |
4926 | 5334 |
4927 targetm.calls.function_arg_advance (args_so_far, mode, (tree) 0, true); | 5335 targetm.calls.function_arg_advance (args_so_far, arg); |
4928 } | 5336 } |
5337 | |
5338 for (int i = 0; i < nargs; i++) | |
5339 if (reg_parm_stack_space > 0 | |
5340 || argvec[i].reg == 0 | |
5341 || argvec[i].partial != 0) | |
5342 update_stack_alignment_for_call (&argvec[i].locate); | |
4929 | 5343 |
4930 /* If this machine requires an external definition for library | 5344 /* If this machine requires an external definition for library |
4931 functions, write one out. */ | 5345 functions, write one out. */ |
4932 assemble_external_libcall (fun); | 5346 assemble_external_libcall (fun); |
4933 | 5347 |
5252 gcc_assert (multiple_p (stack_pointer_delta, | 5666 gcc_assert (multiple_p (stack_pointer_delta, |
5253 PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)); | 5667 PREFERRED_STACK_BOUNDARY / BITS_PER_UNIT)); |
5254 | 5668 |
5255 before_call = get_last_insn (); | 5669 before_call = get_last_insn (); |
5256 | 5670 |
5671 if (flag_callgraph_info) | |
5672 record_final_call (SYMBOL_REF_DECL (orgfun), UNKNOWN_LOCATION); | |
5673 | |
5257 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which | 5674 /* We pass the old value of inhibit_defer_pop + 1 to emit_call_1, which |
5258 will set inhibit_defer_pop to that value. */ | 5675 will set inhibit_defer_pop to that value. */ |
5259 /* The return type is needed to decide how many bytes the function pops. | 5676 /* The return type is needed to decide how many bytes the function pops. |
5260 Signedness plays no role in that, so for simplicity, we pretend it's | 5677 Signedness plays no role in that, so for simplicity, we pretend it's |
5261 always signed. We also assume that the list of arguments passed has | 5678 always signed. We also assume that the list of arguments passed has |
5265 get_identifier (XSTR (orgfun, 0)), | 5682 get_identifier (XSTR (orgfun, 0)), |
5266 build_function_type (tfom, NULL_TREE), | 5683 build_function_type (tfom, NULL_TREE), |
5267 original_args_size.constant, args_size.constant, | 5684 original_args_size.constant, args_size.constant, |
5268 struct_value_size, | 5685 struct_value_size, |
5269 targetm.calls.function_arg (args_so_far, | 5686 targetm.calls.function_arg (args_so_far, |
5270 VOIDmode, void_type_node, true), | 5687 function_arg_info::end_marker ()), |
5271 valreg, | 5688 valreg, |
5272 old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far); | 5689 old_inhibit_defer_pop + 1, call_fusage, flags, args_so_far); |
5273 | 5690 |
5274 if (flag_ipa_ra) | 5691 if (flag_ipa_ra) |
5275 { | 5692 { |
5778 pop_temp_slots (); | 6195 pop_temp_slots (); |
5779 | 6196 |
5780 return sibcall_failure; | 6197 return sibcall_failure; |
5781 } | 6198 } |
5782 | 6199 |
5783 /* Nonzero if we do not know how to pass TYPE solely in registers. */ | 6200 /* Nonzero if we do not know how to pass ARG solely in registers. */ |
5784 | 6201 |
5785 bool | 6202 bool |
5786 must_pass_in_stack_var_size (machine_mode mode ATTRIBUTE_UNUSED, | 6203 must_pass_in_stack_var_size (const function_arg_info &arg) |
5787 const_tree type) | |
5788 { | 6204 { |
5789 if (!type) | 6205 if (!arg.type) |
5790 return false; | 6206 return false; |
5791 | 6207 |
5792 /* If the type has variable size... */ | 6208 /* If the type has variable size... */ |
5793 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) | 6209 if (!poly_int_tree_p (TYPE_SIZE (arg.type))) |
5794 return true; | 6210 return true; |
5795 | 6211 |
5796 /* If the type is marked as addressable (it is required | 6212 /* If the type is marked as addressable (it is required |
5797 to be constructed into the stack)... */ | 6213 to be constructed into the stack)... */ |
5798 if (TREE_ADDRESSABLE (type)) | 6214 if (TREE_ADDRESSABLE (arg.type)) |
5799 return true; | 6215 return true; |
5800 | 6216 |
5801 return false; | 6217 return false; |
5802 } | 6218 } |
5803 | 6219 |
5804 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one | 6220 /* Another version of the TARGET_MUST_PASS_IN_STACK hook. This one |
5805 takes trailing padding of a structure into account. */ | 6221 takes trailing padding of a structure into account. */ |
5806 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */ | 6222 /* ??? Should be able to merge these two by examining BLOCK_REG_PADDING. */ |
5807 | 6223 |
5808 bool | 6224 bool |
5809 must_pass_in_stack_var_size_or_pad (machine_mode mode, const_tree type) | 6225 must_pass_in_stack_var_size_or_pad (const function_arg_info &arg) |
5810 { | 6226 { |
5811 if (!type) | 6227 if (!arg.type) |
5812 return false; | 6228 return false; |
5813 | 6229 |
5814 /* If the type has variable size... */ | 6230 /* If the type has variable size... */ |
5815 if (TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST) | 6231 if (TREE_CODE (TYPE_SIZE (arg.type)) != INTEGER_CST) |
5816 return true; | 6232 return true; |
5817 | 6233 |
5818 /* If the type is marked as addressable (it is required | 6234 /* If the type is marked as addressable (it is required |
5819 to be constructed into the stack)... */ | 6235 to be constructed into the stack)... */ |
5820 if (TREE_ADDRESSABLE (type)) | 6236 if (TREE_ADDRESSABLE (arg.type)) |
5821 return true; | 6237 return true; |
5822 | 6238 |
5823 if (TYPE_EMPTY_P (type)) | 6239 if (TYPE_EMPTY_P (arg.type)) |
5824 return false; | 6240 return false; |
5825 | 6241 |
5826 /* If the padding and mode of the type is such that a copy into | 6242 /* If the padding and mode of the type is such that a copy into |
5827 a register would put it into the wrong part of the register. */ | 6243 a register would put it into the wrong part of the register. */ |
5828 if (mode == BLKmode | 6244 if (arg.mode == BLKmode |
5829 && int_size_in_bytes (type) % (PARM_BOUNDARY / BITS_PER_UNIT) | 6245 && int_size_in_bytes (arg.type) % (PARM_BOUNDARY / BITS_PER_UNIT) |
5830 && (targetm.calls.function_arg_padding (mode, type) | 6246 && (targetm.calls.function_arg_padding (arg.mode, arg.type) |
5831 == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD))) | 6247 == (BYTES_BIG_ENDIAN ? PAD_UPWARD : PAD_DOWNWARD))) |
5832 return true; | 6248 return true; |
5833 | 6249 |
5834 return false; | 6250 return false; |
5835 } | 6251 } |
5836 | 6252 |
6253 /* Return true if TYPE must be passed on the stack when passed to | |
6254 the "..." arguments of a function. */ | |
6255 | |
6256 bool | |
6257 must_pass_va_arg_in_stack (tree type) | |
6258 { | |
6259 function_arg_info arg (type, /*named=*/false); | |
6260 return targetm.calls.must_pass_in_stack (arg); | |
6261 } | |
6262 | |
5837 /* Tell the garbage collector about GTY markers in this source file. */ | 6263 /* Tell the garbage collector about GTY markers in this source file. */ |
5838 #include "gt-calls.h" | 6264 #include "gt-calls.h" |