Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Sujit_S_
Beginner
419 Views

warning #69: integer conversion resulted in truncatio

Getting a warning with icpc (icpc (ICC) 15.0.3 20150407)

/n/dv/src/icc/releases/bin/icpc -std=c++14 -m32 -lstdc++ test.cc
test.cc(7): warning #69: integer conversion resulted in truncation
    test = (std::bitset<128> (0x0123456789abcdefULL << 36));

#include<iostream>
#include<bitset>

int main()
{
  std::bitset<128> test;
  test = (std::bitset<128> (0x0123456789abcdefULL << 36));
  std::cout<<test;
  std::bitset<128> value = (std::bitset<128>(0x1234567890123456) << 64) | std::bitset<128>(0x1234567890123456);
  std::cout<<value;
}

but g++ works

/n/sw/gen/gcc/x86-64/gcc-4.9.2/bin/g++ -std=c++14 -m32 test.cc

a.out
0000000000000000000000000000000000000000000000000000000000000000100110101011110011011110111100000000000000000000000000000000000000010010001101000101011001111000100100000001001000110100010101100001001000110100010101100111100010010000000100100011010001010110

 

any help will be apprecitated.

 

 

 

 

 

0 Kudos
9 Replies
Kittur_G_Intel
Employee
419 Views

Hi Sujit,
I tried with the version of icpc you're using (15.0.3) and later versions including the latest 16.0 Update 1 version as well but couldn't reproduce the issue. I don't see any warning output and behaves similar to gcc.    

1) Which OS you're running the test on? 
2)  Download the latest 16.0 update 1 version released recently from the Intel Registration Center and try it out? 
3) If you still get the warning after the above, can you attach the pre-processed file (.i suffix)  to this issue so I can try that out? To generate the file, you can use -P option when compiling the test case.

_Kittur

 

Sujit_S_
Beginner
419 Views

Hi Kittur,

Thanks for your reply.

1)  I am running on Scientific Linux release 6.6 (Carbon)

$ uname -a
Linux b-111-43.centtech.com 2.6.32-431.29.2.el6.x86_64 #1 SMP Tue Sep 9 13:45:55 CDT 2014 x86_64 x86_64 x86_64 GNU/Linux

$ lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch
Distributor ID:    Scientific
Description:    Scientific Linux release 6.6 (Carbon)
Release:    6.6
Codename:    Carbon

2) I am attaching the pre-preocessed file (run on 15.0.3 version)

a.out
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100100000001001000110100010101100000000000000000000000000000000010010000000100100011010001010110

Thanks,

Sujit

Kittur_G_Intel
Employee
419 Views

Thanks Sujit, yes I could reproduce with icpc and when using the test.i file.  BTW, can you also attach the source file to the issue? Also, which g++ version did you use?  

I"ll file the issue with the product team and will keep you updated accordingly, appreciate much.

_Kittur 

419 Views

Hi Kittur/Sujit,

Some hints on this issue. (First of all, with Sujit's preprocessed test.i, yes, I can reproduce too...)

The issue seems related to C++11 and 32bit mode only (in 64bit mode, there is no overflow), and the issue will not work with g++ without C++11 mode. Let me show it as below:

$ source /opt/gcc/gcc-4.7.0/bin/gccvars.sh
$ g++ temp.cpp  -m32  -std=c++11
$ g++ temp.cpp  -m32
temp.cpp: In function 'int main()':
temp.cpp:7:56: warning: large integer implicitly truncated to unsigned type [-Woverflow]
temp.cpp:9:64: warning: large integer implicitly truncated to unsigned type [-Woverflow]
temp.cpp:9:110: warning: large integer implicitly truncated to unsigned type [-Woverflow]
$ icpc temp.cpp -m32
temp.cpp(7): warning #69: integer conversion resulted in truncation
    test = (std::bitset<128> (0x0123456789abcdefULL << 36));
                              ^

temp.cpp(9): warning #69: integer conversion resulted in truncation
    std::bitset<128> value = (std::bitset<128>(0x1234567890123456) << 64) | std::bitset<128>(0x1234567890123456);
                                               ^

temp.cpp(9): warning #69: integer conversion resulted in truncation
    std::bitset<128> value = (std::bitset<128>(0x1234567890123456) << 64) | std::bitset<128>(0x1234567890123456);
                                                                                             ^

$ icpc temp.cpp -m32 -std=c++11
$ ./a.out
0000000000000000000000000000000000000000000000000000000000000000100110101011110011011110111100000000000000000000000000000000000000010010001101000101011001111000100100000001001000110100010101100001001000110100010101100111100010010000000100100011010001010110$

From above, you can see that ICC and G++ behaviour totally same, it will BOTH have warning without std=c++11, which is expected as there are some overflow there.

This gives me some hints, in Sujit's issue description, he invoke ICC and G++ using absolute path (like /xxx/xxx/icc, /xxx/xxx/g++, which is g++4.9.2). Please do not forget that ICC depends on G++ to work well, in this case, /xxx/xxx/icc may invoke another version of G++ (system default g++ usually) which may be old and does not support some C++11 feature (Note: for ICC to support C++11 features, if the feature is syntax related, it may be independent with g++, but if it is header related, it will be dependent with g++ headers it picked up! I have no experience on "Scientific Linux release 6.6", but I guess the system default g++ may be very old and does not support the bitset C++11 feature and causing ICC to fail. I think you can invoke your system default g++ to double check (which should also fail!). I can simulate the case as below:

$ source /opt/gcc/gcc-4.1.2/bin/gccvar.sh
$ icpc temp.cpp -m32 -std=c++11
temp.cpp(7): warning #69: integer conversion resulted in truncation
    test = (std::bitset<128> (0x0123456789abcdefULL << 36));
                              ^

temp.cpp(9): warning #69: integer conversion resulted in truncation
    std::bitset<128> value = (std::bitset<128>(0x1234567890123456) << 64) | std::bitset<128>(0x1234567890123456);
                                               ^

temp.cpp(9): warning #69: integer conversion resulted in truncation
    std::bitset<128> value = (std::bitset<128>(0x1234567890123456) << 64) | std::bitset<128>(0x1234567890123456);
                                                                                             ^

$ g++ temp.cpp -m32 -std=c++11
cc1plus: error: unrecognized command line option "-std=c++11"
$

(My g++ is really old and it does not even support -std=c++11 option, in this case, ICC will fail of course as the header of bitset is old and C++11 does not take effect for it). I suspect this is the case Sujit has...

Summary: make sure correct g++ is picked up (check with "icpc -v"), if using ICC with very old g++ which does not support this C++11 feature for bitset, you'll have the issue.

Solution: set your g++ 4.9.2 in the PATH and icc will pick it up. Below is a reference of my source script to switch to g++ 4.9.0:

$ cat /opt/gcc/gcc-4.9.0/bin/gccvars.sh
export NGCCDIR=/opt/gcc/gcc-4.9.0
export PATH=$NGCCDIR/bin:$PATH
export LD_LIBRARY_PATH=$NGCCDIR/lib:$NGCCDIR/lib64:$LD_LIBRARY_PATH
export MANPATH=$NGCCDIR/share/man:$MANPATH

Hope it is clear and helps.

Thanks,

Shenghong

419 Views

Searched on Internet about this SL linux gcc...it seems it has devtoolset which has g++4.7.2 as default?

http://linux.web.cern.ch/linux/devtoolset/

g++4.7.2 should support this C++11 feature also. I have no experience on this SL Linux distribution, not sure which version of gcc it has as default. Whatever, please still read my last reply and check in your environment (when you compare with g++, invoke g++ directly (without absolute path), as icpc will only pick up g++ command line in your current PATH environment only). If you are not sure, just run below commands and paste the terminal output here:

g++ -std=c++14 -m32 -lstdc++ test.cc
g++ -v

Thanks,

Shenghong

Kittur_G_Intel
Employee
419 Views

HI Shenghong,
Yes, I agree I did the same thing as you suggested and could reproduce your findings per your previous post suggestions as well. Your suggestion to Sujit makes sense,  thanks.

Hi Sujit,
Please read the detailed post by Shenghong earlier and try out accordingly (ensuring you have the right g++ version) and let us know, thanks

_Kittur

Kittur_G_Intel
Employee
419 Views

@Sujit:  I verified again on our systems ensuring correct version of g++ that supported the c11 feature and it works fine with both icc and gcc.  So, it appears that what Shenghong pointed out earlier is what's causing icpc to output the warnings while gcc didn't.  Please confirm and let me know, appreciate much.

_Kittur

Sujit_S_
Beginner
419 Views

HI Shenghong, Kittur.

Thanks a lot. That solved the issue. Very much appreciate.

- Sujit

 

 

 

Kittur_G_Intel
Employee
419 Views

Great to hear Sujit, thanks for the confirmation and your patience through this much appreciated.

_Kittur