<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 - missed opt: restrict not propagated to definition"
href="https://bugs.llvm.org/show_bug.cgi?id=43104">43104</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>missed opt: restrict not propagated to definition
</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>All
</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>C
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>gonzalobg88@gmail.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>The following code:
int foo(int* restrict x, int* restrict y);
int foo(int* x, int* y) { return *x + *y; }
C11 6.2.7p2 (<a href="https://port70.net/~nsz/c/c11/n1570.html#6.2.7p2">https://port70.net/~nsz/c/c11/n1570.html#6.2.7p2</a>) says:
<span class="quote">> All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined.</span >
C11 6.7.6.3p15 (<a href="https://port70.net/~nsz/c/c11/n1570.html#6.7.6.3p15">https://port70.net/~nsz/c/c11/n1570.html#6.7.6.3p15</a>):
<span class="quote">> For two function types to be compatible, [...] corresponding parameters shall have compatible types</span >
C11 6.7.6.1p2 (<a href="https://port70.net/~nsz/c/c11/n1570.html#6.7.6.1p2">https://port70.net/~nsz/c/c11/n1570.html#6.7.6.1p2</a>) says:
<span class="quote">> For two pointer types to be compatible, both shall be identically qualified and both shall be pointers to compatible types.</span >
so AFAICT this program has undefined behavior, because the prototypes are not
compatible, because their argument types are not compatible, because they are
pointer types that are differently cvr-qualified.
It isn't uncommon in C to give more work at the declarations in header files,
which is what most users of a library end up using, than to the implementation
of those declarations in a `.c` file. So we could propagate noalias to the
definition in this case. We should also propagate noalias from definitions to
function declarations for the opposite case, e.g., when the definition is
noalias, but the declaration is not.
We have an incompatible type diagnostic that for some reason is a warning and
not an error, and that it doesn't warn on this case. I think we should also do
this, but if the declaration is in a different translation unit, such warnings
can only be emitted, e.g., during LTO.</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>