[LLVMbugs] [Bug 24132] New: __declspec(property): double invocations of foo() when compiling foo()->propertyName
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jul 15 10:05:31 PDT 2015
https://llvm.org/bugs/show_bug.cgi?id=24132
Bug ID: 24132
Summary: __declspec(property): double invocations of foo() when
compiling foo()->propertyName
Product: clang
Version: 3.6
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: chenxuz at outlook.com
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Code for repro is as follows.
00 #include <stdio.h>
01 class Test1 {
02 private:
03 int x_;
04 public:
05 Test1(int x) : x_(x) {}
06 __declspec(property(get=get_x)) int X;
07 int get_x() const { return x_; }
08 static Test1* GetTest1(){printf("create,"); return new Test1(10);}
09 };
10 int main(int argc, char** argv) {
11 int x = Test1::GetTest1()->X;
12 printf("x=%d\n",x);
13 }
The execution output is like:
create,create,x=10
Basically, the compiler builds the code line 11 into
0x000000000040077f call 0x4007c0 <Test1::GetTest1()>
0x0000000000400784 mov QWORD PTR [rbp-0x20],rax
0x0000000000400788 call 0x4007c0 <Test1::GetTest1()>
0x000000000040078d mov rdi,rax
0x0000000000400790 call 0x400830 <Test1::get_x() const>
0x0000000000400795 movabs rdi,0x4008e4
0x000000000040079f mov DWORD PTR [rbp-0x14],eax
As we notice, Test1::GetTest1() is called twice. The result of the 1st call is
stored into a compiler-allocated stack variable, and seems never used later;
The result of the 2nd call is passed as "this" pointer to Test1::get_x(). Is
this an expected behavior? Since our real GetTest1() is not idempotent, being
called twice is causing incorrect program behavior.
--
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/20150715/e3422a90/attachment.html>
More information about the llvm-bugs
mailing list