Mercurial > hg > CbC > CbC_gcc
comparison gcc/c/c-decl.c @ 132:d34655255c78
update gcc-8.2
author | mir3636 |
---|---|
date | Thu, 25 Oct 2018 10:21:07 +0900 |
parents | bdf41c9fa0b7 84e7813d76e9 |
children | 351920fa3827 |
comparison
equal
deleted
inserted
replaced
130:e108057fa461 | 132:d34655255c78 |
---|---|
1 /* Process declarations and variables for C compiler. | 1 /* Process declarations and variables for C compiler. |
2 Copyright (C) 1988-2017 Free Software Foundation, Inc. | 2 Copyright (C) 1988-2018 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 |
23 | 23 |
24 /* ??? not all decl nodes are given the most useful possible | 24 /* ??? not all decl nodes are given the most useful possible |
25 line numbers. For example, the CONST_DECLs for enum values. */ | 25 line numbers. For example, the CONST_DECLs for enum values. */ |
26 | 26 |
27 #include "config.h" | 27 #include "config.h" |
28 #define INCLUDE_UNIQUE_PTR | |
28 #include "system.h" | 29 #include "system.h" |
29 #include "coretypes.h" | 30 #include "coretypes.h" |
30 #include "target.h" | 31 #include "target.h" |
31 #include "function.h" | 32 #include "function.h" |
32 #include "c-tree.h" | 33 #include "c-tree.h" |
47 #include "langhooks.h" | 48 #include "langhooks.h" |
48 #include "tree-iterator.h" | 49 #include "tree-iterator.h" |
49 #include "dumpfile.h" | 50 #include "dumpfile.h" |
50 #include "plugin.h" | 51 #include "plugin.h" |
51 #include "c-family/c-ada-spec.h" | 52 #include "c-family/c-ada-spec.h" |
52 #include "cilk.h" | |
53 #include "builtins.h" | 53 #include "builtins.h" |
54 #include "spellcheck-tree.h" | 54 #include "spellcheck-tree.h" |
55 #include "gcc-rich-location.h" | 55 #include "gcc-rich-location.h" |
56 #include "asan.h" | 56 #include "asan.h" |
57 #include "c-family/name-hint.h" | |
58 #include "c-family/known-headers.h" | |
59 #include "c-family/c-spellcheck.h" | |
57 #ifndef noCbC | 60 #ifndef noCbC |
58 #include "cbc-tree.h" | 61 #include "cbc-tree.h" |
59 tree cbc_env; | 62 tree cbc_env; |
60 tree cbc_return_f; | 63 tree cbc_return_f; |
61 location_t cbc_return; | 64 location_t cbc_return; |
951 | 954 |
952 bool | 955 bool |
953 global_bindings_p (void) | 956 global_bindings_p (void) |
954 { | 957 { |
955 return current_scope == file_scope; | 958 return current_scope == file_scope; |
959 } | |
960 | |
961 /* Return true if we're declaring parameters in an old-style function | |
962 declaration. */ | |
963 | |
964 bool | |
965 old_style_parameter_scope (void) | |
966 { | |
967 /* If processing parameters and there is no function statement list, we | |
968 * have an old-style function declaration. */ | |
969 return (current_scope->parm_flag && !DECL_SAVED_TREE (current_function_decl)); | |
956 } | 970 } |
957 | 971 |
958 void | 972 void |
959 keep_next_level (void) | 973 keep_next_level (void) |
960 { | 974 { |
1561 && (B_IN_CURRENT_SCOPE (b) | 1575 && (B_IN_CURRENT_SCOPE (b) |
1562 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) | 1576 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) |
1563 && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) | 1577 && (TYPE_MAIN_VARIANT (TREE_TYPE (b->decl)) |
1564 != TYPE_MAIN_VARIANT (type))) | 1578 != TYPE_MAIN_VARIANT (type))) |
1565 { | 1579 { |
1580 auto_diagnostic_group d; | |
1566 if (warning_at (loc, OPT_Wc___compat, | 1581 if (warning_at (loc, OPT_Wc___compat, |
1567 ("using %qD as both a typedef and a tag is " | 1582 ("using %qD as both a typedef and a tag is " |
1568 "invalid in C++"), b->decl) | 1583 "invalid in C++"), b->decl) |
1569 && b->locus != UNKNOWN_LOCATION) | 1584 && b->locus != UNKNOWN_LOCATION) |
1570 inform (b->locus, "originally defined here"); | 1585 inform (b->locus, "originally defined here"); |
1789 first in a pair of mismatched declarations, using the diagnostic | 1804 first in a pair of mismatched declarations, using the diagnostic |
1790 function DIAG. */ | 1805 function DIAG. */ |
1791 static void | 1806 static void |
1792 locate_old_decl (tree decl) | 1807 locate_old_decl (tree decl) |
1793 { | 1808 { |
1794 if (TREE_CODE (decl) == FUNCTION_DECL && DECL_BUILT_IN (decl) | 1809 if (TREE_CODE (decl) == FUNCTION_DECL && fndecl_built_in_p (decl) |
1795 && !C_DECL_DECLARED_BUILTIN (decl)) | 1810 && !C_DECL_DECLARED_BUILTIN (decl)) |
1796 ; | 1811 ; |
1797 else if (DECL_INITIAL (decl)) | 1812 else if (DECL_INITIAL (decl)) |
1798 inform (input_location, "previous definition of %q+D was here", decl); | 1813 inform (input_location, "previous definition of %q+D was here", decl); |
1799 else if (C_DECL_IMPLICIT (decl)) | 1814 else if (C_DECL_IMPLICIT (decl)) |
1813 static bool | 1828 static bool |
1814 diagnose_mismatched_decls (tree newdecl, tree olddecl, | 1829 diagnose_mismatched_decls (tree newdecl, tree olddecl, |
1815 tree *newtypep, tree *oldtypep) | 1830 tree *newtypep, tree *oldtypep) |
1816 { | 1831 { |
1817 tree newtype, oldtype; | 1832 tree newtype, oldtype; |
1818 bool pedwarned = false; | |
1819 bool warned = false; | |
1820 bool retval = true; | 1833 bool retval = true; |
1821 | 1834 |
1822 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \ | 1835 #define DECL_EXTERN_INLINE(DECL) (DECL_DECLARED_INLINE_P (DECL) \ |
1823 && DECL_EXTERNAL (DECL)) | 1836 && DECL_EXTERNAL (DECL)) |
1824 | 1837 |
1834 /* Two different categories of symbol altogether. This is an error | 1847 /* Two different categories of symbol altogether. This is an error |
1835 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */ | 1848 unless OLDDECL is a builtin. OLDDECL will be discarded in any case. */ |
1836 if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) | 1849 if (TREE_CODE (olddecl) != TREE_CODE (newdecl)) |
1837 { | 1850 { |
1838 if (!(TREE_CODE (olddecl) == FUNCTION_DECL | 1851 if (!(TREE_CODE (olddecl) == FUNCTION_DECL |
1839 && DECL_BUILT_IN (olddecl) | 1852 && fndecl_built_in_p (olddecl) |
1840 && !C_DECL_DECLARED_BUILTIN (olddecl))) | 1853 && !C_DECL_DECLARED_BUILTIN (olddecl))) |
1841 { | 1854 { |
1855 auto_diagnostic_group d; | |
1842 error ("%q+D redeclared as different kind of symbol", newdecl); | 1856 error ("%q+D redeclared as different kind of symbol", newdecl); |
1843 locate_old_decl (olddecl); | 1857 locate_old_decl (olddecl); |
1844 } | 1858 } |
1845 else if (TREE_PUBLIC (newdecl)) | 1859 else if (TREE_PUBLIC (newdecl)) |
1846 warning (OPT_Wbuiltin_declaration_mismatch, | 1860 warning (OPT_Wbuiltin_declaration_mismatch, |
1854 | 1868 |
1855 /* Enumerators have no linkage, so may only be declared once in a | 1869 /* Enumerators have no linkage, so may only be declared once in a |
1856 given scope. */ | 1870 given scope. */ |
1857 if (TREE_CODE (olddecl) == CONST_DECL) | 1871 if (TREE_CODE (olddecl) == CONST_DECL) |
1858 { | 1872 { |
1873 auto_diagnostic_group d; | |
1859 error ("redeclaration of enumerator %q+D", newdecl); | 1874 error ("redeclaration of enumerator %q+D", newdecl); |
1860 locate_old_decl (olddecl); | 1875 locate_old_decl (olddecl); |
1861 return false; | 1876 return false; |
1862 } | 1877 } |
1863 | 1878 |
1879 bool pedwarned = false; | |
1880 bool warned = false; | |
1881 auto_diagnostic_group d; | |
1882 | |
1864 if (!comptypes (oldtype, newtype)) | 1883 if (!comptypes (oldtype, newtype)) |
1865 { | 1884 { |
1866 if (TREE_CODE (olddecl) == FUNCTION_DECL | 1885 if (TREE_CODE (olddecl) == FUNCTION_DECL |
1867 && DECL_BUILT_IN (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) | 1886 && fndecl_built_in_p (olddecl) && !C_DECL_DECLARED_BUILTIN (olddecl)) |
1868 { | 1887 { |
1869 /* Accept harmless mismatch in function types. | 1888 /* Accept harmless mismatch in function types. |
1870 This is for the ffs and fprintf builtins. */ | 1889 This is for the ffs and fprintf builtins. */ |
1871 tree trytype = match_builtin_function_types (newtype, oldtype); | 1890 tree trytype = match_builtin_function_types (newtype, oldtype); |
1872 | 1891 |
2010 { | 2029 { |
2011 /* If you declare a built-in function name as static, or | 2030 /* If you declare a built-in function name as static, or |
2012 define the built-in with an old-style definition (so we | 2031 define the built-in with an old-style definition (so we |
2013 can't validate the argument list) the built-in definition is | 2032 can't validate the argument list) the built-in definition is |
2014 overridden, but optionally warn this was a bad choice of name. */ | 2033 overridden, but optionally warn this was a bad choice of name. */ |
2015 if (DECL_BUILT_IN (olddecl) | 2034 if (fndecl_built_in_p (olddecl) |
2016 && !C_DECL_DECLARED_BUILTIN (olddecl) | 2035 && !C_DECL_DECLARED_BUILTIN (olddecl) |
2017 && (!TREE_PUBLIC (newdecl) | 2036 && (!TREE_PUBLIC (newdecl) |
2018 || (DECL_INITIAL (newdecl) | 2037 || (DECL_INITIAL (newdecl) |
2019 && !prototype_p (TREE_TYPE (newdecl))))) | 2038 && !prototype_p (TREE_TYPE (newdecl))))) |
2020 { | 2039 { |
2042 || !lookup_attribute ("gnu_inline", | 2061 || !lookup_attribute ("gnu_inline", |
2043 DECL_ATTRIBUTES (newdecl)))) | 2062 DECL_ATTRIBUTES (newdecl)))) |
2044 ) | 2063 ) |
2045 && same_translation_unit_p (newdecl, olddecl)) | 2064 && same_translation_unit_p (newdecl, olddecl)) |
2046 { | 2065 { |
2066 auto_diagnostic_group d; | |
2047 error ("redefinition of %q+D", newdecl); | 2067 error ("redefinition of %q+D", newdecl); |
2048 locate_old_decl (olddecl); | 2068 locate_old_decl (olddecl); |
2049 return false; | 2069 return false; |
2050 } | 2070 } |
2051 } | 2071 } |
2052 } | 2072 } |
2053 /* If we have a prototype after an old-style function definition, | 2073 /* If we have a prototype after an old-style function definition, |
2054 the argument types must be checked specially. */ | 2074 the argument types must be checked specially. */ |
2055 else if (DECL_INITIAL (olddecl) | 2075 else if (DECL_INITIAL (olddecl) |
2056 && !prototype_p (oldtype) && prototype_p (newtype) | 2076 && !prototype_p (oldtype) && prototype_p (newtype) |
2057 && TYPE_ACTUAL_ARG_TYPES (oldtype) | 2077 && TYPE_ACTUAL_ARG_TYPES (oldtype)) |
2058 && !validate_proto_after_old_defn (newdecl, newtype, oldtype)) | 2078 { |
2059 { | 2079 auto_diagnostic_group d; |
2060 locate_old_decl (olddecl); | 2080 if (!validate_proto_after_old_defn (newdecl, newtype, oldtype)) |
2061 return false; | 2081 { |
2082 locate_old_decl (olddecl); | |
2083 return false; | |
2084 } | |
2062 } | 2085 } |
2063 /* A non-static declaration (even an "extern") followed by a | 2086 /* A non-static declaration (even an "extern") followed by a |
2064 static declaration is undefined behavior per C99 6.2.2p3-5,7. | 2087 static declaration is undefined behavior per C99 6.2.2p3-5,7. |
2065 The same is true for a static forward declaration at block | 2088 The same is true for a static forward declaration at block |
2066 scope followed by a non-static declaration/definition at file | 2089 scope followed by a non-static declaration/definition at file |
2077 occur only in Objective C; see also above. (FIXME: Make | 2100 occur only in Objective C; see also above. (FIXME: Make |
2078 Objective C use normal builtins.) */ | 2101 Objective C use normal builtins.) */ |
2079 if (!DECL_IS_BUILTIN (olddecl) | 2102 if (!DECL_IS_BUILTIN (olddecl) |
2080 && !DECL_EXTERN_INLINE (olddecl)) | 2103 && !DECL_EXTERN_INLINE (olddecl)) |
2081 { | 2104 { |
2105 auto_diagnostic_group d; | |
2082 error ("static declaration of %q+D follows " | 2106 error ("static declaration of %q+D follows " |
2083 "non-static declaration", newdecl); | 2107 "non-static declaration", newdecl); |
2084 locate_old_decl (olddecl); | 2108 locate_old_decl (olddecl); |
2085 } | 2109 } |
2086 return false; | 2110 return false; |
2087 } | 2111 } |
2088 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)) | 2112 else if (TREE_PUBLIC (newdecl) && !TREE_PUBLIC (olddecl)) |
2089 { | 2113 { |
2090 if (DECL_CONTEXT (olddecl)) | 2114 if (DECL_CONTEXT (olddecl)) |
2091 { | 2115 { |
2116 auto_diagnostic_group d; | |
2092 error ("non-static declaration of %q+D follows " | 2117 error ("non-static declaration of %q+D follows " |
2093 "static declaration", newdecl); | 2118 "static declaration", newdecl); |
2094 locate_old_decl (olddecl); | 2119 locate_old_decl (olddecl); |
2095 return false; | 2120 return false; |
2096 } | 2121 } |
2111 DECL_ATTRIBUTES (newdecl)) != NULL; | 2136 DECL_ATTRIBUTES (newdecl)) != NULL; |
2112 bool olda = lookup_attribute ("gnu_inline", | 2137 bool olda = lookup_attribute ("gnu_inline", |
2113 DECL_ATTRIBUTES (olddecl)) != NULL; | 2138 DECL_ATTRIBUTES (olddecl)) != NULL; |
2114 if (newa != olda) | 2139 if (newa != olda) |
2115 { | 2140 { |
2141 auto_diagnostic_group d; | |
2116 error_at (input_location, "%<gnu_inline%> attribute present on %q+D", | 2142 error_at (input_location, "%<gnu_inline%> attribute present on %q+D", |
2117 newa ? newdecl : olddecl); | 2143 newa ? newdecl : olddecl); |
2118 error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl), | 2144 error_at (DECL_SOURCE_LOCATION (newa ? olddecl : newdecl), |
2119 "but not here"); | 2145 "but not here"); |
2120 } | 2146 } |
2131 will merge the threadprivate attribute into NEWDECL. */ | 2157 will merge the threadprivate attribute into NEWDECL. */ |
2132 ; | 2158 ; |
2133 } | 2159 } |
2134 else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)) | 2160 else if (DECL_THREAD_LOCAL_P (newdecl) != DECL_THREAD_LOCAL_P (olddecl)) |
2135 { | 2161 { |
2162 auto_diagnostic_group d; | |
2136 if (DECL_THREAD_LOCAL_P (newdecl)) | 2163 if (DECL_THREAD_LOCAL_P (newdecl)) |
2137 error ("thread-local declaration of %q+D follows " | 2164 error ("thread-local declaration of %q+D follows " |
2138 "non-thread-local declaration", newdecl); | 2165 "non-thread-local declaration", newdecl); |
2139 else | 2166 else |
2140 error ("non-thread-local declaration of %q+D follows " | 2167 error ("non-thread-local declaration of %q+D follows " |
2145 } | 2172 } |
2146 | 2173 |
2147 /* Multiple initialized definitions are not allowed (6.9p3,5). */ | 2174 /* Multiple initialized definitions are not allowed (6.9p3,5). */ |
2148 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl)) | 2175 if (DECL_INITIAL (newdecl) && DECL_INITIAL (olddecl)) |
2149 { | 2176 { |
2177 auto_diagnostic_group d; | |
2150 error ("redefinition of %q+D", newdecl); | 2178 error ("redefinition of %q+D", newdecl); |
2151 locate_old_decl (olddecl); | 2179 locate_old_decl (olddecl); |
2152 return false; | 2180 return false; |
2153 } | 2181 } |
2154 | 2182 |
2165 { | 2193 { |
2166 if (DECL_EXTERNAL (newdecl)) | 2194 if (DECL_EXTERNAL (newdecl)) |
2167 { | 2195 { |
2168 if (!DECL_FILE_SCOPE_P (olddecl)) | 2196 if (!DECL_FILE_SCOPE_P (olddecl)) |
2169 { | 2197 { |
2198 auto_diagnostic_group d; | |
2170 error ("extern declaration of %q+D follows " | 2199 error ("extern declaration of %q+D follows " |
2171 "declaration with no linkage", newdecl); | 2200 "declaration with no linkage", newdecl); |
2172 locate_old_decl (olddecl); | 2201 locate_old_decl (olddecl); |
2173 return false; | 2202 return false; |
2174 } | 2203 } |
2179 "follows static declaration", newdecl); | 2208 "follows static declaration", newdecl); |
2180 } | 2209 } |
2181 } | 2210 } |
2182 else | 2211 else |
2183 { | 2212 { |
2213 auto_diagnostic_group d; | |
2184 if (TREE_PUBLIC (newdecl)) | 2214 if (TREE_PUBLIC (newdecl)) |
2185 error ("non-static declaration of %q+D follows " | 2215 error ("non-static declaration of %q+D follows " |
2186 "static declaration", newdecl); | 2216 "static declaration", newdecl); |
2187 else | 2217 else |
2188 error ("static declaration of %q+D follows " | 2218 error ("static declaration of %q+D follows " |
2201 /* Extern with initializer at block scope, which will | 2231 /* Extern with initializer at block scope, which will |
2202 already have received an error. */ | 2232 already have received an error. */ |
2203 } | 2233 } |
2204 else if (DECL_EXTERNAL (olddecl)) | 2234 else if (DECL_EXTERNAL (olddecl)) |
2205 { | 2235 { |
2236 auto_diagnostic_group d; | |
2206 error ("declaration of %q+D with no linkage follows " | 2237 error ("declaration of %q+D with no linkage follows " |
2207 "extern declaration", newdecl); | 2238 "extern declaration", newdecl); |
2208 locate_old_decl (olddecl); | 2239 locate_old_decl (olddecl); |
2209 } | 2240 } |
2210 else | 2241 else |
2211 { | 2242 { |
2243 auto_diagnostic_group d; | |
2212 error ("redeclaration of %q+D with no linkage", newdecl); | 2244 error ("redeclaration of %q+D with no linkage", newdecl); |
2213 locate_old_decl (olddecl); | 2245 locate_old_decl (olddecl); |
2214 } | 2246 } |
2215 | 2247 |
2216 return false; | 2248 return false; |
2253 mark_forward_parm_decls. */ | 2285 mark_forward_parm_decls. */ |
2254 | 2286 |
2255 if (TREE_CODE (newdecl) == PARM_DECL | 2287 if (TREE_CODE (newdecl) == PARM_DECL |
2256 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) | 2288 && (!TREE_ASM_WRITTEN (olddecl) || TREE_ASM_WRITTEN (newdecl))) |
2257 { | 2289 { |
2290 auto_diagnostic_group d; | |
2258 error ("redefinition of parameter %q+D", newdecl); | 2291 error ("redefinition of parameter %q+D", newdecl); |
2259 locate_old_decl (olddecl); | 2292 locate_old_decl (olddecl); |
2260 return false; | 2293 return false; |
2261 } | 2294 } |
2262 } | 2295 } |
2268 definition. */ | 2301 definition. */ |
2269 && !(TREE_CODE (newdecl) == FUNCTION_DECL | 2302 && !(TREE_CODE (newdecl) == FUNCTION_DECL |
2270 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) | 2303 && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) |
2271 /* Don't warn about redundant redeclarations of builtins. */ | 2304 /* Don't warn about redundant redeclarations of builtins. */ |
2272 && !(TREE_CODE (newdecl) == FUNCTION_DECL | 2305 && !(TREE_CODE (newdecl) == FUNCTION_DECL |
2273 && !DECL_BUILT_IN (newdecl) | 2306 && !fndecl_built_in_p (newdecl) |
2274 && DECL_BUILT_IN (olddecl) | 2307 && fndecl_built_in_p (olddecl) |
2275 && !C_DECL_DECLARED_BUILTIN (olddecl)) | 2308 && !C_DECL_DECLARED_BUILTIN (olddecl)) |
2276 /* Don't warn about an extern followed by a definition. */ | 2309 /* Don't warn about an extern followed by a definition. */ |
2277 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) | 2310 && !(DECL_EXTERNAL (olddecl) && !DECL_EXTERNAL (newdecl)) |
2278 /* Don't warn about forward parameter decls. */ | 2311 /* Don't warn about forward parameter decls. */ |
2279 && !(TREE_CODE (newdecl) == PARM_DECL | 2312 && !(TREE_CODE (newdecl) == PARM_DECL |
2547 = DECL_DISREGARD_INLINE_LIMITS (olddecl) | 2580 = DECL_DISREGARD_INLINE_LIMITS (olddecl) |
2548 = (DECL_DISREGARD_INLINE_LIMITS (newdecl) | 2581 = (DECL_DISREGARD_INLINE_LIMITS (newdecl) |
2549 || DECL_DISREGARD_INLINE_LIMITS (olddecl)); | 2582 || DECL_DISREGARD_INLINE_LIMITS (olddecl)); |
2550 } | 2583 } |
2551 | 2584 |
2552 if (DECL_BUILT_IN (olddecl)) | 2585 if (fndecl_built_in_p (olddecl)) |
2553 { | 2586 { |
2554 /* If redeclaring a builtin function, it stays built in. | 2587 /* If redeclaring a builtin function, it stays built in. |
2555 But it gets tagged as having been declared. */ | 2588 But it gets tagged as having been declared. */ |
2556 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); | 2589 DECL_BUILT_IN_CLASS (newdecl) = DECL_BUILT_IN_CLASS (olddecl); |
2557 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); | 2590 DECL_FUNCTION_CODE (newdecl) = DECL_FUNCTION_CODE (olddecl); |
2755 /* Shadow warnings wanted? */ | 2788 /* Shadow warnings wanted? */ |
2756 if (!(warn_shadow | 2789 if (!(warn_shadow |
2757 || warn_shadow_local | 2790 || warn_shadow_local |
2758 || warn_shadow_compatible_local) | 2791 || warn_shadow_compatible_local) |
2759 /* No shadow warnings for internally generated vars. */ | 2792 /* No shadow warnings for internally generated vars. */ |
2760 || DECL_IS_BUILTIN (new_decl) | 2793 || DECL_IS_BUILTIN (new_decl)) |
2761 /* No shadow warnings for vars made for inlining. */ | |
2762 || DECL_FROM_INLINE (new_decl)) | |
2763 return; | 2794 return; |
2764 | 2795 |
2765 /* Is anything being shadowed? Invisible decls do not count. */ | 2796 /* Is anything being shadowed? Invisible decls do not count. */ |
2766 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed) | 2797 for (b = I_SYMBOL_BINDING (DECL_NAME (new_decl)); b; b = b->shadowed) |
2767 if (b->decl && b->decl != new_decl && !b->invisible | 2798 if (b->decl && b->decl != new_decl && !b->invisible |
2768 && (b->decl == error_mark_node | 2799 && (b->decl == error_mark_node |
2769 || diagnostic_report_warnings_p (global_dc, | 2800 || diagnostic_report_warnings_p (global_dc, |
2770 DECL_SOURCE_LOCATION (b->decl)))) | 2801 DECL_SOURCE_LOCATION (b->decl)))) |
2771 { | 2802 { |
2772 tree old_decl = b->decl; | 2803 tree old_decl = b->decl; |
2773 bool warned = false; | |
2774 | 2804 |
2775 if (old_decl == error_mark_node) | 2805 if (old_decl == error_mark_node) |
2776 { | 2806 { |
2777 warning (OPT_Wshadow, "declaration of %q+D shadows previous " | 2807 warning (OPT_Wshadow, "declaration of %q+D shadows previous " |
2778 "non-variable", new_decl); | 2808 "non-variable", new_decl); |
2779 break; | 2809 break; |
2780 } | 2810 } |
2781 else if (TREE_CODE (old_decl) == PARM_DECL) | 2811 |
2812 bool warned = false; | |
2813 auto_diagnostic_group d; | |
2814 if (TREE_CODE (old_decl) == PARM_DECL) | |
2782 { | 2815 { |
2783 enum opt_code warning_code; | 2816 enum opt_code warning_code; |
2784 | 2817 |
2785 /* If '-Wshadow=compatible-local' is specified without other | 2818 /* If '-Wshadow=compatible-local' is specified without other |
2786 -Wshadow= flags, we will warn only when the types of the | 2819 -Wshadow= flags, we will warn only when the types of the |
2809 "declaration of %qD shadows a global " | 2842 "declaration of %qD shadows a global " |
2810 "declaration", | 2843 "declaration", |
2811 new_decl); | 2844 new_decl); |
2812 } | 2845 } |
2813 else if (TREE_CODE (old_decl) == FUNCTION_DECL | 2846 else if (TREE_CODE (old_decl) == FUNCTION_DECL |
2814 && DECL_BUILT_IN (old_decl)) | 2847 && fndecl_built_in_p (old_decl)) |
2815 { | 2848 { |
2816 warning (OPT_Wshadow, "declaration of %q+D shadows " | 2849 warning (OPT_Wshadow, "declaration of %q+D shadows " |
2817 "a built-in function", new_decl); | 2850 "a built-in function", new_decl); |
2818 break; | 2851 break; |
2819 } | 2852 } |
2922 thistype = composite_type (vistype, type); | 2955 thistype = composite_type (vistype, type); |
2923 else | 2956 else |
2924 thistype = TREE_TYPE (b_use->decl); | 2957 thistype = TREE_TYPE (b_use->decl); |
2925 b_use->u.type = TREE_TYPE (b_use->decl); | 2958 b_use->u.type = TREE_TYPE (b_use->decl); |
2926 if (TREE_CODE (b_use->decl) == FUNCTION_DECL | 2959 if (TREE_CODE (b_use->decl) == FUNCTION_DECL |
2927 && DECL_BUILT_IN (b_use->decl)) | 2960 && fndecl_built_in_p (b_use->decl)) |
2928 thistype | 2961 thistype |
2929 = build_type_attribute_variant (thistype, | 2962 = build_type_attribute_variant (thistype, |
2930 TYPE_ATTRIBUTES | 2963 TYPE_ATTRIBUTES |
2931 (b_use->u.type)); | 2964 (b_use->u.type)); |
2932 TREE_TYPE (b_use->decl) = thistype; | 2965 TREE_TYPE (b_use->decl) = thistype; |
3026 thistype = TREE_TYPE (b->decl); | 3059 thistype = TREE_TYPE (b->decl); |
3027 } | 3060 } |
3028 else | 3061 else |
3029 thistype = type; | 3062 thistype = type; |
3030 b->u.type = TREE_TYPE (b->decl); | 3063 b->u.type = TREE_TYPE (b->decl); |
3031 if (TREE_CODE (b->decl) == FUNCTION_DECL && DECL_BUILT_IN (b->decl)) | 3064 if (TREE_CODE (b->decl) == FUNCTION_DECL |
3065 && fndecl_built_in_p (b->decl)) | |
3032 thistype | 3066 thistype |
3033 = build_type_attribute_variant (thistype, | 3067 = build_type_attribute_variant (thistype, |
3034 TYPE_ATTRIBUTES (b->u.type)); | 3068 TYPE_ATTRIBUTES (b->u.type)); |
3035 TREE_TYPE (b->decl) = thistype; | 3069 TREE_TYPE (b->decl) = thistype; |
3036 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true, | 3070 bind (name, b->decl, scope, /*invisible=*/false, /*nested=*/true, |
3113 { | 3147 { |
3114 if (!warn_implicit_function_declaration) | 3148 if (!warn_implicit_function_declaration) |
3115 return; | 3149 return; |
3116 | 3150 |
3117 bool warned; | 3151 bool warned; |
3118 const char *hint = NULL; | 3152 auto_diagnostic_group d; |
3153 name_hint hint; | |
3119 if (!olddecl) | 3154 if (!olddecl) |
3120 hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME); | 3155 hint = lookup_name_fuzzy (id, FUZZY_LOOKUP_FUNCTION_NAME, loc); |
3121 | 3156 |
3122 if (flag_isoc99) | 3157 if (flag_isoc99) |
3123 { | 3158 { |
3124 if (hint) | 3159 if (hint) |
3125 { | 3160 { |
3126 gcc_rich_location richloc (loc); | 3161 gcc_rich_location richloc (loc); |
3127 richloc.add_fixit_replace (hint); | 3162 richloc.add_fixit_replace (hint.suggestion ()); |
3128 warned = pedwarn_at_rich_loc | 3163 warned = pedwarn (&richloc, OPT_Wimplicit_function_declaration, |
3129 (&richloc, OPT_Wimplicit_function_declaration, | 3164 "implicit declaration of function %qE;" |
3130 "implicit declaration of function %qE; did you mean %qs?", | 3165 " did you mean %qs?", |
3131 id, hint); | 3166 id, hint.suggestion ()); |
3132 } | 3167 } |
3133 else | 3168 else |
3134 warned = pedwarn (loc, OPT_Wimplicit_function_declaration, | 3169 warned = pedwarn (loc, OPT_Wimplicit_function_declaration, |
3135 "implicit declaration of function %qE", id); | 3170 "implicit declaration of function %qE", id); |
3136 } | 3171 } |
3137 else if (hint) | 3172 else if (hint) |
3138 { | 3173 { |
3139 gcc_rich_location richloc (loc); | 3174 gcc_rich_location richloc (loc); |
3140 richloc.add_fixit_replace (hint); | 3175 richloc.add_fixit_replace (hint.suggestion ()); |
3141 warned = warning_at_rich_loc | 3176 warned = warning_at |
3142 (&richloc, OPT_Wimplicit_function_declaration, | 3177 (&richloc, OPT_Wimplicit_function_declaration, |
3143 G_("implicit declaration of function %qE; did you mean %qs?"), | 3178 G_("implicit declaration of function %qE; did you mean %qs?"), |
3144 id, hint); | 3179 id, hint.suggestion ()); |
3145 } | 3180 } |
3146 else | 3181 else |
3147 warned = warning_at (loc, OPT_Wimplicit_function_declaration, | 3182 warned = warning_at (loc, OPT_Wimplicit_function_declaration, |
3148 G_("implicit declaration of function %qE"), id); | 3183 G_("implicit declaration of function %qE"), id); |
3149 | 3184 |
3150 if (olddecl && warned) | 3185 if (olddecl && warned) |
3151 locate_old_decl (olddecl); | 3186 locate_old_decl (olddecl); |
3187 | |
3188 if (!warned) | |
3189 hint.suppress (); | |
3152 } | 3190 } |
3153 | 3191 |
3154 /* This function represents mapping of a function code FCODE | 3192 /* This function represents mapping of a function code FCODE |
3155 to its respective header. */ | 3193 to its respective header. */ |
3156 | 3194 |
3166 CASE_FLT_FN (BUILT_IN_ATAN): | 3204 CASE_FLT_FN (BUILT_IN_ATAN): |
3167 CASE_FLT_FN (BUILT_IN_ATANH): | 3205 CASE_FLT_FN (BUILT_IN_ATANH): |
3168 CASE_FLT_FN (BUILT_IN_ATAN2): | 3206 CASE_FLT_FN (BUILT_IN_ATAN2): |
3169 CASE_FLT_FN (BUILT_IN_CBRT): | 3207 CASE_FLT_FN (BUILT_IN_CBRT): |
3170 CASE_FLT_FN (BUILT_IN_CEIL): | 3208 CASE_FLT_FN (BUILT_IN_CEIL): |
3209 CASE_FLT_FN_FLOATN_NX (BUILT_IN_CEIL): | |
3171 CASE_FLT_FN (BUILT_IN_COPYSIGN): | 3210 CASE_FLT_FN (BUILT_IN_COPYSIGN): |
3211 CASE_FLT_FN_FLOATN_NX (BUILT_IN_COPYSIGN): | |
3172 CASE_FLT_FN (BUILT_IN_COS): | 3212 CASE_FLT_FN (BUILT_IN_COS): |
3173 CASE_FLT_FN (BUILT_IN_COSH): | 3213 CASE_FLT_FN (BUILT_IN_COSH): |
3174 CASE_FLT_FN (BUILT_IN_ERF): | 3214 CASE_FLT_FN (BUILT_IN_ERF): |
3175 CASE_FLT_FN (BUILT_IN_ERFC): | 3215 CASE_FLT_FN (BUILT_IN_ERFC): |
3176 CASE_FLT_FN (BUILT_IN_EXP): | 3216 CASE_FLT_FN (BUILT_IN_EXP): |
3177 CASE_FLT_FN (BUILT_IN_EXP2): | 3217 CASE_FLT_FN (BUILT_IN_EXP2): |
3178 CASE_FLT_FN (BUILT_IN_EXPM1): | 3218 CASE_FLT_FN (BUILT_IN_EXPM1): |
3179 CASE_FLT_FN (BUILT_IN_FABS): | 3219 CASE_FLT_FN (BUILT_IN_FABS): |
3220 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FABS): | |
3180 CASE_FLT_FN (BUILT_IN_FDIM): | 3221 CASE_FLT_FN (BUILT_IN_FDIM): |
3181 CASE_FLT_FN (BUILT_IN_FLOOR): | 3222 CASE_FLT_FN (BUILT_IN_FLOOR): |
3223 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FLOOR): | |
3182 CASE_FLT_FN (BUILT_IN_FMA): | 3224 CASE_FLT_FN (BUILT_IN_FMA): |
3225 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMA): | |
3183 CASE_FLT_FN (BUILT_IN_FMAX): | 3226 CASE_FLT_FN (BUILT_IN_FMAX): |
3227 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMAX): | |
3184 CASE_FLT_FN (BUILT_IN_FMIN): | 3228 CASE_FLT_FN (BUILT_IN_FMIN): |
3229 CASE_FLT_FN_FLOATN_NX (BUILT_IN_FMIN): | |
3185 CASE_FLT_FN (BUILT_IN_FMOD): | 3230 CASE_FLT_FN (BUILT_IN_FMOD): |
3186 CASE_FLT_FN (BUILT_IN_FREXP): | 3231 CASE_FLT_FN (BUILT_IN_FREXP): |
3187 CASE_FLT_FN (BUILT_IN_HYPOT): | 3232 CASE_FLT_FN (BUILT_IN_HYPOT): |
3188 CASE_FLT_FN (BUILT_IN_ILOGB): | 3233 CASE_FLT_FN (BUILT_IN_ILOGB): |
3189 CASE_FLT_FN (BUILT_IN_LDEXP): | 3234 CASE_FLT_FN (BUILT_IN_LDEXP): |
3198 CASE_FLT_FN (BUILT_IN_LRINT): | 3243 CASE_FLT_FN (BUILT_IN_LRINT): |
3199 CASE_FLT_FN (BUILT_IN_LROUND): | 3244 CASE_FLT_FN (BUILT_IN_LROUND): |
3200 CASE_FLT_FN (BUILT_IN_MODF): | 3245 CASE_FLT_FN (BUILT_IN_MODF): |
3201 CASE_FLT_FN (BUILT_IN_NAN): | 3246 CASE_FLT_FN (BUILT_IN_NAN): |
3202 CASE_FLT_FN (BUILT_IN_NEARBYINT): | 3247 CASE_FLT_FN (BUILT_IN_NEARBYINT): |
3248 CASE_FLT_FN_FLOATN_NX (BUILT_IN_NEARBYINT): | |
3203 CASE_FLT_FN (BUILT_IN_NEXTAFTER): | 3249 CASE_FLT_FN (BUILT_IN_NEXTAFTER): |
3204 CASE_FLT_FN (BUILT_IN_NEXTTOWARD): | 3250 CASE_FLT_FN (BUILT_IN_NEXTTOWARD): |
3205 CASE_FLT_FN (BUILT_IN_POW): | 3251 CASE_FLT_FN (BUILT_IN_POW): |
3206 CASE_FLT_FN (BUILT_IN_REMAINDER): | 3252 CASE_FLT_FN (BUILT_IN_REMAINDER): |
3207 CASE_FLT_FN (BUILT_IN_REMQUO): | 3253 CASE_FLT_FN (BUILT_IN_REMQUO): |
3208 CASE_FLT_FN (BUILT_IN_RINT): | 3254 CASE_FLT_FN (BUILT_IN_RINT): |
3255 CASE_FLT_FN_FLOATN_NX (BUILT_IN_RINT): | |
3209 CASE_FLT_FN (BUILT_IN_ROUND): | 3256 CASE_FLT_FN (BUILT_IN_ROUND): |
3257 CASE_FLT_FN_FLOATN_NX (BUILT_IN_ROUND): | |
3210 CASE_FLT_FN (BUILT_IN_SCALBLN): | 3258 CASE_FLT_FN (BUILT_IN_SCALBLN): |
3211 CASE_FLT_FN (BUILT_IN_SCALBN): | 3259 CASE_FLT_FN (BUILT_IN_SCALBN): |
3212 CASE_FLT_FN (BUILT_IN_SIN): | 3260 CASE_FLT_FN (BUILT_IN_SIN): |
3213 CASE_FLT_FN (BUILT_IN_SINH): | 3261 CASE_FLT_FN (BUILT_IN_SINH): |
3214 CASE_FLT_FN (BUILT_IN_SINCOS): | 3262 CASE_FLT_FN (BUILT_IN_SINCOS): |
3215 CASE_FLT_FN (BUILT_IN_SQRT): | 3263 CASE_FLT_FN (BUILT_IN_SQRT): |
3264 CASE_FLT_FN_FLOATN_NX (BUILT_IN_SQRT): | |
3216 CASE_FLT_FN (BUILT_IN_TAN): | 3265 CASE_FLT_FN (BUILT_IN_TAN): |
3217 CASE_FLT_FN (BUILT_IN_TANH): | 3266 CASE_FLT_FN (BUILT_IN_TANH): |
3218 CASE_FLT_FN (BUILT_IN_TGAMMA): | 3267 CASE_FLT_FN (BUILT_IN_TGAMMA): |
3219 CASE_FLT_FN (BUILT_IN_TRUNC): | 3268 CASE_FLT_FN (BUILT_IN_TRUNC): |
3269 CASE_FLT_FN_FLOATN_NX (BUILT_IN_TRUNC): | |
3220 case BUILT_IN_ISINF: | 3270 case BUILT_IN_ISINF: |
3221 case BUILT_IN_ISNAN: | 3271 case BUILT_IN_ISNAN: |
3222 return "<math.h>"; | 3272 return "<math.h>"; |
3223 CASE_FLT_FN (BUILT_IN_CABS): | 3273 CASE_FLT_FN (BUILT_IN_CABS): |
3224 CASE_FLT_FN (BUILT_IN_CACOS): | 3274 CASE_FLT_FN (BUILT_IN_CACOS): |
3366 /* FIXME: Objective-C has weird not-really-builtin functions | 3416 /* FIXME: Objective-C has weird not-really-builtin functions |
3367 which are supposed to be visible automatically. They wind up | 3417 which are supposed to be visible automatically. They wind up |
3368 in the external scope because they're pushed before the file | 3418 in the external scope because they're pushed before the file |
3369 scope gets created. Catch this here and rebind them into the | 3419 scope gets created. Catch this here and rebind them into the |
3370 file scope. */ | 3420 file scope. */ |
3371 if (!DECL_BUILT_IN (decl) && DECL_IS_BUILTIN (decl)) | 3421 if (!fndecl_built_in_p (decl) && DECL_IS_BUILTIN (decl)) |
3372 { | 3422 { |
3373 bind (functionid, decl, file_scope, | 3423 bind (functionid, decl, file_scope, |
3374 /*invisible=*/false, /*nested=*/true, | 3424 /*invisible=*/false, /*nested=*/true, |
3375 DECL_SOURCE_LOCATION (decl)); | 3425 DECL_SOURCE_LOCATION (decl)); |
3376 return decl; | 3426 return decl; |
3387 if (!C_DECL_IMPLICIT (decl)) | 3437 if (!C_DECL_IMPLICIT (decl)) |
3388 { | 3438 { |
3389 implicit_decl_warning (loc, functionid, decl); | 3439 implicit_decl_warning (loc, functionid, decl); |
3390 C_DECL_IMPLICIT (decl) = 1; | 3440 C_DECL_IMPLICIT (decl) = 1; |
3391 } | 3441 } |
3392 if (DECL_BUILT_IN (decl)) | 3442 if (fndecl_built_in_p (decl)) |
3393 { | 3443 { |
3394 newtype = build_type_attribute_variant (newtype, | 3444 newtype = build_type_attribute_variant (newtype, |
3395 TYPE_ATTRIBUTES | 3445 TYPE_ATTRIBUTES |
3396 (TREE_TYPE (decl))); | 3446 (TREE_TYPE (decl))); |
3397 if (!comptypes (newtype, TREE_TYPE (decl))) | 3447 if (!comptypes (newtype, TREE_TYPE (decl))) |
3403 const char *header | 3453 const char *header |
3404 = header_for_builtin_fn (DECL_FUNCTION_CODE (decl)); | 3454 = header_for_builtin_fn (DECL_FUNCTION_CODE (decl)); |
3405 if (header != NULL && warned) | 3455 if (header != NULL && warned) |
3406 { | 3456 { |
3407 rich_location richloc (line_table, loc); | 3457 rich_location richloc (line_table, loc); |
3408 maybe_add_include_fixit (&richloc, header); | 3458 maybe_add_include_fixit (&richloc, header, true); |
3409 inform_at_rich_loc | 3459 inform (&richloc, |
3410 (&richloc, | 3460 "include %qs or provide a declaration of %qD", |
3411 "include %qs or provide a declaration of %qD", | 3461 header, decl); |
3412 header, decl); | |
3413 } | 3462 } |
3414 newtype = TREE_TYPE (decl); | 3463 newtype = TREE_TYPE (decl); |
3415 } | 3464 } |
3416 } | 3465 } |
3417 else | 3466 else |
3418 { | 3467 { |
3419 if (!comptypes (newtype, TREE_TYPE (decl))) | 3468 if (!comptypes (newtype, TREE_TYPE (decl))) |
3420 { | 3469 { |
3470 auto_diagnostic_group d; | |
3421 error_at (loc, "incompatible implicit declaration of " | 3471 error_at (loc, "incompatible implicit declaration of " |
3422 "function %qD", decl); | 3472 "function %qD", decl); |
3423 locate_old_decl (decl); | 3473 locate_old_decl (decl); |
3424 } | 3474 } |
3425 } | 3475 } |
3473 undeclared_variable (location_t loc, tree id) | 3523 undeclared_variable (location_t loc, tree id) |
3474 { | 3524 { |
3475 static bool already = false; | 3525 static bool already = false; |
3476 struct c_scope *scope; | 3526 struct c_scope *scope; |
3477 | 3527 |
3528 auto_diagnostic_group d; | |
3478 if (current_function_decl == NULL_TREE) | 3529 if (current_function_decl == NULL_TREE) |
3479 { | 3530 { |
3480 const char *guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); | 3531 name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc); |
3481 if (guessed_id) | 3532 if (guessed_id) |
3482 { | 3533 { |
3483 gcc_rich_location richloc (loc); | 3534 gcc_rich_location richloc (loc); |
3484 richloc.add_fixit_replace (guessed_id); | 3535 richloc.add_fixit_replace (guessed_id.suggestion ()); |
3485 error_at_rich_loc (&richloc, | 3536 error_at (&richloc, |
3486 "%qE undeclared here (not in a function);" | 3537 "%qE undeclared here (not in a function);" |
3487 " did you mean %qs?", | 3538 " did you mean %qs?", |
3488 id, guessed_id); | 3539 id, guessed_id.suggestion ()); |
3489 } | 3540 } |
3490 else | 3541 else |
3491 error_at (loc, "%qE undeclared here (not in a function)", id); | 3542 error_at (loc, "%qE undeclared here (not in a function)", id); |
3492 scope = current_scope; | 3543 scope = current_scope; |
3493 } | 3544 } |
3494 else | 3545 else |
3495 { | 3546 { |
3496 if (!objc_diagnose_private_ivar (id)) | 3547 if (!objc_diagnose_private_ivar (id)) |
3497 { | 3548 { |
3498 const char *guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME); | 3549 name_hint guessed_id = lookup_name_fuzzy (id, FUZZY_LOOKUP_NAME, loc); |
3499 if (guessed_id) | 3550 if (guessed_id) |
3500 { | 3551 { |
3501 gcc_rich_location richloc (loc); | 3552 gcc_rich_location richloc (loc); |
3502 richloc.add_fixit_replace (guessed_id); | 3553 richloc.add_fixit_replace (guessed_id.suggestion ()); |
3503 error_at_rich_loc | 3554 error_at (&richloc, |
3504 (&richloc, | 3555 "%qE undeclared (first use in this function);" |
3505 "%qE undeclared (first use in this function);" | 3556 " did you mean %qs?", |
3506 " did you mean %qs?", | 3557 id, guessed_id.suggestion ()); |
3507 id, guessed_id); | |
3508 } | 3558 } |
3509 else | 3559 else |
3510 error_at (loc, "%qE undeclared (first use in this function)", id); | 3560 error_at (loc, "%qE undeclared (first use in this function)", id); |
3511 } | 3561 } |
3512 if (!already) | 3562 if (!already) |
3673 | 3723 |
3674 /* Check to make sure that the label hasn't already been declared | 3724 /* Check to make sure that the label hasn't already been declared |
3675 at this scope */ | 3725 at this scope */ |
3676 if (b && B_IN_CURRENT_SCOPE (b)) | 3726 if (b && B_IN_CURRENT_SCOPE (b)) |
3677 { | 3727 { |
3728 auto_diagnostic_group d; | |
3678 error ("duplicate label declaration %qE", name); | 3729 error ("duplicate label declaration %qE", name); |
3679 locate_old_decl (b->decl); | 3730 locate_old_decl (b->decl); |
3680 | 3731 |
3681 /* Just use the previous declaration. */ | 3732 /* Just use the previous declaration. */ |
3682 return b->decl; | 3733 return b->decl; |
3771 && ((DECL_CONTEXT (label) == current_function_decl | 3822 && ((DECL_CONTEXT (label) == current_function_decl |
3772 && DECL_INITIAL (label) != NULL_TREE) | 3823 && DECL_INITIAL (label) != NULL_TREE) |
3773 || (DECL_CONTEXT (label) != current_function_decl | 3824 || (DECL_CONTEXT (label) != current_function_decl |
3774 && C_DECLARED_LABEL_FLAG (label)))) | 3825 && C_DECLARED_LABEL_FLAG (label)))) |
3775 { | 3826 { |
3827 auto_diagnostic_group d; | |
3776 error_at (location, "duplicate label %qD", label); | 3828 error_at (location, "duplicate label %qD", label); |
3777 locate_old_decl (label); | 3829 locate_old_decl (label); |
3778 return NULL_TREE; | 3830 return NULL_TREE; |
3779 } | 3831 } |
3780 else if (label && DECL_CONTEXT (label) == current_function_decl) | 3832 else if (label && DECL_CONTEXT (label) == current_function_decl) |
4011 The function also looks for similar macro names to NAME, since a | 4063 The function also looks for similar macro names to NAME, since a |
4012 misspelled macro name will not be expanded, and hence looks like an | 4064 misspelled macro name will not be expanded, and hence looks like an |
4013 identifier to the C frontend. | 4065 identifier to the C frontend. |
4014 | 4066 |
4015 It also looks for start_typename keywords, to detect "singed" vs "signed" | 4067 It also looks for start_typename keywords, to detect "singed" vs "signed" |
4016 typos. */ | 4068 typos. |
4017 | 4069 |
4018 const char * | 4070 Use LOC for any deferred diagnostics. */ |
4019 lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind) | 4071 |
4072 name_hint | |
4073 lookup_name_fuzzy (tree name, enum lookup_name_fuzzy_kind kind, location_t loc) | |
4020 { | 4074 { |
4021 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE); | 4075 gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE); |
4076 | |
4077 /* First, try some well-known names in the C standard library, in case | |
4078 the user forgot a #include. */ | |
4079 const char *header_hint | |
4080 = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name)); | |
4081 | |
4082 if (header_hint) | |
4083 return name_hint (NULL, | |
4084 new suggest_missing_header (loc, | |
4085 IDENTIFIER_POINTER (name), | |
4086 header_hint)); | |
4087 | |
4088 /* Only suggest names reserved for the implementation if NAME begins | |
4089 with an underscore. */ | |
4090 bool consider_implementation_names = (IDENTIFIER_POINTER (name)[0] == '_'); | |
4022 | 4091 |
4023 best_match<tree, tree> bm (name); | 4092 best_match<tree, tree> bm (name); |
4024 | 4093 |
4025 /* Look within currently valid scopes. */ | 4094 /* Look within currently valid scopes. */ |
4026 for (c_scope *scope = current_scope; scope; scope = scope->outer) | 4095 for (c_scope *scope = current_scope; scope; scope = scope->outer) |
4027 for (c_binding *binding = scope->bindings; binding; binding = binding->prev) | 4096 for (c_binding *binding = scope->bindings; binding; binding = binding->prev) |
4028 { | 4097 { |
4029 if (!binding->id || binding->invisible) | 4098 if (!binding->id || binding->invisible) |
4030 continue; | 4099 continue; |
4100 if (binding->decl == error_mark_node) | |
4101 continue; | |
4031 /* Don't use bindings from implicitly declared functions, | 4102 /* Don't use bindings from implicitly declared functions, |
4032 as they were likely misspellings themselves. */ | 4103 as they were likely misspellings themselves. */ |
4033 if (TREE_CODE (binding->decl) == FUNCTION_DECL) | 4104 if (TREE_CODE (binding->decl) == FUNCTION_DECL) |
4034 if (C_DECL_IMPLICIT (binding->decl)) | 4105 if (C_DECL_IMPLICIT (binding->decl)) |
4035 continue; | 4106 continue; |
4107 /* Don't suggest names that are reserved for use by the | |
4108 implementation, unless NAME began with an underscore. */ | |
4109 if (!consider_implementation_names) | |
4110 { | |
4111 const char *suggestion_str = IDENTIFIER_POINTER (binding->id); | |
4112 if (name_reserved_for_implementation_p (suggestion_str)) | |
4113 continue; | |
4114 } | |
4036 switch (kind) | 4115 switch (kind) |
4037 { | 4116 { |
4038 case FUZZY_LOOKUP_TYPENAME: | 4117 case FUZZY_LOOKUP_TYPENAME: |
4039 if (TREE_CODE (binding->decl) != TYPE_DECL) | 4118 if (TREE_CODE (binding->decl) != TYPE_DECL) |
4040 continue; | 4119 continue; |
4104 } | 4183 } |
4105 } | 4184 } |
4106 | 4185 |
4107 tree best = bm.get_best_meaningful_candidate (); | 4186 tree best = bm.get_best_meaningful_candidate (); |
4108 if (best) | 4187 if (best) |
4109 return IDENTIFIER_POINTER (best); | 4188 return name_hint (IDENTIFIER_POINTER (best), NULL); |
4110 else | 4189 else |
4111 return NULL; | 4190 return name_hint (NULL, NULL); |
4112 } | 4191 } |
4113 | 4192 |
4114 | 4193 |
4115 /* Create the predefined scalar types of C, | 4194 /* Create the predefined scalar types of C, |
4116 and some nodes representing standard constants (0, 1, (void *) 0). | 4195 and some nodes representing standard constants (0, 1, (void *) 0). |
4603 && ((VAR_P (*node) && is_global_var (*node)) | 4682 && ((VAR_P (*node) && is_global_var (*node)) |
4604 || TREE_CODE (*node) == FUNCTION_DECL)) | 4683 || TREE_CODE (*node) == FUNCTION_DECL)) |
4605 { | 4684 { |
4606 if (VAR_P (*node) | 4685 if (VAR_P (*node) |
4607 && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node))) | 4686 && !lang_hooks.types.omp_mappable_type (TREE_TYPE (*node))) |
4608 error ("%q+D in declare target directive does not have mappable type", | 4687 attributes = tree_cons (get_identifier ("omp declare target implicit"), |
4609 *node); | 4688 NULL_TREE, attributes); |
4610 else | 4689 else |
4611 attributes = tree_cons (get_identifier ("omp declare target"), | 4690 attributes = tree_cons (get_identifier ("omp declare target"), |
4612 NULL_TREE, attributes); | 4691 NULL_TREE, attributes); |
4613 } | 4692 } |
4614 return decl_attributes (node, attributes, flags); | 4693 |
4694 /* Look up the current declaration with all the attributes merged | |
4695 so far so that attributes on the current declaration that's | |
4696 about to be pushed that conflict with the former can be detected, | |
4697 diagnosed, and rejected as appropriate. */ | |
4698 tree last_decl = lookup_name (DECL_NAME (*node)); | |
4699 if (!last_decl) | |
4700 last_decl = lookup_name_in_scope (DECL_NAME (*node), external_scope); | |
4701 | |
4702 return decl_attributes (node, attributes, flags, last_decl); | |
4615 } | 4703 } |
4616 | 4704 |
4617 | 4705 |
4618 /* Decode a declarator in an ordinary declaration or data definition. | 4706 /* Decode a declarator in an ordinary declaration or data definition. |
4619 This is called as soon as the type information and variable name | 4707 This is called as soon as the type information and variable name |
4651 return NULL_TREE; | 4739 return NULL_TREE; |
4652 | 4740 |
4653 if (expr) | 4741 if (expr) |
4654 add_stmt (fold_convert (void_type_node, expr)); | 4742 add_stmt (fold_convert (void_type_node, expr)); |
4655 | 4743 |
4656 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl))) | 4744 if (TREE_CODE (decl) != FUNCTION_DECL && MAIN_NAME_P (DECL_NAME (decl)) |
4745 && TREE_PUBLIC (decl)) | |
4657 warning (OPT_Wmain, "%q+D is usually a function", decl); | 4746 warning (OPT_Wmain, "%q+D is usually a function", decl); |
4658 | 4747 |
4659 if (initialized) | 4748 if (initialized) |
4660 /* Is it valid for this decl to have an initializer at all? | 4749 /* Is it valid for this decl to have an initializer at all? |
4661 If not, set INITIALIZED to zero, which will indirectly | 4750 If not, set INITIALIZED to zero, which will indirectly |
4920 break; | 5009 break; |
4921 | 5010 |
4922 case 2: | 5011 case 2: |
4923 if (do_default) | 5012 if (do_default) |
4924 error ("array size missing in %q+D", decl); | 5013 error ("array size missing in %q+D", decl); |
4925 /* If a `static' var's size isn't known, | |
4926 make it extern as well as static, so it does not get | |
4927 allocated. | |
4928 If it is not `static', then do not mark extern; | |
4929 finish_incomplete_decl will give it a default size | |
4930 and it will get allocated. */ | |
4931 else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) | |
4932 DECL_EXTERNAL (decl) = 1; | |
4933 break; | 5014 break; |
4934 | 5015 |
4935 case 3: | 5016 case 3: |
4936 error ("zero or negative size array %q+D", decl); | 5017 error ("zero or negative size array %q+D", decl); |
4937 break; | 5018 break; |
4962 TREE_TYPE (DECL_INITIAL (decl)) = type; | 5043 TREE_TYPE (DECL_INITIAL (decl)) = type; |
4963 | 5044 |
4964 relayout_decl (decl); | 5045 relayout_decl (decl); |
4965 } | 5046 } |
4966 | 5047 |
5048 if (TREE_CODE (type) == ARRAY_TYPE | |
5049 && TYPE_STRING_FLAG (TREE_TYPE (type)) | |
5050 && DECL_INITIAL (decl) | |
5051 && TREE_CODE (DECL_INITIAL (decl)) == CONSTRUCTOR) | |
5052 DECL_INITIAL (decl) = braced_list_to_string (type, DECL_INITIAL (decl)); | |
5053 | |
4967 if (VAR_P (decl)) | 5054 if (VAR_P (decl)) |
4968 { | 5055 { |
4969 if (init && TREE_CODE (init) == CONSTRUCTOR) | 5056 if (init && TREE_CODE (init) == CONSTRUCTOR) |
4970 add_flexible_array_elts_to_size (decl, init); | 5057 add_flexible_array_elts_to_size (decl, init); |
5058 | |
5059 complete_flexible_array_elts (DECL_INITIAL (decl)); | |
4971 | 5060 |
4972 if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node | 5061 if (DECL_SIZE (decl) == NULL_TREE && TREE_TYPE (decl) != error_mark_node |
4973 && COMPLETE_TYPE_P (TREE_TYPE (decl))) | 5062 && COMPLETE_TYPE_P (TREE_TYPE (decl))) |
4974 layout_decl (decl, 0); | 5063 layout_decl (decl, 0); |
4975 | 5064 |
5174 else if (RECORD_OR_UNION_TYPE_P (type) | 5263 else if (RECORD_OR_UNION_TYPE_P (type) |
5175 && C_TYPE_FIELDS_READONLY (type)) | 5264 && C_TYPE_FIELDS_READONLY (type)) |
5176 diagnose_uninitialized_cst_member (decl, type); | 5265 diagnose_uninitialized_cst_member (decl, type); |
5177 } | 5266 } |
5178 | 5267 |
5179 invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl); | 5268 if (flag_openmp |
5269 && VAR_P (decl) | |
5270 && lookup_attribute ("omp declare target implicit", | |
5271 DECL_ATTRIBUTES (decl))) | |
5272 { | |
5273 DECL_ATTRIBUTES (decl) | |
5274 = remove_attribute ("omp declare target implicit", | |
5275 DECL_ATTRIBUTES (decl)); | |
5276 if (!lang_hooks.types.omp_mappable_type (TREE_TYPE (decl))) | |
5277 error ("%q+D in declare target directive does not have mappable type", | |
5278 decl); | |
5279 else if (!lookup_attribute ("omp declare target", | |
5280 DECL_ATTRIBUTES (decl)) | |
5281 && !lookup_attribute ("omp declare target link", | |
5282 DECL_ATTRIBUTES (decl))) | |
5283 DECL_ATTRIBUTES (decl) | |
5284 = tree_cons (get_identifier ("omp declare target"), | |
5285 NULL_TREE, DECL_ATTRIBUTES (decl)); | |
5286 } | |
5287 | |
5288 invoke_plugin_callbacks (PLUGIN_FINISH_DECL, decl); | |
5180 } | 5289 } |
5181 | 5290 |
5182 /* Given a parsed parameter declaration, decode it into a PARM_DECL. | 5291 /* Given a parsed parameter declaration, decode it into a PARM_DECL. |
5183 EXPR is NULL or a pointer to an expression that needs to be | 5292 EXPR is NULL or a pointer to an expression that needs to be |
5184 evaluated for the side effects of array size expressions in the | 5293 evaluated for the side effects of array size expressions in the |
5240 | 5349 |
5241 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound | 5350 /* Build a COMPOUND_LITERAL_EXPR. TYPE is the type given in the compound |
5242 literal, which may be an incomplete array type completed by the | 5351 literal, which may be an incomplete array type completed by the |
5243 initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound | 5352 initializer; INIT is a CONSTRUCTOR at LOC that initializes the compound |
5244 literal. NON_CONST is true if the initializers contain something | 5353 literal. NON_CONST is true if the initializers contain something |
5245 that cannot occur in a constant expression. */ | 5354 that cannot occur in a constant expression. If ALIGNAS_ALIGN is nonzero, |
5355 it is the (valid) alignment for this compound literal, as specified | |
5356 with _Alignas. */ | |
5246 | 5357 |
5247 tree | 5358 tree |
5248 build_compound_literal (location_t loc, tree type, tree init, bool non_const) | 5359 build_compound_literal (location_t loc, tree type, tree init, bool non_const, |
5360 unsigned int alignas_align) | |
5249 { | 5361 { |
5250 /* We do not use start_decl here because we have a type, not a declarator; | 5362 /* We do not use start_decl here because we have a type, not a declarator; |
5251 and do not use finish_decl because the decl should be stored inside | 5363 and do not use finish_decl because the decl should be stored inside |
5252 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */ | 5364 the COMPOUND_LITERAL_EXPR rather than added elsewhere as a DECL_EXPR. */ |
5253 tree decl; | 5365 tree decl; |
5267 DECL_READ_P (decl) = 1; | 5379 DECL_READ_P (decl) = 1; |
5268 DECL_ARTIFICIAL (decl) = 1; | 5380 DECL_ARTIFICIAL (decl) = 1; |
5269 DECL_IGNORED_P (decl) = 1; | 5381 DECL_IGNORED_P (decl) = 1; |
5270 TREE_TYPE (decl) = type; | 5382 TREE_TYPE (decl) = type; |
5271 c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl); | 5383 c_apply_type_quals_to_decl (TYPE_QUALS (strip_array_types (type)), decl); |
5384 if (alignas_align) | |
5385 { | |
5386 SET_DECL_ALIGN (decl, alignas_align * BITS_PER_UNIT); | |
5387 DECL_USER_ALIGN (decl) = 1; | |
5388 } | |
5272 store_init_value (loc, decl, init, NULL_TREE); | 5389 store_init_value (loc, decl, init, NULL_TREE); |
5273 | 5390 |
5274 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) | 5391 if (TREE_CODE (type) == ARRAY_TYPE && !COMPLETE_TYPE_P (type)) |
5275 { | 5392 { |
5276 int failure = complete_array_type (&TREE_TYPE (decl), | 5393 int failure = complete_array_type (&TREE_TYPE (decl), |
5302 DECL_DEFER_OUTPUT (decl) = 1; | 5419 DECL_DEFER_OUTPUT (decl) = 1; |
5303 DECL_COMDAT (decl) = 1; | 5420 DECL_COMDAT (decl) = 1; |
5304 pushdecl (decl); | 5421 pushdecl (decl); |
5305 rest_of_decl_compilation (decl, 1, 0); | 5422 rest_of_decl_compilation (decl, 1, 0); |
5306 } | 5423 } |
5424 else | |
5425 pushdecl (decl); | |
5307 | 5426 |
5308 if (non_const) | 5427 if (non_const) |
5309 { | 5428 { |
5310 complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit); | 5429 complit = build2 (C_MAYBE_CONST_EXPR, type, NULL, complit); |
5311 C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1; | 5430 C_MAYBE_CONST_EXPR_NON_CONST (complit) = 1; |
5433 pedwarn_c90 (loc, OPT_Wpedantic, | 5552 pedwarn_c90 (loc, OPT_Wpedantic, |
5434 "type of bit-field %qs is a GCC extension", name); | 5553 "type of bit-field %qs is a GCC extension", name); |
5435 | 5554 |
5436 max_width = TYPE_PRECISION (*type); | 5555 max_width = TYPE_PRECISION (*type); |
5437 | 5556 |
5438 if (0 < compare_tree_int (*width, max_width)) | 5557 if (compare_tree_int (*width, max_width) > 0) |
5439 { | 5558 { |
5440 error_at (loc, "width of %qs exceeds its type", name); | 5559 error_at (loc, "width of %qs exceeds its type", name); |
5441 w = max_width; | 5560 w = max_width; |
5442 *width = build_int_cst (integer_type_node, w); | 5561 *width = build_int_cst (integer_type_node, w); |
5443 } | 5562 } |
5699 if (declspecs->default_int_p && !in_system_header_at (input_location)) | 5818 if (declspecs->default_int_p && !in_system_header_at (input_location)) |
5700 { | 5819 { |
5701 /* Issue a warning if this is an ISO C 99 program or if | 5820 /* Issue a warning if this is an ISO C 99 program or if |
5702 -Wreturn-type and this is a function, or if -Wimplicit; | 5821 -Wreturn-type and this is a function, or if -Wimplicit; |
5703 prefer the former warning since it is more explicit. */ | 5822 prefer the former warning since it is more explicit. */ |
5704 if ((warn_implicit_int || warn_return_type || flag_isoc99) | 5823 if ((warn_implicit_int || warn_return_type > 0 || flag_isoc99) |
5705 && funcdef_flag) | 5824 && funcdef_flag) |
5706 warn_about_return_type = 1; | 5825 warn_about_return_type = 1; |
5707 else | 5826 else |
5708 { | 5827 { |
5709 if (name) | 5828 if (name) |
5773 | 5892 |
5774 /* Applying the _Atomic qualifier to an array type (through the use | 5893 /* Applying the _Atomic qualifier to an array type (through the use |
5775 of typedefs or typeof) must be detected here. If the qualifier | 5894 of typedefs or typeof) must be detected here. If the qualifier |
5776 is introduced later, any appearance of applying it to an array is | 5895 is introduced later, any appearance of applying it to an array is |
5777 actually applying it to an element of that array. */ | 5896 actually applying it to an element of that array. */ |
5778 if (atomicp && TREE_CODE (type) == ARRAY_TYPE) | 5897 if (declspecs->atomic_p && TREE_CODE (type) == ARRAY_TYPE) |
5779 error_at (loc, "%<_Atomic%>-qualified array type"); | 5898 error_at (loc, "%<_Atomic%>-qualified array type"); |
5780 | 5899 |
5781 /* Warn about storage classes that are invalid for certain | 5900 /* Warn about storage classes that are invalid for certain |
5782 kinds of declarations (parameters, typenames, etc.). */ | 5901 kinds of declarations (parameters, typenames, etc.). */ |
5783 | 5902 |
6441 | 6560 |
6442 This is expected to happen automatically when the pointed-to | 6561 This is expected to happen automatically when the pointed-to |
6443 type has a name/declaration of it's own, but special attention | 6562 type has a name/declaration of it's own, but special attention |
6444 is required if the type is anonymous. | 6563 is required if the type is anonymous. |
6445 | 6564 |
6446 We handle the NORMAL and FIELD contexts here by attaching an | 6565 We attach an artificial TYPE_DECL to such pointed-to type |
6447 artificial TYPE_DECL to such pointed-to type. This forces the | 6566 and arrange for it to be included in a DECL_EXPR. This |
6448 sizes evaluation at a safe point and ensures it is not deferred | 6567 forces the sizes evaluation at a safe point and ensures it |
6449 until e.g. within a deeper conditional context. | 6568 is not deferred until e.g. within a deeper conditional context. |
6450 | 6569 |
6451 We expect nothing to be needed here for PARM or TYPENAME. | 6570 PARM contexts have no enclosing statement list that |
6452 Pushing a TYPE_DECL at this point for TYPENAME would actually | 6571 can hold the DECL_EXPR, so we need to use a BIND_EXPR |
6453 be incorrect, as we might be in the middle of an expression | 6572 instead, and add it to the list of expressions that |
6454 with side effects on the pointed-to type size "arguments" prior | 6573 need to be evaluated. |
6455 to the pointer declaration point and the fake TYPE_DECL in the | 6574 |
6456 enclosing context would force the size evaluation prior to the | 6575 TYPENAME contexts do have an enclosing statement list, |
6457 side effects. */ | 6576 but it would be incorrect to use it, as the size should |
6458 | 6577 only be evaluated if the containing expression is |
6578 evaluated. We might also be in the middle of an | |
6579 expression with side effects on the pointed-to type size | |
6580 "arguments" prior to the pointer declaration point and | |
6581 the fake TYPE_DECL in the enclosing context would force | |
6582 the size evaluation prior to the side effects. We therefore | |
6583 use BIND_EXPRs in TYPENAME contexts too. */ | |
6459 if (!TYPE_NAME (type) | 6584 if (!TYPE_NAME (type) |
6460 && (decl_context == NORMAL || decl_context == FIELD) | |
6461 && variably_modified_type_p (type, NULL_TREE)) | 6585 && variably_modified_type_p (type, NULL_TREE)) |
6462 { | 6586 { |
6587 tree bind = NULL_TREE; | |
6588 if (decl_context == TYPENAME || decl_context == PARM) | |
6589 { | |
6590 bind = build3 (BIND_EXPR, void_type_node, NULL_TREE, | |
6591 NULL_TREE, NULL_TREE); | |
6592 TREE_SIDE_EFFECTS (bind) = 1; | |
6593 BIND_EXPR_BODY (bind) = push_stmt_list (); | |
6594 push_scope (); | |
6595 } | |
6463 tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type); | 6596 tree decl = build_decl (loc, TYPE_DECL, NULL_TREE, type); |
6464 DECL_ARTIFICIAL (decl) = 1; | 6597 DECL_ARTIFICIAL (decl) = 1; |
6465 pushdecl (decl); | 6598 pushdecl (decl); |
6466 finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); | 6599 finish_decl (decl, loc, NULL_TREE, NULL_TREE, NULL_TREE); |
6467 TYPE_NAME (type) = decl; | 6600 TYPE_NAME (type) = decl; |
6601 if (bind) | |
6602 { | |
6603 pop_scope (); | |
6604 BIND_EXPR_BODY (bind) | |
6605 = pop_stmt_list (BIND_EXPR_BODY (bind)); | |
6606 if (*expr) | |
6607 *expr = build2 (COMPOUND_EXPR, void_type_node, *expr, | |
6608 bind); | |
6609 else | |
6610 *expr = bind; | |
6611 } | |
6468 } | 6612 } |
6469 | 6613 |
6470 type = c_build_pointer_type (type); | 6614 type = c_build_pointer_type (type); |
6471 | 6615 |
6472 /* Process type qualifiers (such as const or volatile) | 6616 /* Process type qualifiers (such as const or volatile) |
6631 && b->decl != NULL_TREE | 6775 && b->decl != NULL_TREE |
6632 && (B_IN_CURRENT_SCOPE (b) | 6776 && (B_IN_CURRENT_SCOPE (b) |
6633 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) | 6777 || (current_scope == file_scope && B_IN_EXTERNAL_SCOPE (b))) |
6634 && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type)) | 6778 && TYPE_MAIN_VARIANT (b->decl) != TYPE_MAIN_VARIANT (type)) |
6635 { | 6779 { |
6780 auto_diagnostic_group d; | |
6636 if (warning_at (declarator->id_loc, OPT_Wc___compat, | 6781 if (warning_at (declarator->id_loc, OPT_Wc___compat, |
6637 ("using %qD as both a typedef and a tag is " | 6782 ("using %qD as both a typedef and a tag is " |
6638 "invalid in C++"), decl) | 6783 "invalid in C++"), decl) |
6639 && b->locus != UNKNOWN_LOCATION) | 6784 && b->locus != UNKNOWN_LOCATION) |
6640 inform (b->locus, "originally defined here"); | 6785 inform (b->locus, "originally defined here"); |
6819 orig_qual_indirect); | 6964 orig_qual_indirect); |
6820 decl = build_decl (declarator->id_loc, | 6965 decl = build_decl (declarator->id_loc, |
6821 FIELD_DECL, declarator->u.id, type); | 6966 FIELD_DECL, declarator->u.id, type); |
6822 DECL_NONADDRESSABLE_P (decl) = bitfield; | 6967 DECL_NONADDRESSABLE_P (decl) = bitfield; |
6823 if (bitfield && !declarator->u.id) | 6968 if (bitfield && !declarator->u.id) |
6824 TREE_NO_WARNING (decl) = 1; | 6969 { |
6970 TREE_NO_WARNING (decl) = 1; | |
6971 DECL_PADDING_P (decl) = 1; | |
6972 } | |
6825 | 6973 |
6826 if (size_varies) | 6974 if (size_varies) |
6827 C_DECL_VARIABLE_SIZE (decl) = 1; | 6975 C_DECL_VARIABLE_SIZE (decl) = 1; |
6828 } | 6976 } |
6829 else if (TREE_CODE (type) == FUNCTION_TYPE) | 6977 else if (TREE_CODE (type) == FUNCTION_TYPE) |
8164 { | 8312 { |
8165 TYPE_TRANSPARENT_AGGR (t) = 0; | 8313 TYPE_TRANSPARENT_AGGR (t) = 0; |
8166 warning_at (loc, 0, "union cannot be made transparent"); | 8314 warning_at (loc, 0, "union cannot be made transparent"); |
8167 } | 8315 } |
8168 | 8316 |
8317 /* Update type location to the one of the definition, instead of e.g. | |
8318 a forward declaration. */ | |
8319 if (TYPE_STUB_DECL (t)) | |
8320 DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc; | |
8321 | |
8322 /* Finish debugging output for this type. */ | |
8323 rest_of_type_compilation (t, toplevel); | |
8324 | |
8169 /* If this structure or union completes the type of any previous | 8325 /* If this structure or union completes the type of any previous |
8170 variable declaration, lay it out and output its rtl. */ | 8326 variable declaration, lay it out and output its rtl. */ |
8171 for (x = incomplete_vars; x; x = TREE_CHAIN (x)) | 8327 for (x = incomplete_vars; x; x = TREE_CHAIN (x)) |
8172 { | 8328 { |
8173 tree decl = TREE_VALUE (x); | 8329 tree decl = TREE_VALUE (x); |
8179 if (c_dialect_objc ()) | 8335 if (c_dialect_objc ()) |
8180 objc_check_decl (decl); | 8336 objc_check_decl (decl); |
8181 rest_of_decl_compilation (decl, toplevel, 0); | 8337 rest_of_decl_compilation (decl, toplevel, 0); |
8182 } | 8338 } |
8183 } | 8339 } |
8184 | |
8185 /* Update type location to the one of the definition, instead of e.g. | |
8186 a forward declaration. */ | |
8187 if (TYPE_STUB_DECL (t)) | |
8188 DECL_SOURCE_LOCATION (TYPE_STUB_DECL (t)) = loc; | |
8189 | |
8190 /* Finish debugging output for this type. */ | |
8191 rest_of_type_compilation (t, toplevel); | |
8192 | 8340 |
8193 /* If we're inside a function proper, i.e. not file-scope and not still | 8341 /* If we're inside a function proper, i.e. not file-scope and not still |
8194 parsing parameters, then arrange for the size of a variable sized type | 8342 parsing parameters, then arrange for the size of a variable sized type |
8195 to be bound now. */ | 8343 to be bound now. */ |
8196 if (building_stmt_list_p () && variably_modified_type_p (t, NULL_TREE)) | 8344 if (building_stmt_list_p () && variably_modified_type_p (t, NULL_TREE)) |
8738 TYPE_ARG_TYPES (TREE_TYPE (decl1))); | 8886 TYPE_ARG_TYPES (TREE_TYPE (decl1))); |
8739 } | 8887 } |
8740 | 8888 |
8741 if (warn_about_return_type) | 8889 if (warn_about_return_type) |
8742 warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int | 8890 warn_defaults_to (loc, flag_isoc99 ? OPT_Wimplicit_int |
8743 : (warn_return_type ? OPT_Wreturn_type | 8891 : (warn_return_type > 0 ? OPT_Wreturn_type |
8744 : OPT_Wimplicit_int), | 8892 : OPT_Wimplicit_int), |
8745 "return type defaults to %<int%>"); | 8893 "return type defaults to %<int%>"); |
8746 | 8894 |
8747 /* Make the init_value nonzero so pushdecl knows this is not tentative. | 8895 /* Make the init_value nonzero so pushdecl knows this is not tentative. |
8748 error_mark_node is replaced below (in pop_scope) with the BLOCK. */ | 8896 error_mark_node is replaced below (in pop_scope) with the BLOCK. */ |
8767 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), | 8915 && comptypes (TREE_TYPE (TREE_TYPE (decl1)), |
8768 TREE_TYPE (TREE_TYPE (old_decl)))) | 8916 TREE_TYPE (TREE_TYPE (old_decl)))) |
8769 { | 8917 { |
8770 if (stdarg_p (TREE_TYPE (old_decl))) | 8918 if (stdarg_p (TREE_TYPE (old_decl))) |
8771 { | 8919 { |
8920 auto_diagnostic_group d; | |
8772 warning_at (loc, 0, "%q+D defined as variadic function " | 8921 warning_at (loc, 0, "%q+D defined as variadic function " |
8773 "without prototype", decl1); | 8922 "without prototype", decl1); |
8774 locate_old_decl (old_decl); | 8923 locate_old_decl (old_decl); |
8775 } | 8924 } |
8776 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl), | 8925 TREE_TYPE (decl1) = composite_type (TREE_TYPE (old_decl), |
9447 } | 9596 } |
9448 | 9597 |
9449 /* Tie off the statement tree for this function. */ | 9598 /* Tie off the statement tree for this function. */ |
9450 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl)); | 9599 DECL_SAVED_TREE (fndecl) = pop_stmt_list (DECL_SAVED_TREE (fndecl)); |
9451 | 9600 |
9452 /* If the function has _Cilk_spawn in front of a function call inside it | |
9453 i.e. it is a spawning function, then add the appropriate Cilk plus | |
9454 functions inside. */ | |
9455 if (fn_contains_cilk_spawn_p (cfun)) | |
9456 cfun->cilk_frame_decl = insert_cilk_frame (fndecl); | |
9457 | |
9458 finish_fname_decls (); | 9601 finish_fname_decls (); |
9459 | 9602 |
9460 /* Complain if there's just no return statement. */ | 9603 /* Complain if there's no return statement only if option specified on |
9461 if (warn_return_type | 9604 command line. */ |
9605 if (warn_return_type > 0 | |
9462 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE | 9606 && TREE_CODE (TREE_TYPE (TREE_TYPE (fndecl))) != VOID_TYPE |
9463 && !current_function_returns_value && !current_function_returns_null | 9607 && !current_function_returns_value && !current_function_returns_null |
9464 /* Don't complain if we are no-return. */ | 9608 /* Don't complain if we are no-return. */ |
9465 && !current_function_returns_abnormally | 9609 && !current_function_returns_abnormally |
9466 /* Don't complain if we are declared noreturn. */ | 9610 /* Don't complain if we are declared noreturn. */ |
9599 "to compile your code"); | 9743 "to compile your code"); |
9600 hint = false; | 9744 hint = false; |
9601 } | 9745 } |
9602 return NULL_TREE; | 9746 return NULL_TREE; |
9603 } | 9747 } |
9748 else | |
9749 pedwarn_c90 (loc, OPT_Wpedantic, "ISO C90 does not support %<for%> loop " | |
9750 "initial declarations"); | |
9751 | |
9604 /* C99 subclause 6.8.5 paragraph 3: | 9752 /* C99 subclause 6.8.5 paragraph 3: |
9605 | 9753 |
9606 [#3] The declaration part of a for statement shall only | 9754 [#3] The declaration part of a for statement shall only |
9607 declare identifiers for objects having storage class auto or | 9755 declare identifiers for objects having storage class auto or |
9608 register. | 9756 register. |