Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

2018.1 crashes in basic code with strings

David_H_4
Beginner
820 Views

This crash occurs in Centos 7.4 and Centos 6.9 w/ devtoolkit-6. In other words, GCC 6 plus intel compiler 2018.1. There is no crash using 2018.0. It works fine in -O0 but -O2 and -O3 crash.

#include <cstring>
#include <string>
#include <iostream>

std::string a() {
  return "xxxxxxxxxxxxxxxxxx";
}
std::string b() {
  return std::string("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") + std::string("x");
}
int main( int argc, char *argv[] ) {
  auto s = a() + b();
  printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
  return 0;
}

0 Kudos
9 Replies
Viet_H_Intel
Moderator
820 Views

Hi,

I dont have a CentOS 7.1 nor 6.9, so tried on RHEL 7.1 + GNU 6.1, but ran into compilation error.

Does your test case be compiled on other OSes? 

Thanks,

Viet 

0 Kudos
David_H_4
Beginner
820 Views

What is your complilation error? That is about as basic of a code example as is possible.

0 Kudos
Viet_H_Intel
Moderator
821 Views

 

I just copied your test case.

$ icpc test.cpp

test.cpp(12): error: no suitable conversion function from "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" to "int" exists

    auto s = a() + b();
             ^

test.cpp(13): error: expression must have class type
    printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
                             ^

test.cpp(13): error: expression must have class type
    printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
                                        ^

test.cpp(13): error: expression must have class type
    printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
                                                           ^

test.cpp(13): error: identifier "printf" is undefined
    printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
    ^

compilation aborted for test.cpp (code 2)
$ icpc -V
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.163 Build 20171018
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

 

0 Kudos
Viet_H_Intel
Moderator
821 Views

$ g++ test.cpp
test.cpp: In function âint main(int, char**)â:
test.cpp:12:8: error: âsâ does not name a type
   auto s = a() + b();
        ^
test.cpp:13:28: error: âsâ was not declared in this scope
   printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
                            ^
test.cpp:13:68: error: âprintfâ was not declared in this scope
   printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
                                                                    ^

0 Kudos
David_H_4
Beginner
821 Views

Could you please get someone who knows C++ to take a look at this please? This is not productive on so many levels.

This is all -std=c++14 code. Centos 7 and Centos6+devtoolkit6 are supported configurations in the release notes. 2018.0 works fine. 2018.1 is broken with optimization enabled, I don't know how to describe the problem in simpler terms. 

 

0 Kudos
Viet_H_Intel
Moderator
821 Views

 

Next time, please give us a completed command line of options.

I couldn't be able to reproduce it on RHEL 7.1. Let me find Centos 7 and try it there.

$ icpc -std=c++14 t.cpp && ./a.out

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 67, 67

$ icpc -std=c++14 t.cpp -O3&& ./a.out
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 67, 67
$ cat t.cpp
#include <cstring>
#include <string>
#include <iostream>

std::string a() {
  return "xxxxxxxxxxxxxxxxxx";
}
std::string b() {
  return std::string("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") + std::string("x");
}
int main( int argc, char *argv[] ) {
  auto s = a() + b();
  printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
  return 0;
}

$ icpc -V
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.163 Build 20171018

0 Kudos
Scott_S_1
Beginner
821 Views

Maybe I can simplify this a bit, using the following:

GCC 4 

[root@offtest4 ~]# icpc -v

icpc version 18.0.1 (gcc version 4.8.5 compatibility)

[root@offtest4 ~]# icpc -V
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.163 Build 20171018
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

[root@offtest4 ~]# cat teststring.cpp 
#include <string>

std::string a() {
  return "aaa";
}
std::string b() {
    return std::string("bbbbbbbb") + std::string("c");
/*  return std::string("bbbbbbb") + std::string("c"); */
}
int main( int argc, char *argv[] ) {
  std::string s = a() + b();
  return 0;
}


[root@offtest4 ~]# icpc teststring.cpp; ./a.out

<this one works fine>

GCC 6

[root@offtest4 ~]# scl enable devtoolset-6 bash

[root@offtest4 ~]# icpc -v
icpc version 18.0.1 (gcc version 6.2.1 compatibility)


[root@offtest4 ~]# icpc teststring.cpp; ./a.out
*** Error in `./a.out': double free or corruption (fasttop): 0x0000000001cac0a0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7c503)[0x7f7f84fed503]
./a.out[0x400f7d]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7f7f84f92b35]
./a.out[0x400be9]
======= Memory map: ========
00400000-00404000 r-xp 00000000 08:02 100944754                          /root/a.out
00603000-00604000 r--p 00003000 08:02 100944754                          /root/a.out
00604000-00605000 rw-p 00004000 08:02 100944754                          /root/a.out
01cac000-01ccd000 rw-p 00000000 00:00 0                                  [heap]
7f7f80000000-7f7f80021000 rw-p 00000000 00:00 0 
7f7f80021000-7f7f84000000 ---p 00000000 00:00 0 
7f7f84d6d000-7f7f84d6f000 r-xp 00000000 08:02 33561456                   /usr/lib64/libdl-2.17.so
7f7f84d6f000-7f7f84f6f000 ---p 00002000 08:02 33561456                   /usr/lib64/libdl-2.17.so
7f7f84f6f000-7f7f84f70000 r--p 00002000 08:02 33561456                   /usr/lib64/libdl-2.17.so
7f7f84f70000-7f7f84f71000 rw-p 00003000 08:02 33561456                   /usr/lib64/libdl-2.17.so
7f7f84f71000-7f7f85127000 r-xp 00000000 08:02 33561432                   /usr/lib64/libc-2.17.so
7f7f85127000-7f7f85327000 ---p 001b6000 08:02 33561432                   /usr/lib64/libc-2.17.so
7f7f85327000-7f7f8532b000 r--p 001b6000 08:02 33561432                   /usr/lib64/libc-2.17.so
7f7f8532b000-7f7f8532d000 rw-p 001ba000 08:02 33561432                   /usr/lib64/libc-2.17.so
7f7f8532d000-7f7f85332000 rw-p 00000000 00:00 0 
7f7f85332000-7f7f85347000 r-xp 00000000 08:02 33557016                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f7f85347000-7f7f85546000 ---p 00015000 08:02 33557016                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f7f85546000-7f7f85547000 r--p 00014000 08:02 33557016                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f7f85547000-7f7f85548000 rw-p 00015000 08:02 33557016                   /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7f7f85548000-7f7f85648000 r-xp 00000000 08:02 33561458                   /usr/lib64/libm-2.17.so
7f7f85648000-7f7f85848000 ---p 00100000 08:02 33561458                   /usr/lib64/libm-2.17.so
7f7f85848000-7f7f85849000 r--p 00100000 08:02 33561458                   /usr/lib64/libm-2.17.so
7f7f85849000-7f7f8584a000 rw-p 00101000 08:02 33561458                   /usr/lib64/libm-2.17.so
7f7f8584a000-7f7f85933000 r-xp 00000000 08:02 33561777                   /usr/lib64/libstdc++.so.6.0.19
7f7f85933000-7f7f85b33000 ---p 000e9000 08:02 33561777                   /usr/lib64/libstdc++.so.6.0.19
7f7f85b33000-7f7f85b3b000 r--p 000e9000 08:02 33561777                   /usr/lib64/libstdc++.so.6.0.19
7f7f85b3b000-7f7f85b3d000 rw-p 000f1000 08:02 33561777                   /usr/lib64/libstdc++.so.6.0.19
7f7f85b3d000-7f7f85b52000 rw-p 00000000 00:00 0 
7f7f85b52000-7f7f85b72000 r-xp 00000000 08:02 33561425                   /usr/lib64/ld-2.17.so
7f7f85d5e000-7f7f85d64000 rw-p 00000000 00:00 0 
7f7f85d6f000-7f7f85d71000 rw-p 00000000 00:00 0 
7f7f85d71000-7f7f85d72000 r--p 0001f000 08:02 33561425                   /usr/lib64/ld-2.17.so
7f7f85d72000-7f7f85d73000 rw-p 00020000 08:02 33561425                   /usr/lib64/ld-2.17.so
7f7f85d73000-7f7f85d74000 rw-p 00000000 00:00 0 
7ffd9dd27000-7ffd9dd49000 rw-p 00000000 00:00 0                          [stack]
7ffd9ddb6000-7ffd9ddb8000 r--p 00000000 00:00 0                          [vvar]
7ffd9ddb8000-7ffd9ddba000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted

0 Kudos
David_H_4
Beginner
821 Views

What does `gcc -v` say when you are running this test? -std=c++14 should not be a required command line arg if you are running w/ icpc 18 and gcc 6. I am not specifying a -std= param, and even if I do it crashes at runtime. Again, -O0 works fine. -O2/-O3 crash.

icpc test.cpp / icpc -O3 test.cpp

 

 

0 Kudos
Viet_H_Intel
Moderator
821 Views

 

I dont have an exact ENV as yours but found a CentOS 7.2 with GCC 6.3.

vahoang@orcsle150:/tmp$ cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

vahoang@orcsle150:/tmp$ gcc -v
..... 
gcc version 6.3.0 (GCC)


vahoang@orcsle150:/tmp$ rm a.out && icpc -std=c++14 t.cpp -O3 &&./a.out
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 67, 67
vahoang@orcsle150:/tmp$ rm a.out && icpc -std=c++14 t.cpp -O2 &&./a.out
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 67, 67

vahoang@orcsle150:/tmp$ rm a.out && icpc  t.cpp -O3 && ./a.out
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 67, 67
vahoang@orcsle150:/tmp$ rm a.out && icpc  t.cpp -O2 && ./a.out
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, 67, 67

 

vahoang@orcsle150:/tmp$ icpc -V
Intel(R) C++ Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 18.0.1.163 Build 20171018

0 Kudos
Reply