[llvm-bugs] [Bug 32188] New: Warn on very unsafe function-pointer casts

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 8 17:12:07 PST 2017


            Bug ID: 32188
           Summary: Warn on very unsafe function-pointer casts
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hfinkel at anl.gov
                CC: llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk,
                    timshen91 at gmail.com

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.

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170309/5add60f7/attachment.html>

More information about the llvm-bugs mailing list