@@ -1453,61 +1453,20 @@ set_contract_functions (tree fndecl, tree pre, tree post)
1453
1453
set_postcondition_function (fndecl, post );
1454
1454
}
1455
1455
1456
- /* Return a copy of the function decl FNDECL with its own unshared
1457
- PARM_DECL and DECL_ATTRIBUTEs. */
1458
-
1459
- static tree
1460
- copy_fn_decl (tree fndecl)
1461
- {
1462
- gcc_checking_assert (!error_operand_p (fndecl));
1463
-
1464
- tree decl = copy_decl (fndecl);
1465
- DECL_ATTRIBUTES (decl) = copy_list (DECL_ATTRIBUTES (fndecl));
1466
-
1467
- if (DECL_RESULT (fndecl))
1468
- {
1469
- DECL_RESULT (decl) = copy_decl (DECL_RESULT (fndecl));
1470
- DECL_CONTEXT (DECL_RESULT (decl)) = decl;
1471
- }
1472
-
1473
- if (!DECL_ARGUMENTS (fndecl))
1474
- return decl;
1475
-
1476
- if (VOID_TYPE_P (DECL_ARGUMENTS (fndecl)))
1477
- {
1478
- DECL_ARGUMENTS (decl) = void_list_node;
1479
- return decl;
1480
- }
1481
-
1482
- tree last = DECL_ARGUMENTS (decl) = copy_decl (DECL_ARGUMENTS (decl));
1483
- DECL_CONTEXT (last) = decl;
1484
- for (tree p = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); p; p = TREE_CHAIN (p))
1485
- {
1486
- if (VOID_TYPE_P (p))
1487
- {
1488
- TREE_CHAIN (last) = void_list_node;
1489
- break ;
1490
- }
1491
- last = TREE_CHAIN (last) = copy_decl (p);
1492
- DECL_CONTEXT (last) = decl;
1493
- }
1494
- return decl;
1495
- }
1496
-
1497
1456
/* Build a declaration for the pre- or postcondition of a guarded FNDECL. */
1498
1457
1499
1458
static tree
1500
1459
build_contract_condition_function (tree fndecl, bool pre )
1501
1460
{
1502
- if (TREE_TYPE (fndecl) == error_mark_node )
1461
+ if (error_operand_p (fndecl))
1503
1462
return error_mark_node;
1463
+
1504
1464
if (DECL_IOBJ_MEMBER_FUNCTION_P (fndecl)
1505
1465
&& !TYPE_METHOD_BASETYPE (TREE_TYPE (fndecl)))
1506
1466
return error_mark_node;
1507
1467
1508
- /* Create and rename the unchecked function and give an internal name. */
1509
- tree fn = copy_fn_decl (fndecl);
1510
- DECL_RESULT (fn) = NULL_TREE;
1468
+ /* Start the copy. */
1469
+ tree fn = copy_decl (fndecl);
1511
1470
1512
1471
/* Don't propagate declaration attributes to the checking function,
1513
1472
including the original contracts. */
@@ -1525,12 +1484,11 @@ build_contract_condition_function (tree fndecl, bool pre)
1525
1484
if (DECL_ATTRIBUTES (fn))
1526
1485
cplus_decl_attributes (&fn, DECL_ATTRIBUTES (fn), 0 );
1527
1486
1487
+ /* FIXME will later optimizations delete unused args to prevent extra arg
1488
+ passing? do we care? */
1528
1489
/* Handle the args list. */
1529
1490
tree arg_types = NULL_TREE;
1530
1491
tree *last = &arg_types;
1531
-
1532
- /* FIXME will later optimizations delete unused args to prevent extra arg
1533
- passing? do we care? */
1534
1492
tree class_type = NULL_TREE;
1535
1493
for (tree arg_type = TYPE_ARG_TYPES (TREE_TYPE (fn));
1536
1494
arg_type && arg_type != void_list_node;
@@ -1546,6 +1504,20 @@ build_contract_condition_function (tree fndecl, bool pre)
1546
1504
last = &TREE_CHAIN (*last);
1547
1505
}
1548
1506
1507
+ /* Copy the function parameters, if present. Disable warnings for them. */
1508
+ DECL_ARGUMENTS (fn) = NULL_TREE;
1509
+ if (DECL_ARGUMENTS (fndecl))
1510
+ {
1511
+ tree *last_a = &DECL_ARGUMENTS (fn);
1512
+ for (tree p = DECL_ARGUMENTS (fndecl); p; p = TREE_CHAIN (p))
1513
+ {
1514
+ *last_a = copy_decl (p);
1515
+ suppress_warning (*last_a);
1516
+ DECL_CONTEXT (*last_a) = fn;
1517
+ last_a = &TREE_CHAIN (*last_a);
1518
+ }
1519
+ }
1520
+
1549
1521
tree orig_fn_value_type = TREE_TYPE (TREE_TYPE (fn));
1550
1522
if (!pre && !VOID_TYPE_P (orig_fn_value_type))
1551
1523
{
@@ -1555,19 +1527,23 @@ build_contract_condition_function (tree fndecl, bool pre)
1555
1527
tree parm = build_lang_decl (PARM_DECL, name, orig_fn_value_type);
1556
1528
DECL_CONTEXT (parm) = fn;
1557
1529
DECL_ARTIFICIAL (parm) = true ;
1530
+ suppress_warning (parm);
1558
1531
DECL_ARGUMENTS (fn) = chainon (DECL_ARGUMENTS (fn), parm);
1559
1532
*last = build_tree_list (NULL_TREE, orig_fn_value_type);
1560
1533
last = &TREE_CHAIN (*last);
1561
1534
}
1535
+
1562
1536
*last = void_list_node;
1563
- /* The handlers are void fns. */
1564
- TREE_TYPE (fn) = build_function_type (void_type_node, arg_types);
1565
1537
1566
- /* Disable warnings for all the parameters */
1567
- for (tree p = DECL_ARGUMENTS (fn); p && p!=void_list_node;
1568
- p = TREE_CHAIN (p))
1569
- suppress_warning (p);
1538
+ /* The handlers are void fns. */
1539
+ tree resdecl = build_decl (DECL_SOURCE_LOCATION (fndecl), RESULT_DECL,
1540
+ 0 , void_type_node);
1541
+ DECL_CONTEXT (resdecl) = fn;
1542
+ DECL_ARTIFICIAL (resdecl) = true ;
1543
+ DECL_IGNORED_P (resdecl) = true ;
1544
+ DECL_RESULT (fn) = resdecl;
1570
1545
1546
+ TREE_TYPE (fn) = build_function_type (void_type_node, arg_types);
1571
1547
if (DECL_IOBJ_MEMBER_FUNCTION_P (fndecl))
1572
1548
TREE_TYPE (fn) = build_method_type (class_type, TREE_TYPE (fn));
1573
1549
@@ -1898,9 +1874,22 @@ build_contract_wrapper_function (tree fndecl, bool is_cvh,
1898
1874
1899
1875
location_t loc = DECL_SOURCE_LOCATION (fndecl);
1900
1876
1901
- tree wrapper_return_type = TREE_TYPE (TREE_TYPE (fndecl));
1902
- tree wrapper_args = TYPE_ARG_TYPES (TREE_TYPE (fndecl));
1877
+ /* Handle the arg types list. */
1878
+ tree wrapper_args = NULL_TREE;
1879
+ tree *last = &wrapper_args;
1880
+ for (tree arg_type = TYPE_ARG_TYPES (TREE_TYPE (fndecl)); arg_type;
1881
+ arg_type = TREE_CHAIN (arg_type))
1882
+ {
1883
+ if (arg_type == void_list_node)
1884
+ {
1885
+ *last = void_list_node;
1886
+ break ;
1887
+ }
1888
+ *last = build_tree_list (TREE_PURPOSE (arg_type), TREE_VALUE (arg_type));
1889
+ last = &TREE_CHAIN (*last);
1890
+ }
1903
1891
1892
+ tree wrapper_return_type = copy_node (TREE_TYPE (TREE_TYPE (fndecl)));
1904
1893
tree wrapper_type = build_function_type (wrapper_return_type, wrapper_args);
1905
1894
1906
1895
/* Contract violation wrapper function is always noexcept. Otherwise,
@@ -1930,19 +1919,19 @@ build_contract_wrapper_function (tree fndecl, bool is_cvh,
1930
1919
DECL_IGNORED_P (resdecl) = true ;
1931
1920
DECL_RESULT (wrapdecl) = resdecl;
1932
1921
1933
- /* Copy the function parameters. */
1934
- tree last = DECL_ARGUMENTS (wrapdecl) = copy_decl ( DECL_ARGUMENTS (fndecl));
1935
- DECL_CONTEXT (last ) = wrapdecl ;
1936
- for (tree p = TREE_CHAIN ( DECL_ARGUMENTS (fndecl)); p; p = TREE_CHAIN (p ))
1922
+ /* Copy the function parameters, if present . Suppress (e.g. unused)
1923
+ warnings on them. */
1924
+ DECL_ARGUMENTS (wrapdecl ) = NULL_TREE ;
1925
+ if (tree p = DECL_ARGUMENTS (fndecl))
1937
1926
{
1938
- if (VOID_TYPE_P (p))
1927
+ tree *last_a = &DECL_ARGUMENTS (wrapdecl);
1928
+ for (; p; p = TREE_CHAIN (p))
1939
1929
{
1940
- TREE_CHAIN (last) = void_list_node;
1941
- break ;
1930
+ *last_a = copy_decl (p);
1931
+ suppress_warning (*last_a);
1932
+ DECL_CONTEXT (*last_a) = wrapdecl;
1933
+ last_a = &TREE_CHAIN (*last_a);
1942
1934
}
1943
- suppress_warning (p);
1944
- last = TREE_CHAIN (last) = copy_decl (p);
1945
- DECL_CONTEXT (last) = wrapdecl;
1946
1935
}
1947
1936
1948
1937
/* Copy selected attributes from the original function. */
0 commit comments