[LLVMbugs] [Bug 14339] New: Virtual methods allowed to have mismatching calling convention

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Nov 14 12:16:11 PST 2012


             Bug #: 14339
           Summary: Virtual methods allowed to have mismatching calling
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: daniel.c.klauer at web.de
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 9537
  --> http://llvm.org/bugs/attachment.cgi?id=9537
virtual override with mismatching calling conventions

clang++ does not show an error (nor a warning) when an overriding method uses a
different calling convention than the overridden virtual, for example:

    class A {
            __attribute__((stdcall)) virtual void f();

    class B : public A {
            __attribute__((cdecl)) void f();

This code should trigger an error though, because the functions are
incompatible, similar to the following example:

    void (__attribute__((stdcall)) *p1)();
    void (__attribute__((cdecl)) *p2)();
    p1 = p2;

which triggers an "assigning to '...' from incompatible type '...'" error.

Looking at the LLVM IR output of -S -emit-llvm shows that the stdcall method is
emitted with x86_stdcallcc, and the call following the vtable lookup also uses
x86_stdcallcc, even though the loaded address points to a cdecl function.

A full example is attached. Compiling it with GCC's g++ shows a "conflicting
type attributes specified ..." error as expected; see also gcc bug 14688 [1].

Tested with:

    $ clang++ --version
    Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM
    Target: i386-pc-linux-gnu
    Thread model: posix

    $ build/Debug+Asserts/bin/clang++ --version
    clang version 3.2 (trunk 167930)
    Target: i386-pc-linux-gnu
    Thread model: posix

but presumably all x86 targets are affected.

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14688

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list