<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 --- - Return by reference causes crash while return by value works fine"
href="https://llvm.org/bugs/show_bug.cgi?id=26986">26986</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Return by reference causes crash while return by value works fine
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.4
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>bhupendra_thosare@persistent.co.in
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Hi All,
We are using following configuration:
OS: RHEL 7
Kernal: 3.10.0-123.8.1.el7.x86_64
gcc compiler: gcc version 4.8.2
clang compiler: clang version 3.4.2
Component implemented using <a href="https://www.openoffice.org/udk/common/man/uno.html">https://www.openoffice.org/udk/common/man/uno.html</a>
technology.
In our code, we are default constructing a structure "XXXX" that contains some
member variables, two enums and a structure.
While default constructing the code, UNO uses following method internally.
==== CODE:
inline ::com::sun::star::uno::Type const & cppu_detail_getUnoType(XXXX const *)
{
//TODO: On certain platforms with weak memory models, the following code
can result in some threads observing that the_type points to garbage
static ::typelib_TypeDescriptionReference * the_type = 0;
if (the_type == 0) {
::typelib_TypeDescriptionReference * the_members[] = {
::cppu::UnoType< ::rtl::OUString >::get().getTypeLibType(),
::cppu::UnoType< ::rtl::OUString >::get().getTypeLibType(),
::cppu::UnoType< SomeEnum >::get().getTypeLibType(),
::cppu::UnoType< SomeEnum >::get().getTypeLibType(),
::cppu::UnoType< ::sal_Int64 >::get().getTypeLibType(),
::cppu::UnoType< ::sal_Int64 >::get().getTypeLibType(),
::cppu::UnoType< SomeStructure >::get().getTypeLibType(),
::cppu::UnoType< ::com::sun::star::uno::Any
<span class="quote">>::get().getTypeLibType() };</span >
::typelib_static_struct_type_init(&the_type, "XXXX", 0, 8, the_members,
0);
}
::std::cerr << ::std::endl << "Before reinterpret_cast";
static ::com::sun::star::uno::Type returnValue = *reinterpret_cast<
::com::sun::star::uno::Type * >(&the_type);
::std::cerr << ::std::endl << "returnValue Type = " <<
returnValue.getTypeName();
return returnValue;
}
When we are release building (without -g) the component (that default construct
XXXX) using clang then cppu_detail_getUnoType()returns NULL when it return by
reference and therefore further it crashes with SIGSEGV.
Please note that "returnValue" is always valid object and we have confirmed it
using "returnValue.getTypeName()" but returned value at caller is NULL when it
return by reference.
However, when we use return by value as follows:
inline ::com::sun::star::uno::Type const
cppu_detail_getUnoType(::xoc::svc::event::ZEventObject const *)
Then, cppu_detail_getUnoType()returns valid object and everything works fine.
We do not have any clue why return by reference causes crash and return by
value works fine with clang.
With gcc, return by reference everything works fine.
Please let us know your suggestion.</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>