public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/114657] New: Invalid type conversion from some _BitInt bit-fields
@ 2024-04-09 13:36 juuso.alasuutari at gmail dot com
  2024-04-09 13:54 ` [Bug c/114657] " jakub at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: juuso.alasuutari at gmail dot com @ 2024-04-09 13:36 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114657

            Bug ID: 114657
           Summary: Invalid type conversion from some _BitInt bit-fields
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: juuso.alasuutari at gmail dot com
  Target Milestone: ---

Created attachment 57911
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57911&action=edit
Preprocessed test program source

Summary
-------

GCC's type conversion from some bit-precise integer-typed bit-fields
does not match the description in the C23 standard.


Expected vs. observed behavior
------------------------------

Based on footnote on page 47 of ISO/IEC 9899/2024 6.3.1.1 (n3320.pdf),
the converted type of a _BitInt bit-field should match the original
bit-precise integer:

  "E.g. unsigned _BitInt(7): 2 is a bit-field that can hold the
   values 0, 1, 2, 3, and converts to unsigned _BitInt(7)."

My expectation would then be to see the following output, which does
in fact happen when compiling with clang-19:

  $ ./test
  unsigned _BitInt(7)

This is what GCC does:

  $ ./test
  unsigned _BitInt(2)


Output of gcc-14 -v
-------------------

Using built-in specs.
COLLECT_GCC=gcc-14
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-linux-gnu/14/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 14-20240330-1'
--with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs
--enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr
--with-gcc-major-version-only --program-suffix=-14
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-vtable-verify
--enable-plugin --enable-default-pie --with-system-zlib
--enable-libphobos-checking=release --with-target-system-zlib=auto
--enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet
--with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/reproducible-path/gcc-14-14-20240330/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/reproducible-path/gcc-14-14-20240330/debian/tmp-gcn/usr
--enable-offload-defaulted --without-cuda-driver
--enable-checking=yes,extra,rtl --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 14.0.1 20240330 (experimental) [master r14-9728-g6fc84f680d0]
(Debian 14-20240330-1) 


Compilation command
-------------------

gcc-14 -std=gnu23 -Wall -Wextra -Wpedantic -save-temps -o test test.c

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/114657] Invalid type conversion from some _BitInt bit-fields
  2024-04-09 13:36 [Bug c/114657] New: Invalid type conversion from some _BitInt bit-fields juuso.alasuutari at gmail dot com
@ 2024-04-09 13:54 ` jakub at gcc dot gnu.org
  2024-04-09 14:01 ` jakub at gcc dot gnu.org
  2024-04-09 14:37 ` jsm28 at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-09 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114657

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I believe Joseph said this isn't well specified in the C standard, see
https://gcc.gnu.org/pipermail/gcc-patches/2023-July/625765.html
If you use something like + 0uwb it should be the type after the integral
promotions and so what the standard specifies for integral promotions of the
_BitInt bit-fields.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/114657] Invalid type conversion from some _BitInt bit-fields
  2024-04-09 13:36 [Bug c/114657] New: Invalid type conversion from some _BitInt bit-fields juuso.alasuutari at gmail dot com
  2024-04-09 13:54 ` [Bug c/114657] " jakub at gcc dot gnu.org
@ 2024-04-09 14:01 ` jakub at gcc dot gnu.org
  2024-04-09 14:37 ` jsm28 at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-04-09 14:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114657

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
In particular, 6.5.1.1/2 says
"The type of the controlling expression is the type of the expression as if it
had undergone an lvalue conversion, array to pointer conversion, or function to
pointer conversion."
but doesn't list integer promotions (if those were to occur, you'd e.g. never
be able to match a char, signed char, unsigned char, short, unsigned short
types with _Generic because everything would be promoted to int.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c/114657] Invalid type conversion from some _BitInt bit-fields
  2024-04-09 13:36 [Bug c/114657] New: Invalid type conversion from some _BitInt bit-fields juuso.alasuutari at gmail dot com
  2024-04-09 13:54 ` [Bug c/114657] " jakub at gcc dot gnu.org
  2024-04-09 14:01 ` jakub at gcc dot gnu.org
@ 2024-04-09 14:37 ` jsm28 at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: jsm28 at gcc dot gnu.org @ 2024-04-09 14:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114657

--- Comment #3 from Joseph S. Myers <jsm28 at gcc dot gnu.org> ---
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2958.htm has my analysis of
the various notions of "type" used in relation to bit-fields and the questions
of what expressions are considered to have special properties associated with
referring to a bit-field.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-09 14:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09 13:36 [Bug c/114657] New: Invalid type conversion from some _BitInt bit-fields juuso.alasuutari at gmail dot com
2024-04-09 13:54 ` [Bug c/114657] " jakub at gcc dot gnu.org
2024-04-09 14:01 ` jakub at gcc dot gnu.org
2024-04-09 14:37 ` jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).