<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 - clang handles differently signed overflow depending on variable constness and its storage"
href="https://bugs.llvm.org/show_bug.cgi?id=43686">43686</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang handles differently signed overflow depending on variable constness and its storage
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</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>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>ki.stfu@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Godbolt: <a href="https://godbolt.org/z/2uqkzB">https://godbolt.org/z/2uqkzB</a>
The first one, with i32_max int on stack prints "is 0" and returns 0:
```
int int_test() {
int i32_max = std::numeric_limits<int>::max();
int res = i32_max + 3;
printf("res %d < i32_max %d is %d\n", res, i32_max, (int)(res < i32_max));
// ... is 0
return (int)(res < i32_max); // returns 0
}
-----------------------------------
int_test(): # @int_test()
push rax
mov edi, offset .L.str
mov esi, -2147483646
mov edx, 2147483647
xor ecx, ecx
xor eax, eax
call printf
xor eax, eax
pop rcx
ret
```
The second function, with i32_max const int on stack prints "is 1" and returns
1:
```
int const_int_test() {
const int i32_max = std::numeric_limits<int>::max();
int res = i32_max + 3;
printf("res %d < i32_max %d is %d\n", res, i32_max, (int)(res < i32_max));
// ... is 1
return (int)(res < i32_max); // returns 1
}
-----------------------------------
const_int_test(): # @const_int_test()
push rax
mov edi, offset .L.str
mov esi, -2147483646
mov edx, 2147483647
mov ecx, 1
xor eax, eax
call printf
mov eax, 1
pop rcx
ret
```
And in the last case, with i32_max static int, it prints "is 0" and returns 1:
```
int static_int_test() {
static int i32_max = std::numeric_limits<int>::max();
int res = i32_max + 3;
printf("res %d < i32_max %d is %d\n", res, i32_max, (int)(res < i32_max));
// ... is 0
return (int)(res < i32_max); // return 1
}
-----------------------------------
static_int_test(): # @static_int_test()
push rax
mov edi, offset .L.str
mov esi, -2147483646
mov edx, 2147483647
xor ecx, ecx
xor eax, eax
call printf
mov eax, 1
pop rcx
ret
```
Also, clang warns about signed overflow only in the const int 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>