[LLVMbugs] [Bug 15768] New: [-cxx-abi microsoft] __cdecl methods returning structures misbehave

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Apr 17 07:50:03 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=15768

            Bug ID: 15768
           Summary: [-cxx-abi microsoft] __cdecl methods returning
                    structures misbehave
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: timurrrr at google.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

----------------
$ cat cl.cpp
extern "C" int printf(const char *fmt, ...);

struct S {
  int a, b, c;
};

struct This {
  S __cdecl foo(S x);
  int field;
};

int main(void) {
  This obj;
  obj.field = 13;
  S arg;
  arg.a = 99;
  S s = obj.foo(arg);
  printf("obj.field = %d\n", obj.field);
  return 0;
}
----------------
$ cat clang.cpp
extern "C" int printf(const char *fmt, ...);

struct S {
  int a, b, c;
};

struct This {
  S __cdecl foo(S x);
  int field;
};

S __cdecl This::foo(S x) {
  S ret;
  ret.a = 42;
  printf("field = %d, x.a = %d\n", field, x.a);
  field = 77;
  return ret;
}
----------------
$ cl cl.cpp clang.cpp && ./cl.exe
field = 13, x.a = 99
obj.field = 77
----------------
$ clang -Xclang -cxx-abi -Xclang microsoft clang.cpp -c && \
  cl -nologo -c cl.cpp && link clang.o cl.obj && ./clang.exe
field = -2, x.a = 99
obj.field = 42
(As of Clang r179681)

-- 
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/20130417/8ca7af7d/attachment.html>


More information about the llvm-bugs mailing list