<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58544>58544</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[C] (1024 > 2048) evaluating as true
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
paulprocacci
</td>
</tr>
</table>
<pre>
* Compiler Optimizations > O0 effect the outcome. O0 compiler option works just fine.
* Works on gcc regardless of optimizations
I was toying with a custom memory allocator as I had an idea to implement lzcnt when I ran into a strange phenomenon where a part of my program should not have been ran when indeed it was.
At first I thought this was a bug in my program so I debugged a bit until I reached an if statement which absolutely should evaluate as false but instead was evaluating as true.
Attached on line 80, you'll find the if in question. It reads as follows:
if(blksize > 2048)
blksize is a uint64_t which had the value of 1024. Given this, clearly the statement is false, yet the "return directMap(blksize);" which followed was being executed and shouldn't have been.
Examples:
# clang -Wall -O3 -fomit-frame-pointer -march=native -o alloc.o -c alloc.c
# cc -o test test.c alloc.o
# ./test
1024 > 2048
You should never get here!
With gcc this does not happen and works as expected:
# gcc -Wall -O3 -fomit-frame-pointer -march=native -o alloc.o -c alloc.c
# gcc -o test test.c alloc.o
# ./test
1024 > 2048
test.c in the above cases is just a simple: 'alloc(512);'
You'll notice if you're so inclined to check the return value you can a usable pointer instead of that "You should never get here!" so it is indeed working.
# clang -v
FreeBSD clang version 13.0.0 (git@github.com:llvm/llvm-project.git llvmorg-13.0.0-0-gd7b669b3a303)
Target: x86_64-unknown-freebsd13.1
Thread model: posix
InstalledDir: /usr/bin
# uname -a
FreeBSD nas.myhome 13.1-RELEASE FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC amd64
Not sure what other information I can provide, but please let me know if any questions arise!
[alloc.txt](https://github.com/llvm/llvm-project/files/9843814/alloc.txt)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVk1v2zgQ_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