Lines 754-761
Link Here
|
754 |
tree asmspec_tree, |
754 |
tree asmspec_tree, |
755 |
int flags) |
755 |
int flags) |
756 |
{ |
756 |
{ |
757 |
gcc_assert (TREE_PUBLIC (decl)); |
|
|
758 |
|
759 |
DECL_CONTEXT (decl) = current_class_type; |
757 |
DECL_CONTEXT (decl) = current_class_type; |
760 |
|
758 |
|
761 |
/* We cannot call pushdecl here, because that would fill in the |
759 |
/* We cannot call pushdecl here, because that would fill in the |
Lines 765-771
Link Here
|
765 |
if (!asmspec_tree && current_class_type) |
763 |
if (!asmspec_tree && current_class_type) |
766 |
DECL_INITIAL (decl) = error_mark_node; |
764 |
DECL_INITIAL (decl) = error_mark_node; |
767 |
|
765 |
|
768 |
if (! processing_template_decl) |
766 |
if (! processing_template_decl && TREE_PUBLIC (decl)) |
769 |
note_vague_linkage_var (decl); |
767 |
note_vague_linkage_var (decl); |
770 |
|
768 |
|
771 |
if (LOCAL_CLASS_P (current_class_type)) |
769 |
if (LOCAL_CLASS_P (current_class_type)) |
Lines 1578-1583
Link Here
|
1578 |
return true; |
1576 |
return true; |
1579 |
} |
1577 |
} |
1580 |
|
1578 |
|
|
|
1579 |
/* A special return value from type_visibility meaning internal |
1580 |
linkage. */ |
1581 |
|
1582 |
enum { VISIBILITY_STATIC = VISIBILITY_INTERNAL+1 }; |
1583 |
|
1584 |
/* walk_tree helper function for type_visibility. */ |
1585 |
|
1586 |
static tree |
1587 |
min_vis_r (tree *tp, int *walk_subtrees, void *data) |
1588 |
{ |
1589 |
int *vis_p = (int *)data; |
1590 |
if (! TYPE_P (*tp)) |
1591 |
{ |
1592 |
*walk_subtrees = 0; |
1593 |
} |
1594 |
else if (CLASS_TYPE_P (*tp)) |
1595 |
{ |
1596 |
if (!TREE_PUBLIC (TYPE_MAIN_DECL (*tp))) |
1597 |
{ |
1598 |
*vis_p = VISIBILITY_STATIC; |
1599 |
return *tp; |
1600 |
} |
1601 |
else if (CLASSTYPE_VISIBILITY (*tp) > *vis_p) |
1602 |
*vis_p = CLASSTYPE_VISIBILITY (*tp); |
1603 |
} |
1604 |
return NULL; |
1605 |
} |
1606 |
|
1607 |
/* Returns the visibility of TYPE, which is the minimum visibility of its |
1608 |
component types. */ |
1609 |
|
1610 |
static int |
1611 |
type_visibility (tree type) |
1612 |
{ |
1613 |
int vis = VISIBILITY_DEFAULT; |
1614 |
walk_tree_without_duplicates (&type, min_vis_r, &vis); |
1615 |
return vis; |
1616 |
} |
1617 |
|
1618 |
/* Limit the visibility of DECL to VISIBILITY. SPECIFIED is true if the |
1619 |
constraint comes from an attribute or pragma; REASON is the source of |
1620 |
the constraint. */ |
1621 |
|
1622 |
static bool |
1623 |
constrain_visibility (tree decl, int visibility, bool specified, |
1624 |
const char *reason) |
1625 |
{ |
1626 |
if (visibility == VISIBILITY_STATIC) |
1627 |
{ |
1628 |
TREE_PUBLIC (decl) = 0; |
1629 |
DECL_INTERFACE_KNOWN (decl) = 1; |
1630 |
if (DECL_LANG_SPECIFIC (decl)) |
1631 |
DECL_NOT_REALLY_EXTERN (decl) = 1; |
1632 |
} |
1633 |
else if (visibility > DECL_VISIBILITY (decl)) |
1634 |
{ |
1635 |
if (lookup_attribute ("visibility", DECL_ATTRIBUTES (decl))) |
1636 |
warning (OPT_Wattributes, "%q+D: visibility attribute requests " |
1637 |
"greater visibility than its %s allows", decl, reason); |
1638 |
DECL_VISIBILITY (decl) = visibility; |
1639 |
if (!DECL_VISIBILITY_SPECIFIED (decl)) |
1640 |
DECL_VISIBILITY_SPECIFIED (decl) = specified; |
1641 |
return true; |
1642 |
} |
1643 |
return false; |
1644 |
} |
1645 |
|
1646 |
/* Constrain the visibility of DECL based on the visbility of its template |
1647 |
arguments. */ |
1648 |
|
1649 |
static void |
1650 |
constrain_visibility_for_template (tree decl, tree targs) |
1651 |
{ |
1652 |
/* If this is a template instantiation, check the innermost |
1653 |
template args for visibility constraints. The outer template |
1654 |
args are covered by the class check. */ |
1655 |
tree args = INNERMOST_TEMPLATE_ARGS (targs); |
1656 |
int i; |
1657 |
for (i = TREE_VEC_LENGTH (args); i > 0; --i) |
1658 |
{ |
1659 |
int vis = 0; |
1660 |
|
1661 |
tree arg = TREE_VEC_ELT (args, i-1); |
1662 |
if (TYPE_P (arg)) |
1663 |
vis = type_visibility (arg); |
1664 |
else if (TREE_TYPE (arg) && POINTER_TYPE_P (TREE_TYPE (arg))) |
1665 |
{ |
1666 |
STRIP_NOPS (arg); |
1667 |
if (TREE_CODE (arg) == ADDR_EXPR) |
1668 |
arg = TREE_OPERAND (arg, 0); |
1669 |
if (TREE_CODE (arg) == VAR_DECL |
1670 |
|| TREE_CODE (arg) == FUNCTION_DECL) |
1671 |
{ |
1672 |
if (! TREE_PUBLIC (arg)) |
1673 |
vis = VISIBILITY_STATIC; |
1674 |
else |
1675 |
vis = DECL_VISIBILITY (arg); |
1676 |
} |
1677 |
} |
1678 |
if (vis) |
1679 |
constrain_visibility (decl, vis, false, "template parameter"); |
1680 |
} |
1681 |
} |
1682 |
|
1581 |
/* Like c_determine_visibility, but with additional C++-specific |
1683 |
/* Like c_determine_visibility, but with additional C++-specific |
1582 |
behavior. |
1684 |
behavior. |
1583 |
|
1685 |
|
Lines 1589-1601
Link Here
|
1589 |
|
1691 |
|
1590 |
Note that because namespaces have multiple independent definitions, |
1692 |
Note that because namespaces have multiple independent definitions, |
1591 |
namespace visibility is handled elsewhere using the #pragma visibility |
1693 |
namespace visibility is handled elsewhere using the #pragma visibility |
1592 |
machinery rather than by decorating the namespace declaration. */ |
1694 |
machinery rather than by decorating the namespace declaration. |
1593 |
|
1695 |
|
|
|
1696 |
The goal is for constraints from the type to give a diagnostic, and |
1697 |
other constraints to be applied silently. */ |
1698 |
|
1594 |
void |
1699 |
void |
1595 |
determine_visibility (tree decl) |
1700 |
determine_visibility (tree decl) |
1596 |
{ |
1701 |
{ |
1597 |
tree class_type; |
1702 |
tree class_type = NULL_TREE; |
|
|
1703 |
bool use_template; |
1598 |
|
1704 |
|
|
|
1705 |
/* Remember that all decls get VISIBILITY_DEFAULT when built. */ |
1706 |
|
1599 |
/* Only relevant for names with external linkage. */ |
1707 |
/* Only relevant for names with external linkage. */ |
1600 |
if (!TREE_PUBLIC (decl)) |
1708 |
if (!TREE_PUBLIC (decl)) |
1601 |
return; |
1709 |
return; |
Lines 1605-1614
Link Here
|
1605 |
maybe_clone_body. */ |
1713 |
maybe_clone_body. */ |
1606 |
gcc_assert (!DECL_CLONED_FUNCTION_P (decl)); |
1714 |
gcc_assert (!DECL_CLONED_FUNCTION_P (decl)); |
1607 |
|
1715 |
|
1608 |
/* Give the common code a chance to make a determination. */ |
1716 |
if (TREE_CODE (decl) == TYPE_DECL) |
1609 |
if (c_determine_visibility (decl)) |
1717 |
{ |
1610 |
return; |
1718 |
if (CLASS_TYPE_P (TREE_TYPE (decl))) |
|
|
1719 |
use_template = CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl)); |
1720 |
else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl))) |
1721 |
use_template = 1; |
1722 |
else |
1723 |
use_template = 0; |
1724 |
} |
1725 |
else if (DECL_LANG_SPECIFIC (decl)) |
1726 |
use_template = DECL_USE_TEMPLATE (decl); |
1727 |
else |
1728 |
use_template = 0; |
1611 |
|
1729 |
|
|
|
1730 |
/* Anything that is exported must have default visibility. */ |
1731 |
if (TARGET_DLLIMPORT_DECL_ATTRIBUTES |
1732 |
&& lookup_attribute ("dllexport", |
1733 |
TREE_CODE (decl) == TYPE_DECL |
1734 |
? TYPE_ATTRIBUTES (TREE_TYPE (decl)) |
1735 |
: DECL_ATTRIBUTES (decl))) |
1736 |
{ |
1737 |
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; |
1738 |
DECL_VISIBILITY_SPECIFIED (decl) = 1; |
1739 |
} |
1740 |
|
1612 |
/* If DECL is a member of a class, visibility specifiers on the |
1741 |
/* If DECL is a member of a class, visibility specifiers on the |
1613 |
class can influence the visibility of the DECL. */ |
1742 |
class can influence the visibility of the DECL. */ |
1614 |
if (DECL_CLASS_SCOPE_P (decl)) |
1743 |
if (DECL_CLASS_SCOPE_P (decl)) |
Lines 1619-1624
Link Here
|
1619 |
class_type = TREE_TYPE (DECL_NAME (decl)); |
1748 |
class_type = TREE_TYPE (DECL_NAME (decl)); |
1620 |
else |
1749 |
else |
1621 |
{ |
1750 |
{ |
|
|
1751 |
/* Not a class member. */ |
1752 |
|
1622 |
/* Virtual tables have DECL_CONTEXT set to their associated class, |
1753 |
/* Virtual tables have DECL_CONTEXT set to their associated class, |
1623 |
so they are automatically handled above. */ |
1754 |
so they are automatically handled above. */ |
1624 |
gcc_assert (TREE_CODE (decl) != VAR_DECL |
1755 |
gcc_assert (TREE_CODE (decl) != VAR_DECL |
Lines 1626-1704
Link Here
|
1626 |
|
1757 |
|
1627 |
if (DECL_FUNCTION_SCOPE_P (decl)) |
1758 |
if (DECL_FUNCTION_SCOPE_P (decl)) |
1628 |
{ |
1759 |
{ |
|
|
1760 |
/* Local statics and classes get the visibility of their |
1761 |
containing function. */ |
1629 |
tree fn = DECL_CONTEXT (decl); |
1762 |
tree fn = DECL_CONTEXT (decl); |
1630 |
DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn); |
1763 |
DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn); |
1631 |
DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn); |
1764 |
DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn); |
|
|
1765 |
|
1766 |
/* Local classes in templates have CLASSTYPE_USE_TEMPLATE set, |
1767 |
but have no TEMPLATE_INFO, so don't try to check it. */ |
1768 |
use_template = 0; |
1632 |
} |
1769 |
} |
|
|
1770 |
else if (TREE_CODE (decl) == VAR_DECL && DECL_TINFO_P (decl)) |
1771 |
{ |
1772 |
/* tinfo visibility is based on the type it's for. */ |
1773 |
constrain_visibility |
1774 |
(decl, type_visibility (TREE_TYPE (DECL_NAME (decl))), |
1775 |
false, "type"); |
1776 |
} |
1777 |
else if (use_template) |
1778 |
/* Template instantiations and specializations get visibility based |
1779 |
on their template unless they override it with an attribute. */; |
1780 |
else if (! DECL_VISIBILITY_SPECIFIED (decl)) |
1781 |
{ |
1782 |
/* Set default visibility to whatever the user supplied with |
1783 |
#pragma GCC visibility or a namespace visibility attribute. */ |
1784 |
DECL_VISIBILITY (decl) = default_visibility; |
1785 |
DECL_VISIBILITY_SPECIFIED (decl) = visibility_options.inpragma; |
1786 |
} |
1787 |
} |
1633 |
|
1788 |
|
1634 |
/* Entities not associated with any class just get the |
1789 |
if (use_template) |
1635 |
visibility specified by their attributes. */ |
1790 |
{ |
1636 |
return; |
1791 |
tree tinfo = (TREE_CODE (decl) == TYPE_DECL |
|
|
1792 |
? TYPE_TEMPLATE_INFO (TREE_TYPE (decl)) |
1793 |
: DECL_TEMPLATE_INFO (decl)); |
1794 |
tree args = TI_ARGS (tinfo); |
1795 |
int depth = TMPL_ARGS_DEPTH (args); |
1796 |
|
1797 |
/* If the template has explicit visibility and the specialization |
1798 |
doesn't, use the visibility from the template. */ |
1799 |
if (!DECL_VISIBILITY_SPECIFIED (decl)) |
1800 |
{ |
1801 |
tree pattern = DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo)); |
1802 |
DECL_VISIBILITY (decl) = DECL_VISIBILITY (pattern); |
1803 |
} |
1804 |
|
1805 |
/* FIXME should TMPL_ARGS_DEPTH really return 1 for null input? */ |
1806 |
if (args && depth > template_class_depth (class_type)) |
1807 |
/* Don't let it have more visibility than its template type |
1808 |
arguments. */ |
1809 |
constrain_visibility_for_template (decl, args); |
1637 |
} |
1810 |
} |
1638 |
|
1811 |
|
1639 |
/* By default, static data members and function members receive |
|
|
1640 |
the visibility of their containing class. */ |
1641 |
if (class_type) |
1812 |
if (class_type) |
1642 |
{ |
1813 |
determine_visibility_from_class (decl, class_type); |
1643 |
determine_visibility_from_class (decl, class_type); |
|
|
1644 |
|
1814 |
|
1645 |
/* Give the target a chance to override the visibility associated |
1815 |
/* Don't let it have more visibility than its type. */ |
1646 |
with DECL. */ |
1816 |
if (TREE_CODE (decl) != TYPE_DECL) |
1647 |
if (TREE_CODE (decl) == VAR_DECL |
1817 |
if (constrain_visibility (decl, type_visibility (TREE_TYPE (decl)), |
1648 |
&& (DECL_TINFO_P (decl) |
1818 |
false, "type")) |
1649 |
|| (DECL_VTABLE_OR_VTT_P (decl) |
1819 |
warning (OPT_Wattributes, "\ |
1650 |
/* Construction virtual tables are not exported because |
1820 |
%q+D declared with greater visibility than its type", |
1651 |
they cannot be referred to from other object files; |
1821 |
decl); |
1652 |
their name is not standardized by the ABI. */ |
1822 |
|
1653 |
&& !DECL_CONSTRUCTION_VTABLE_P (decl))) |
1823 |
if (decl_anon_ns_mem_p (decl)) |
1654 |
&& TREE_PUBLIC (decl) |
1824 |
/* Names in an anonymous namespace get internal linkage. |
1655 |
&& !DECL_REALLY_EXTERN (decl) |
1825 |
This might change once we implement export. */ |
1656 |
&& DECL_VISIBILITY_SPECIFIED (decl) |
1826 |
constrain_visibility (decl, VISIBILITY_STATIC, |
1657 |
&& (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))) |
1827 |
false, "namespace"); |
1658 |
targetm.cxx.determine_class_data_visibility (decl); |
|
|
1659 |
} |
1660 |
} |
1828 |
} |
1661 |
|
1829 |
|
|
|
1830 |
/* By default, static data members and function members receive |
1831 |
the visibility of their containing class. */ |
1832 |
|
1662 |
static void |
1833 |
static void |
1663 |
determine_visibility_from_class (tree decl, tree class_type) |
1834 |
determine_visibility_from_class (tree decl, tree class_type) |
1664 |
{ |
1835 |
{ |
1665 |
if (TARGET_DLLIMPORT_DECL_ATTRIBUTES |
1836 |
if (visibility_options.inlines_hidden |
1666 |
&& lookup_attribute ("dllexport", TYPE_ATTRIBUTES (class_type))) |
1837 |
/* Don't do this for inline templates; specializations might not be |
1667 |
{ |
1838 |
inline, and we don't want them to inherit the hidden |
1668 |
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT; |
1839 |
visibility. We'll set it here for all inline instantiations. */ |
1669 |
DECL_VISIBILITY_SPECIFIED (decl) = 1; |
1840 |
&& !processing_template_decl |
1670 |
} |
1841 |
&& ! DECL_VISIBILITY_SPECIFIED (decl) |
1671 |
else if (TREE_CODE (decl) == FUNCTION_DECL |
1842 |
&& TREE_CODE (decl) == FUNCTION_DECL |
1672 |
&& DECL_DECLARED_INLINE_P (decl) |
1843 |
&& DECL_DECLARED_INLINE_P (decl)) |
1673 |
&& visibility_options.inlines_hidden) |
1844 |
DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; |
1674 |
{ |
1845 |
|
1675 |
/* Don't change it if it has been set explicitly by user. */ |
1846 |
/* The decl can't have more visibility than its class. */ |
1676 |
if (!DECL_VISIBILITY_SPECIFIED (decl)) |
1847 |
constrain_visibility (decl, CLASSTYPE_VISIBILITY (class_type), |
1677 |
{ |
1848 |
CLASSTYPE_VISIBILITY_SPECIFIED (class_type), |
1678 |
DECL_VISIBILITY (decl) = VISIBILITY_HIDDEN; |
1849 |
"class"); |
1679 |
DECL_VISIBILITY_SPECIFIED (decl) = 1; |
1850 |
|
1680 |
} |
1851 |
/* Give the target a chance to override the visibility associated |
1681 |
} |
1852 |
with DECL. */ |
1682 |
else if (CLASSTYPE_VISIBILITY_SPECIFIED (class_type)) |
1853 |
if (TREE_CODE (decl) == VAR_DECL |
1683 |
{ |
1854 |
&& (DECL_TINFO_P (decl) |
1684 |
DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type); |
1855 |
|| (DECL_VTABLE_OR_VTT_P (decl) |
1685 |
DECL_VISIBILITY_SPECIFIED (decl) = 1; |
1856 |
/* Construction virtual tables are not exported because |
1686 |
} |
1857 |
they cannot be referred to from other object files; |
1687 |
else if (TYPE_CLASS_SCOPE_P (class_type)) |
1858 |
their name is not standardized by the ABI. */ |
1688 |
determine_visibility_from_class (decl, TYPE_CONTEXT (class_type)); |
1859 |
&& !DECL_CONSTRUCTION_VTABLE_P (decl))) |
1689 |
else if (TYPE_FUNCTION_SCOPE_P (class_type)) |
1860 |
&& TREE_PUBLIC (decl) |
1690 |
{ |
1861 |
&& !DECL_REALLY_EXTERN (decl) |
1691 |
tree fn = TYPE_CONTEXT (class_type); |
1862 |
&& DECL_VISIBILITY_SPECIFIED (decl) |
1692 |
DECL_VISIBILITY (decl) = DECL_VISIBILITY (fn); |
1863 |
&& (!class_type || !CLASSTYPE_VISIBILITY_SPECIFIED (class_type))) |
1693 |
DECL_VISIBILITY_SPECIFIED (decl) = DECL_VISIBILITY_SPECIFIED (fn); |
1864 |
targetm.cxx.determine_class_data_visibility (decl); |
1694 |
} |
|
|
1695 |
else if (!DECL_VISIBILITY_SPECIFIED (decl)) |
1696 |
{ |
1697 |
DECL_VISIBILITY (decl) = CLASSTYPE_VISIBILITY (class_type); |
1698 |
DECL_VISIBILITY_SPECIFIED (decl) = 0; |
1699 |
} |
1700 |
} |
1865 |
} |
1701 |
|
1866 |
|
|
|
1867 |
/* Constrain the visibility of a class TYPE based on the visibility of its |
1868 |
field types. Warn if any fields require lesser visibility. */ |
1869 |
|
1870 |
void |
1871 |
constrain_class_visibility (tree type) |
1872 |
{ |
1873 |
tree decl = TYPE_MAIN_DECL (type); |
1874 |
tree binfo = TYPE_BINFO (type); |
1875 |
tree t; |
1876 |
int i; |
1877 |
|
1878 |
for (t = TYPE_FIELDS (type); t; t = TREE_CHAIN (t)) |
1879 |
if (TREE_CODE (t) == FIELD_DECL) |
1880 |
if (constrain_visibility (decl, type_visibility (TREE_TYPE (t)), |
1881 |
false, "field type")) |
1882 |
warning (OPT_Wattributes, "\ |
1883 |
%qT declared with greater visibility than the type of its field %qD", |
1884 |
type, t); |
1885 |
|
1886 |
for (i = 0; BINFO_BASE_ITERATE (binfo, i, t); ++i) |
1887 |
if (constrain_visibility (decl, type_visibility (TREE_TYPE (t)), |
1888 |
false, "base type")) |
1889 |
warning (OPT_Wattributes, "\ |
1890 |
%qT declared with greater visibility than its base %qT", |
1891 |
type, TREE_TYPE (t)); |
1892 |
} |
1893 |
|
1702 |
/* DECL is a FUNCTION_DECL or VAR_DECL. If the object file linkage |
1894 |
/* DECL is a FUNCTION_DECL or VAR_DECL. If the object file linkage |
1703 |
for DECL has not already been determined, do so now by setting |
1895 |
for DECL has not already been determined, do so now by setting |
1704 |
DECL_EXTERNAL, DECL_COMDAT and other related flags. Until this |
1896 |
DECL_EXTERNAL, DECL_COMDAT and other related flags. Until this |