Go to file
Jakub Jelinek 896048cf43 c++: Add __builtin_bit_cast to implement std::bit_cast [PR93121]
The following patch adds __builtin_bit_cast builtin, similarly to
clang or MSVC which implement std::bit_cast using such an builtin too.
It checks the various std::bit_cast requirements, when not constexpr
evaluated acts pretty much like VIEW_CONVERT_EXPR of the source argument
to the destination type and the hardest part is obviously the constexpr
evaluation.
I've left out PDP11 handling of those, couldn't figure out how exactly are
bitfields laid out there

2020-12-03  Jakub Jelinek  <jakub@redhat.com>

	PR libstdc++/93121
	* fold-const.h (native_encode_initializer): Add mask argument
	defaulted to nullptr.
	(find_bitfield_repr_type): Declare.
	(native_interpret_aggregate): Declare.
	* fold-const.c (find_bitfield_repr_type): New function.
	(native_encode_initializer): Add mask argument and support for
	filling it.  Handle also some bitfields without integral
	DECL_BIT_FIELD_REPRESENTATIVE.
	(native_interpret_aggregate): New function.
	* gimple-fold.h (clear_type_padding_in_mask): Declare.
	* gimple-fold.c (struct clear_padding_struct): Add clear_in_mask
	member.
	(clear_padding_flush): Handle buf->clear_in_mask.
	(clear_padding_union): Copy clear_in_mask.  Don't error if
	buf->clear_in_mask is set.
	(clear_padding_type): Don't error if buf->clear_in_mask is set.
	(clear_type_padding_in_mask): New function.
	(gimple_fold_builtin_clear_padding): Set buf.clear_in_mask to false.
	* doc/extend.texi (__builtin_bit_cast): Document.

	* c-common.h (enum rid): Add RID_BUILTIN_BIT_CAST.
	* c-common.c (c_common_reswords): Add __builtin_bit_cast.

	* cp-tree.h (cp_build_bit_cast): Declare.
	* cp-tree.def (BIT_CAST_EXPR): New tree code.
	* cp-objcp-common.c (names_builtin_p): Handle RID_BUILTIN_BIT_CAST.
	(cp_common_init_ts): Handle BIT_CAST_EXPR.
	* cxx-pretty-print.c (cxx_pretty_printer::postfix_expression):
	Likewise.
	* parser.c (cp_parser_postfix_expression): Handle
	RID_BUILTIN_BIT_CAST.
	* semantics.c (cp_build_bit_cast): New function.
	* tree.c (cp_tree_equal): Handle BIT_CAST_EXPR.
	(cp_walk_subtrees): Likewise.
	* pt.c (tsubst_copy): Likewise.
	* constexpr.c (check_bit_cast_type, cxx_eval_bit_cast): New functions.
	(cxx_eval_constant_expression): Handle BIT_CAST_EXPR.
	(potential_constant_expression_1): Likewise.
	* cp-gimplify.c (cp_genericize_r): Likewise.

	* g++.dg/cpp2a/bit-cast1.C: New test.
	* g++.dg/cpp2a/bit-cast2.C: New test.
	* g++.dg/cpp2a/bit-cast3.C: New test.
	* g++.dg/cpp2a/bit-cast4.C: New test.
	* g++.dg/cpp2a/bit-cast5.C: New test.
2020-12-03 15:46:54 +01:00
config Daily bump. 2020-11-26 00:16:41 +00:00
contrib Daily bump. 2020-12-03 00:16:47 +00:00
fixincludes Daily bump. 2020-11-19 00:16:30 +00:00
gcc c++: Add __builtin_bit_cast to implement std::bit_cast [PR93121] 2020-12-03 15:46:54 +01:00
gnattools
gotools Daily bump. 2020-10-30 00:16:29 +00:00
include Daily bump. 2020-09-25 00:16:27 +00:00
INSTALL
intl
libada
libatomic Daily bump. 2020-11-30 00:16:27 +00:00
libbacktrace Daily bump. 2020-12-03 00:16:47 +00:00
libcc1 Daily bump. 2020-11-30 00:16:27 +00:00
libcpp Daily bump. 2020-12-02 00:16:41 +00:00
libdecnumber Daily bump. 2020-07-31 00:16:26 +00:00
libffi Daily bump. 2020-11-30 00:16:27 +00:00
libgcc introduce overridable clear_cache emitter 2020-12-02 22:10:32 -03:00
libgfortran Daily bump. 2020-11-30 00:16:27 +00:00
libgo internal/cpu: don't define CacheLinePadSize for mips64x 2020-11-30 12:24:17 -08:00
libgomp Daily bump. 2020-11-30 00:16:27 +00:00
libhsail-rt Daily bump. 2020-11-30 00:16:27 +00:00
libiberty Daily bump. 2020-11-26 00:16:41 +00:00
libitm Daily bump. 2020-11-30 00:16:27 +00:00
libobjc Daily bump. 2020-11-30 00:16:27 +00:00
liboffloadmic Daily bump. 2020-11-30 00:16:27 +00:00
libphobos Daily bump. 2020-12-01 00:16:38 +00:00
libquadmath Daily bump. 2020-11-30 00:16:27 +00:00
libsanitizer Daily bump. 2020-11-30 00:16:27 +00:00
libssp Daily bump. 2020-11-30 00:16:27 +00:00
libstdc++-v3 Daily bump. 2020-12-03 00:16:47 +00:00
libvtv Daily bump. 2020-11-30 00:16:27 +00:00
lto-plugin Daily bump. 2020-11-30 00:16:27 +00:00
maintainer-scripts Daily bump. 2020-05-30 00:16:27 +00:00
zlib Daily bump. 2020-11-30 00:16:27 +00:00
.dir-locals.el
.gitattributes
.gitignore Sync .gitignore with binutils-gdb 2020-12-02 11:04:01 -07:00
ABOUT-NLS
ar-lib
ChangeLog Daily bump. 2020-12-03 00:16:47 +00:00
ChangeLog.jit
ChangeLog.tree-ssa
compile
config-ml.in config-ml.in: Suppress output from multi-do recipes 2020-11-09 14:28:37 +00:00
config.guess config.sub, config.guess : Import upstream 2020-11-07. 2020-11-23 19:30:01 +00:00
config.rpath
config.sub config.sub, config.guess : Import upstream 2020-11-07. 2020-11-23 19:30:01 +00:00
configure configure: Support building D front-end on *-*-darwin* 2020-11-29 22:09:42 +01:00
configure.ac configure: Support building D front-end on *-*-darwin* 2020-11-29 22:09:42 +01:00
COPYING
COPYING3
COPYING3.LIB
COPYING.LIB
COPYING.RUNTIME
depcomp
install-sh
libtool-ldflags
libtool.m4 Fix hppa64-hpux11 build to remove source paths from embedded path. 2020-11-29 20:11:38 +00:00
lt~obsolete.m4
ltgcc.m4
ltmain.sh
ltoptions.m4
ltsugar.m4
ltversion.m4
MAINTAINERS MAINTAINERS: Add myself as arc port maintainer 2020-12-02 16:09:21 +02:00
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.