[llvm-bugs] [Bug 43439] New: Invalid type for bit-field smaller than 32 bits
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Sep 25 00:46:13 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43439
Bug ID: 43439
Summary: Invalid type for bit-field smaller than 32 bits
Product: clang
Version: 9.0
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C11
Assignee: unassignedclangbugs at nondot.org
Reporter: alex_lop at walla.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Here is the reproduction of the bug: https://godbolt.org/z/_IWIqC
The compilation fails on the static_assert, while it shouldn't based on the C11
standard (see quoting below in this post).
The code example below was compiled with the following options: -O3 -std=c11
-Wall -Wextra -v
#include <stdint.h>
#include <assert.h>
#define CHECK_NUM(num) _Generic((num), \
uint64_t : 0, \
int64_t : 0, \
default : 1)
int main(void)
{
struct _s
{
uint64_t val : 1;
} s = {0};
static_assert(CHECK_NUM(s.val), "Variable too large #1"); // <strong>Should
not fail here</strong>
return 0;
}
The compilation output:
clang version 9.0.0 (tags/RELEASE_900/final 372344)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/compiler-explorer/clang-9.0.0/bin
Found candidate GCC installation:
/opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0
Selected GCC installation:
/opt/compiler-explorer/gcc-9.2.0/lib/gcc/x86_64-linux-gnu/9.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64
"/opt/compiler-explorer/clang-9.0.0/bin/clang-9" -cc1 -triple
x86_64-unknown-linux-gnu -S -disable-free -disable-llvm-verifier
-discard-value-names -main-file-name example.c -mrelocation-model static
-mthread-model posix -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info
-debug-info-kind=limited -dwarf-version=4 -debugger-tuning=gdb
-momit-leaf-frame-pointer -v -coverage-notes-file /home/ubuntu/./output.gcno
-resource-dir /opt/compiler-explorer/clang-9.0.0/lib/clang/9.0.0
-internal-isystem /usr/local/include -internal-isystem
/opt/compiler-explorer/clang-9.0.0/lib/clang/9.0.0/include
-internal-externc-isystem /usr/include/x86_64-linux-gnu
-internal-externc-isystem /include -internal-externc-isystem /usr/include -O3
-Wall -Wextra -std=c11 -fdebug-compilation-dir /home/ubuntu -ferror-limit 19
-fmessage-length 0 -fobjc-runtime=gcc -fdiagnostics-show-option
-fcolor-diagnostics -vectorize-loops -vectorize-slp -mllvm
--x86-asm-syntax=intel -faddrsig -o ./output.s -x c <source>
clang -cc1 version 9.0.0 based upon LLVM 9.0.0 default target
x86_64-unknown-linux-gnu
ignoring nonexistent directory "/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/opt/compiler-explorer/clang-9.0.0/lib/clang/9.0.0/include
/usr/include/x86_64-linux-gnu
/usr/include
End of search list.
<source>:15:5: error: static_assert failed "Variable too large #1"
static_assert(CHECK_NUM(s.val), "Variable too large #1"); // Should not
fail here
^ ~~~~~~~~~~~~~~~~
/usr/include/assert.h:143:24: note: expanded from macro 'static_assert'
# define static_assert _Static_assert
^
1 error generated.
Compiler returned: 1
--------------------------------------------------------------------------------------------
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 1 for int in this case.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190925/42b508ac/attachment.html>
More information about the llvm-bugs
mailing list