mirror of
https://gcc.gnu.org/git/gcc.git
synced 2025-01-18 02:14:31 +08:00
134442b217
If the tinfo vars are emitted in the current TU, they are emitted at the end of the compilation, and for some types they are exported from libstdc++/libsupc++ and not emitted in the current TU at all. The following patch allows constant folding of comparisons of typeid addresses and makes it possible to implement P1328R1 - making type_info operator== constexpr (Jonathan has a patch for that). As mentioned in the PR, the varpool/middle-end code is trying to be conservative with address comparisons of different vars if those vars don't bind locally, because of possible aliases in other TUs etc. and so while match.pd folds &typeid(int) == &typeid(int) because it is equality comparison with the same operands, for different typeids it doesn't fold it. On Wed, Dec 08, 2021 at 08:53:03AM -0500, Jason Merrill wrote: > Would it make sense to assume that DECL_ARTIFICIAL variables can't be > aliases? If not, could we have some way of marking a variable as > non-aliasing, perhaps an attribute? I think DECL_ARTIFICIAL vars generally can overlap. The following patch adds a GCC internal attribute "non overlapping" and uses it in symtab_node::equal_address_to. Not sure what plans has Honza in that area and whether it would be useful to make the attribute public and let users assert that some variable will never overlap with other variables, won't have aliases etc. > During constant evaluation, the operator== could compare the type_info > address instead of the __name address, reducing this to the previous > problem. Ah, indeed, good idea. FYI, clang++ seems to constant fold &typeid(x) != &typeid(y) already, so Jonathan could use it even for clang++ in the constexpr operator==. But it folds even extern int &a, &b; constexpr bool c = &a != &b; regardless of whether some other TU has int a; int b __attribute__((alias (a)); or not. 2022-01-03 Jakub Jelinek <jakub@redhat.com> PR c++/103600 gcc/ * symtab.c (symtab_node::equal_address_to): Return 0 if one of VAR_DECLs has "non overlapping" attribute and rs1 != rs2. gcc/c-family/ * c-attribs.c (handle_non_overlapping_attribute): New function. (c_common_attribute_table): Add "non overlapping" attribute. gcc/cp/ * rtti.c (get_tinfo_decl_direct): Add "non overlapping" attribute to DECL_TINFO_P VAR_DECLs. gcc/testsuite/ * g++.dg/cpp0x/constexpr-typeid2.C: New test. |
||
---|---|---|
c++tools | ||
config | ||
contrib | ||
fixincludes | ||
gcc | ||
gnattools | ||
gotools | ||
include | ||
INSTALL | ||
intl | ||
libada | ||
libatomic | ||
libbacktrace | ||
libcc1 | ||
libcody | ||
libcpp | ||
libdecnumber | ||
libffi | ||
libgcc | ||
libgfortran | ||
libgo | ||
libgomp | ||
libiberty | ||
libitm | ||
libobjc | ||
liboffloadmic | ||
libphobos | ||
libquadmath | ||
libsanitizer | ||
libssp | ||
libstdc++-v3 | ||
libvtv | ||
lto-plugin | ||
maintainer-scripts | ||
zlib | ||
.dir-locals.el | ||
.gitattributes | ||
.gitignore | ||
ABOUT-NLS | ||
ar-lib | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING3 | ||
COPYING3.LIB | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
lt~obsolete.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
multilib.am | ||
README | ||
symlink-tree | ||
test-driver | ||
ylwrap |
This directory contains the GNU Compiler Collection (GCC). The GNU Compiler Collection is free software. See the files whose names start with COPYING for copying permission. The manuals, and some of the runtime libraries, are under different terms; see the individual source files for details. The directory INSTALL contains copies of the installation information as HTML and plain text. The source of this information is gcc/doc/install.texi. The installation information includes details of what is included in the GCC sources and what files GCC installs. See the file gcc/doc/gcc.texi (together with other files that it includes) for usage and porting information. An online readable version of the manual is in the files gcc/doc/gcc.info*. See http://gcc.gnu.org/bugs/ for how to report bugs usefully. Copyright years on GCC source files may be listed using range notation, e.g., 1987-2012, indicating that every year in the range, inclusive, is a copyrightable year that could otherwise be listed individually.