[llvm-bugs] [Bug 26986] New: Return by reference causes crash while return by value works fine

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 18 01:33:25 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=26986

            Bug ID: 26986
           Summary: Return by reference causes crash while return by value
                    works fine
           Product: clang
           Version: 3.4
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: bhupendra_thosare at persistent.co.in
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

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 https://www.openoffice.org/udk/common/man/uno.html
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
>::get().getTypeLibType() };
        ::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.

-- 
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/20160318/404a87ef/attachment.html>


More information about the llvm-bugs mailing list