Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Christopher_W_1
Beginner
118 Views

Crash with boost::shared_ptr and -check-uninit

 

Hi,

the sample program below crashes if compiled with

   icc sample.cpp -std=c++11 -check=uninit

with the Intel C++ compiler v14 on Linux (Suse Linux Enterprise Desktop 11) - it claims that some variable is used without initialization, but the header file looks right to me.

Has anyone else encountered this problem? Is it a boost or compiler issue? What can I do if I want to keep both boost and the debug option?

Best Regards,

    Christopher

#include <memory>
#include <iostream>

#include <boost/shared_ptr.hpp>

int main(const char* argv[], int argc)
{
    boost::shared_ptr<int> value(new int);
    *value = 1;
    std::cout << *value << std::endl;
}
0 Kudos
7 Replies
Marián__VooDooMan__M
New Contributor II
118 Views

Greetings,

the shared pointer code looks good to me. But I see a programming mistake:

int main(const char* argv[], int argc)

change this to:

int main(int argc, const char* argv[])

This is the correct order of arguments of main() function.

Christopher_W_1
Beginner
118 Views

Hi,

you are right, I got that mixed up. Should have written int main() anyway since I do not use argc/argv. But the program aborts in either variant after the 1 is printed to stdout (Run-Time Check Failure: The variable 'r' is being used without being initialized).

By the way, my icc is 14.0.4 (gcc version 4.3.0 compatibility), gcc/libc++ version on that machine is 4.3.4, and the boost rpm is boost-devel-1.36.0-12.3.1. Stack trace:

#0  0x00002b6f86a7cb55 in raise () in /lib64/libc-2.11.3.so

#1  0x00002b6f86a7e131 in abort () in /lib64/libc-2.11.3.so

#2  0x0000000000401bd0 in __libirc_get_msg () in a.out

#3  0x00007fff89e1ace0 in ?? ()

#4  0x0000000000401730 in boost::detail::atomic_exchange_and_add (pw=0x606038, dv=-1) at /usr/include/boost/detail/sp_counted_base_gcc_x86.hpp:43

#5  0x000000000040149f in boost::detail::sp_counted_base::release (this=0x606030) at /usr/include/boost/detail/sp_counted_base_gcc_x86.hpp:143

#6  0x000000000040154f in boost::detail::shared_count::~shared_count (this=0x7fff89e1abc8) at /usr/include/boost/detail/shared_count.hpp:216

#7  0x0000000000401308 in boost::shared_ptr<int>::~shared_ptr (this=0x7fff89e1abc0) at /usr/include/boost/shared_ptr.hpp:164

#8  0x00000000004010e9 in main (argc=1, argv=0x7fff89e1ace8) at sample.cpp:10

Regards,

  Christopher

118 Views

Hi Christopher,

I failed to reproduce your issue on my environment. It just works and will not crash at runtime (also no message about "without initialization").

My boost is as below: boost-1.41.0-11.el6_1.2.x86_64

I may need to build the same boost version to reproduce your issue and see whether this is an issue of Boost or an false positive case from ICC's uninit checking.

Also, could you please send me the pre-processed file to me (icc sample.cpp -std=c++11 -check=uninit -E)? I may build your pre-processed file directly.

Thanks,

Shenghong

Christopher_W_1
Beginner
118 Views

Hi Shengong,

sorry I somehow missed your answer in November. The problem is still troubling us, I will send you the preprocessed file when I have access to it tomorrow morning.

We recently stumbled into a related problem with a QT 4.8.6 header (include/QtCore/qatomic_x86_64.h). I do not have a sample program at hand, but the problematic section of the header is the following, and actually looks pretty much the same as in boost:

inline bool QBasicAtomicInt::deref()
{
    unsigned char ret;
    asm volatile("lock\n"
                 "decl %0\n"
                 "setne %1"
                 : "=m" (_q_value), "=qm" (ret)
                 : "m" (_q_value)
                 : "memory");
    return ret != 0;
}

This causes an error "ret is used without being initialized" when used in an object file compiled with --check uninit. If we change the header to initalize ret with zero, no error occurs.

 

Thank you,

  Christopher

118 Views

Hi Christopher,

Thank you for your update. I am kind of clear about the issue now, and reproduce it as below:

$ cat temp.cpp
// icc test.cpp -check=uninit -DFUNC=foo && ./a.out
#include <stdio.h>

static __attribute__((used)) int var1=1;

int foo() {
  int ret;
  ret=var1;
  return ret;
}

int bar() {
  int ret;
  asm("mov var1, %0" : "=r" (ret));
  return ret;
}

int main() {
        printf("%d\n", FUNC());
        return 0;
}
$ icc temp.cpp -DFUNC=foo && ./a.out
1
$ icc temp.cpp -DFUNC=bar && ./a.out
1
$ icc temp.cpp -check=uninit -DFUNC=foo && ./a.out
1
$ icc temp.cpp -check=uninit -DFUNC=bar && ./a.out

Run-Time Check Failure: The variable 'ret' is being used in temp.cpp(14,0) without being initialized

Aborted (core dumped)
$

I'll report it to dev team to see whether it is possible to make this uninit check work for asm code.

Thanks,

Shenghong

Christopher_W_1
Beginner
118 Views

 

Hi Shegong,

thank you very much for your effort.

I just discovered a similar thread on the forum, "False Positives when Boost::shared_ptr is used with Inspector?", which might be the same or a related issue.

    Christopher

118 Views

Hi Christopher,

The issue is fixed in update 3 compiler, my verification as below:

$ cat temp.cpp
// icc test.cpp -check=uninit -DFUNC=foo && ./a.out
#include <stdio.h>

static __attribute__((used)) int var1=1;

int foo() {
  int ret;
  ret=var1;
  return ret;
}

int bar() {
  int ret;
  asm("mov var1, %0" : "=r" (ret));
  return ret;
}

int main() {
        printf("%d\n", FUNC());
        return 0;
}$icc temp.cpp -check=uninit -DFUNC=bar && ./a.out
1
$

Let me know if you still have issues.

Thanks,

Shenghong