[Bug tree-optimization/94086] Missed optimization when converting a bitfield to an integer on x86-64

2020-03-08 Thread alex_lop at walla dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94086

alex_lop at walla dot com changed:

   What|Removed |Added

 CC||alex_lop at walla dot com

--- Comment #1 from alex_lop at walla dot com ---
Relevant discussion on stackoverflow:
https://stackoverflow.com/q/60580591/5218277

[Bug c/91893] New: Bit-field larger than 32 bits has invalid type

2019-09-24 Thread alex_lop at walla dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91893

Bug ID: 91893
   Summary: Bit-field larger than 32 bits has invalid type
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: alex_lop at walla dot com
  Target Milestone: ---

Example: https://godbolt.org/z/4JJtTr

#include 
#include 

#define CHECK_NUM(num)_Generic((num),   \
uint64_t : 0,   \
int64_t : 0,\
default : 1)
int main(void)
{ 
struct _s
{
uint64_tval : 33; // this cannot be held in unsigned int
} s;

static_assert(CHECK_NUM(s.val), "Variable too large #1"); //
Compilation should fail here

(void)s;

return 0;
}


Based on the C11 standard section 6.3.1.1 Boolean, characters and integers :
"If an int can represent all values of the original type (as restricted by the
width, for a bit-field), the value is converted to an int; otherwise, it is
converted to an unsigned int. These are called the integer promotions.) All
other types are unchanged by the integer promotions."

I would expect _Generic((s.val), ...) to return 0 for uint64_t in this case.

Note: might be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84516 


Compiler configuration:
Using built-in specs.

COLLECT_GCC=/opt/compiler-explorer/gcc-9.2.0/bin/gcc

Target: x86_64-linux-gnu

Configured with: ../gcc-9.2.0/configure
--prefix=/opt/compiler-explorer/gcc-build/staging --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu --disable-bootstrap
--enable-multiarch --with-abi=m64 --with-multilib-list=m32,m64,mx32
--enable-multilib --enable-clocale=gnu --enable-languages=c,c++,fortran,ada
--enable-ld=yes --enable-gold=yes --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-linker-build-id --enable-lto
--enable-plugins --enable-threads=posix
--with-pkgversion=Compiler-Explorer-Build

Thread model: posix

gcc version 9.2.0 (Compiler-Explorer-Build) 

COLLECT_GCC_OPTIONS='-fdiagnostics-color=always' '-g' '-o' './output.s'
'-masm=intel' '-S' '-O3' '-std=c11' '-Wall' '-m32' '-Wpedantic' '-Wextra' '-v'
'-mtune=generic' '-march=x86-64'

 /opt/compiler-explorer/gcc-9.2.0/bin/../libexec/gcc/x86_64-linux-gnu/9.2.0/cc1
-quiet -v -imultilib 32 -imultiarch i386-linux-gnu -iprefix
/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/x86_64-linux-gnu/9.2.0/
 -quiet -dumpbase example.c -masm=intel -m32 -mtune=generic
-march=x86-64 -auxbase-strip ./output.s -g -O3 -Wall -Wpedantic -Wextra
-std=c11 -version -fdiagnostics-color=always -o ./output.s

GNU C11 (Compiler-Explorer-Build) version 9.2.0 (x86_64-linux-gnu)

compiled by GNU C version 7.4.0, GMP version 6.1.0, MPFR version 3.1.4,
MPC version 1.0.3, isl version isl-0.18-GMP



GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

ignoring nonexistent directory
"/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include"

ignoring duplicate directory
"/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/9.2.0/include"

ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"

ignoring duplicate directory
"/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/9.2.0/include-fixed"

ignoring nonexistent directory
"/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/../../lib/gcc/x86_64-linux-gnu/9.2.0/../../../../x86_64-linux-gnu/include"

ignoring nonexistent directory "/usr/include/i386-linux-gnu"

#include "..." search starts here:

#include <...> search starts here:

 /opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/x86_64-linux-gnu/9.2.0/include


/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/x86_64-linux-gnu/9.2.0/include-fixed

 /usr/local/include

 /opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/../../include

 /usr/include

End of search list.

GNU C11 (Compiler-Explorer-Build) version 9.2.0 (x86_64-linux-gnu)

compiled by GNU C version 7.4.0, GMP version 6.1.0, MPFR version 3.1.4,
MPC version 1.0.3, isl version isl-0.18-GMP



GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

Compiler executable checksum: eb31180ed62a495914b9b0bdb15992b1

COMPILER_PATH=/opt/compiler-explorer/gcc-9.2.0/bin/../libexec/gcc/x86_64-linux-gnu/9.2.0/:/opt/compiler-explorer/gcc-9.2.0/bin/../libexec/gcc/:/opt/compiler-explorer/gcc-9.2.0/bin/../lib/gcc/x86_64-linux-gnu/9.2.0/.

[Bug c/91893] Bit-field larger than 32 bits has invalid type

2019-09-25 Thread alex_lop at walla dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91893

--- Comment #2 from alex_lop at walla dot com ---
(In reply to Richard Biener from comment #1)
> I believe the type you get is actually a 33-bit type and thus the _Generic
> doesn't apply.  IIRC "long" bitfields are a GCC extension.

I am not a lawyer but if the standard says: "All other types are unchanged by
the integer promotions", then I understand that in case 

struct _s
{
uint64_t val : 33;
} s;

s.val has to be uint64_t, hasn't it?