Can I using clang compile something with gcc headers all time?

I am now trying to implement the conversion of a gcc compilation command to a clang command, to generate a bc file for subsequent static analysis.

This conversion is no problem in most cases. However, in some cases, clang uses the same header files as gcc, but gcc compiles and clang doesn’t. What could be the reasons for an unsuccessful conversion?

Thanks!

I think you need to supply some more details. What exactly is happening and what did you expect to happen? Maybe post the command line and the error you see.

The raw gcc command:

c++ -pthread -std=c++0x -march=native -c src/densematrix.cc -o /root/progs/fastText-master/densematrix.o -c -c

The converted clang command:

clang -pthread -std=c++0x -march=native -c -x c++ /root/progs/fastText-master/src/densematrix.cc -o /root/progs/fastText-master/.piggy/bc/079849797f254e223cbde118eaa445b9.bc -c -c -isystem /usr/include/c++/9 -isystem /usr/include/x86_64-linux-gnu/c++/9 -isystem /usr/include/c++/9/backward -isystem /usr/lib/gcc/x86_64-linux-gnu/9/include -isystem /usr/local/include -isystem /usr/include/x86_64-linux-gnu -isystem /usr/include -g -fPIC -flto -fheinous-gnu-extensions -fno-inline-functions -mllvm -inline-threshold=0 -mllvm -inlinehint-threshold=0 -Wno-everything

The standard include search paths generated by echo "int main(){}" | c++ -E -v -x c++ - are showed below

#include <…> search starts here:
/usr/include/c++/9
/usr/include/x86_64-linux-gnu/c++/9
/usr/include/c++/9/backward
/usr/lib/gcc/x86_64-linux-gnu/9/include
/usr/local/include
/usr/include/x86_64-linux-gnu
/usr/include

I want to get the bitcode which is generated by clang, but the errors were occurred in compile time.

The error message:

Error message:
In file included from /root/progs/fastText-master/src/densematrix.cc:12:
In file included from /usr/include/c++/9/random:50:
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/opt_random.h:34:
In file included from /usr/lib/gcc/x86_64-linux-gnu/9/include/pmmintrin.h:31:
In file included from /usr/lib/gcc/x86_64-linux-gnu/9/include/emmintrin.h:31:
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:130:19: error: use of undeclared identifier ‘__builtin_ia32_addss’
return (__m128) __builtin_ia32_addss ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:136:19: error: use of undeclared identifier ‘__builtin_ia32_subss’
return (__m128) __builtin_ia32_subss ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:142:19: error: use of undeclared identifier ‘__builtin_ia32_mulss’
return (__m128) __builtin_ia32_mulss ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:148:19: error: use of undeclared identifier ‘__builtin_ia32_divss’; did you mean ‘__builtin_ia32_minss’?
return (__m128) __builtin_ia32_divss ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:142:19: note: ‘__builtin_ia32_minss’ declared here
return (__m128) __builtin_ia32_mulss ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:242:10: error: use of undeclared identifier ‘__builtin_ia32_andps’; did you mean ‘__builtin_ia32_haddps’?
return __builtin_ia32_andps (__A, __B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:242:10: note: ‘__builtin_ia32_haddps’ declared here
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:248:10: error: use of undeclared identifier ‘__builtin_ia32_andnps’
return __builtin_ia32_andnps (__A, __B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:254:10: error: use of undeclared identifier ‘__builtin_ia32_orps’
return __builtin_ia32_orps (__A, __B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:260:10: error: use of undeclared identifier ‘__builtin_ia32_xorps’
return __builtin_ia32_xorps (__A, __B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:288:19: error: use of undeclared identifier ‘__builtin_ia32_movss’
return (__m128) __builtin_ia32_movss ((__v4sf) __A,
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:298:19: error: use of undeclared identifier ‘__builtin_ia32_movss’
return (__m128) __builtin_ia32_movss ((__v4sf) __A,
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:326:19: error: use of undeclared identifier ‘__builtin_ia32_movss’
return (__m128) __builtin_ia32_movss ((__v4sf) __A,
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:336:19: error: use of undeclared identifier ‘__builtin_ia32_movss’
return (__m128) __builtin_ia32_movss ((__v4sf) __A,
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:380:19: error: use of undeclared identifier ‘__builtin_ia32_cmpgtps’; did you mean ‘__builtin_ia32_cmpltps’?
return (__m128) __builtin_ia32_cmpgtps ((__v4sf)__A, (__v4sf)__B);
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:368:19: note: ‘__builtin_ia32_cmpltps’ declared here
return (__m128) __builtin_ia32_cmpltps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:386:19: error: use of undeclared identifier ‘__builtin_ia32_cmpgeps’; did you mean ‘__builtin_ia32_cmpleps’?
return (__m128) __builtin_ia32_cmpgeps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:374:19: note: ‘__builtin_ia32_cmpleps’ declared here
return (__m128) __builtin_ia32_cmpleps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:410:19: error: use of undeclared identifier ‘__builtin_ia32_cmpngtps’; did you mean ‘__builtin_ia32_cmpnltps’?
return (__m128) __builtin_ia32_cmpngtps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:380:19: note: ‘__builtin_ia32_cmpnltps’ declared here
return (__m128) __builtin_ia32_cmpgtps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:416:19: error: use of undeclared identifier ‘__builtin_ia32_cmpngeps’; did you mean ‘__builtin_ia32_cmpnleps’?
return (__m128) __builtin_ia32_cmpngeps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:386:19: note: ‘__builtin_ia32_cmpnleps’ declared here
return (__m128) __builtin_ia32_cmpgeps ((__v4sf)__A, (__v4sf)__B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:602:19: error: use of undeclared identifier ‘__builtin_ia32_cvtsi2ss’; did you mean ‘__builtin_ia32_cvtsd2ss’?
return (__m128) __builtin_ia32_cvtsi2ss ((__v4sf) __A, __B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:602:19: note: ‘__builtin_ia32_cvtsd2ss’ declared here
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:602:58: error: cannot initialize a parameter of type ‘attribute((vector_size(2 * sizeof(double)))) double’ (vector of 2 ‘double’ values) with an lvalue of type ‘int’
return (__m128) __builtin_ia32_cvtsi2ss ((__v4sf) __A, __B);
^~~
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:618:19: error: use of undeclared identifier ‘__builtin_ia32_cvtsi642ss’; did you mean ‘__builtin_ia32_cvtsd2ss’?
return (__m128) __builtin_ia32_cvtsi642ss ((__v4sf) __A, __B);
^
/usr/lib/gcc/x86_64-linux-gnu/9/include/xmmintrin.h:602:19: note: ‘__builtin_ia32_cvtsd2ss’ declared here
return (__m128) __builtin_ia32_cvtsi2ss ((__v4sf) __A, __B);
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

clang information

clang version 14.0.0
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.5.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;at m64(repalce ‘at symbol’ by ‘at’)
Candidate multilib: 32;at m32
Candidate multilib: x32;at mx32
Selected multilib: .;at m64

Looking forward to your reply.

Sorry for the short reply here - but I am just replying from my phone.

I don’t think you can mix the intrinsic headers between compilers - they are highly tied with the compiler optimisations. So drop that directory and let clang use its own internal headers.

Thanks for your prompt reply! :smiling_face_with_three_hearts: