<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Invalid type for bit-field smaller than 32 bits"
href="https://bugs.llvm.org/show_bug.cgi?id=43439">43439</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Invalid type for bit-field smaller than 32 bits
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>alex_lop@walla.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Here is the reproduction of the bug: <a href="https://godbolt.org/z/_IWIqC">https://godbolt.org/z/_IWIqC</a>
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.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>