<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - __declspec(property): double invocations of foo() when compiling foo()->propertyName" href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D24132&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=Zuk7LmND9a53TerChoasv1fF4S8FTCeOUnXooD7QS7Y&s=vSoukxPXl7PA1S4sQ8JfuUn2avQv8xLhP6412YztZF8&e=">24132</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>__declspec(property): double invocations of foo() when compiling foo()->propertyName
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.6
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>chenxuz@outlook.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>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.</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>