<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - [C standard violation] incorrect value of a variable pointer to a constant value after a recursive function call"
href="https://llvm.org/bugs/show_bug.cgi?id=25955">25955</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[C standard violation] incorrect value of a variable pointer to a constant value after a recursive function call
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</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>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>andrey.kuleshov@intel.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>-! this bug seems to be a violation of C standard
(6.2.4 Storage durations of objects paragraph 6):
"If the block is entered recursively, a new instance of the
object is created each time. The initial value of the object is indeterminate."
--! This problem appears because clang FE transforms const int b [] =
{constant} to an "internal constant", that means that the value is showed as a
local symbol (STB_LOCAL in the case of ELF) in the object file. But this
corresponds to a "static" keyword. Because of this no new temporary objects are
created and values of pointers are equal.
To my mind such array might be declared as "private", not "internal" in IR
==============HOW TO REPRODUCE====================
#include <stdio.h>
int f(int x,
#ifndef OK
const
#endif
int *a)
{
#ifndef OK
const
#endif
int b[] = { 1, 2, 3}; // any recursive call might create
if (!x)
return f(1, b); // f is recursively called with a
const int b[] as an argument
// a new temporary object might be
crated with a pointer to another address (6.2.4p6)
printf("const int b[] (variable declared in function): %p\n", b);
printf("const int *a (argument of a function): %p\n", a);
return b == a;
}
int main(void)
{
printf("Result of f(0,0) is: %d (might be 0)\n", f(0,0));
return 0;
}
================COMPARED TO OTHER COMPILERS=======================
<span class="quote">>>>Microsoft cl: </span >
const int b[] (variable declared in function): 000000ECFCE4FBF8
const int *a (argument of a function): 000000ECFCE4FC48
Result of f(0,0) is: 0 (might be 0)
<span class="quote">>>>Intel icc:</span >
const int b[] (variable declared in function): 0xffa3f9e0
const int *a (argument of a function): 0xffa3fa80
Result of f(0,0) is: 0 (might be 0)
<span class="quote">>>>gcc:</span >
const int b[] (variable declared in function): 0x7fff8a6dfa00
const int *a (argument of a function): 0x7fff8a6dfa30
Result of f(0,0) is: 0 (might be 0)
<span class="quote">>>>clang:</span >
const int b[] (variable declared in function): 0x400640
const int *a (argument of a function): 0x400640
Result of f(0,0) is: 1 (might be 0)
-------------------------
Intel Software Engineer
Andrey Kuleshov</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>