GCC modified for the FreeChainXenon project
![]() The changes done to genericize_if_stmt in order to improve -Wunreachable-code* warning (which Richi didn't actually commit for GCC 12) are I think fine for normal ifs, but for constexpr if and consteval if we have two competing warnings. The problem is that we replace the non-taken clause (then or else) with void_node and keep the if (cond) { something } else {} or if (cond) {} else { something }; in the IL. This helps -Wunreachable-code*, if something can't fallthru but the non-taken clause can, we don't warn about code after it because it is still (in theory) reachable. But if the non-taken branch can't fallthru, we can get false positive -Wreturn-type warnings (which are enabled by default) if there is nothing after the if and the taken branch can't fallthru either. One possibility to fix this is revert at least temporarily to the previous behavior for constexpr and consteval if, yes, we can get false positive -Wunreachable-code* warnings but the warning isn't present in GCC 12. The patch below implements that for constexpr if which throws its clauses very early (either during parsing or during instantiation), and for consteval if it decides based on block_may_fallthru on the non-taken (for constant evaluation only) clause - if the non-taken branch may fallthru, it does what you did in genericize_if_stmt for consteval if, if it can't fallthru, it uses the older way of pretending there wasn't an if and just replacing it with the taken clause. There are some false positive risks with this though, block_may_fallthru is optimistic and doesn't handle some statements at all (like FOR_STMT, WHILE_STMT, DO_STMT - of course handling those is quite hard). For constexpr if (but perhaps for GCC 13?) we could try to block_may_fallthru before we throw it away and remember it in some flag on the IF_STMT, but am not sure how dangerous would it be to call it on the discarded stmts. Or if it is too dangerous e.g. just remember whether the discarded block of consteval if wasn't present or was empty, in that case assume fallthru, and otherwise assume it can't fallthru (-Wunreachable-code possible false positives). 2022-01-14 Jakub Jelinek <jakub@redhat.com> PR c++/103991 * cp-objcp-common.c (cxx_block_may_fallthru) <case IF_STMT>: For IF_STMT_CONSTEXPR_P with constant false or true condition only check if the taken clause may fall through. * cp-gimplify.c (genericize_if_stmt): For consteval if, revert to r12-5638^ behavior if then_ block can't fall through. For constexpr if, revert to r12-5638^ behavior. * g++.dg/warn/Wreturn-type-13.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 | ||
build.log | ||
ChangeLog | ||
ChangeLog.jit | ||
ChangeLog.tree-ssa | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
COPYING | ||
COPYING.LIB | ||
COPYING.RUNTIME | ||
COPYING3 | ||
COPYING3.LIB | ||
depcomp | ||
install-sh | ||
libtool-ldflags | ||
libtool.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
lt~obsolete.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.