<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 - issue with unsigned long operations. (hweight64)"
href="https://bugs.llvm.org/show_bug.cgi?id=32915">32915</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>issue with unsigned long operations. (hweight64)
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bogdan.becheriu@yahoo.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=18406" name="attach_18406" title="the source code affected">attachment 18406</a> <a href="attachment.cgi?id=18406&action=edit" title="the source code affected">[details]</a></span>
the source code affected
compile the following code. (also attached)
/** compute number of 1 bits in generic data type
* Copyright (C) 2017 Bogdan Becheriu
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <<a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>>.
*/
#define HWEIGHT_IMPL(x) \
static __inline__ unsigned int hweight ## x(u ## x w)\
{\
unsigned int k;\
for (k = 1; k < sizeof(w) << 3; k <<= 1) {\
u ## x mask = ((u ## x)-1) / ((1 << k) + 1);\
w = (w & mask) + ((w >> k) & mask);\
}\
return w;\
}
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long u64;
HWEIGHT_IMPL(8)
HWEIGHT_IMPL(16)
HWEIGHT_IMPL(32)
HWEIGHT_IMPL(64)
/* @@ demo */
#include "stdio.h"
int main(int argc, char *argv[], char **envp)
{
printf("bits set in %d: %d %d %d %d\n", -1, hweight8(-1),
hweight16(-1), hweight32(-1), hweight64(-1));
return 0;
}
--------------------------
it happens only when enabling -O2 or higher on the hweight64 implementation
(unsigned long type).
please see output of executable on both gcc and clang below.
me@gentoo ~/probablyuseless-code $ gcc -Wall -Werror -pedantic -O3 -ansi
hweight.c
me@gentoo ~/probablyuseless-code $ ./a.out
bits set in -1: 8 16 32 64
me@gentoo ~/probablyuseless-code $ clang -Wall -Werror -pedantic -O3 -ansi
hweight.c
me@gentoo ~/probablyuseless-code $ ./a.out
bits set in -1: 8 16 32 0
clang version 3.9.1 (tags/RELEASE_391/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin</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>