<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 - Warn on very unsafe function-pointer casts"
href="https://bugs.llvm.org/show_bug.cgi?id=32188">32188</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Warn on very unsafe function-pointer casts
</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>enhancement
</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>hfinkel@anl.gov
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk, timshen91@gmail.com
</td>
</tr></table>
<p>
<div>
<pre>As Tim reminded us all when fixing r296771, some function-pointer casts are
more unsafe than others. In particular, some are ABI incompatible, and can lead
to hard-to-track-down bugs when used. We should consider always warning on
these, even if the cast is explicit.
For example, this:
typedef void (*fp1)(int, ...);
typedef void (*fp2)(int, int);
void bar(int, int);
fp1 foo() {
fp2 x = bar;
return (fp1) x; // WARN HERE
}
use of the return value of foo, without casting it back to a var-args type, is
unsafe under many ABIs. The calling convention for var-args functions vs.
non-var-args functions are different. How integer parameters vs. floating-point
parameters are passed, for example, are also different.
I recommend that we warn on these things under a separate flag that is on by
default. I hope we could make that not too noisy.</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>