GNOME Bugzilla – Bug 775112
clang compiler warnings due to integer conversions
Last modified: 2017-11-13 14:32:12 UTC
By default the git code of the gstreamer modules enables -Werror, so all compiler warnings are fatal. Compiling with clang causes several compiler warnings related to integer casts: tmp-orc.c:931:13: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var36 = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:1504:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:1505:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:2128:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:2129:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:2563:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:2564:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:2794:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:2795:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:3236:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:3237:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var37.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:3474:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var38.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:3475:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var38.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:3895:13: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var36 = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:4241:13: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var33 = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:4243:15: error: implicit conversion from 'int' to 'orc_int16' (aka 'short') changes value from 32896 to -32640 [-Werror,-Wconstant-conversion] var35.i = (int)0x00008080; /* 32896 or 1.62528e-319f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:5252:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var36.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:5253:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var36.x2[1] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~ tmp-orc.c:5639:19: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var36.x2[0] = (int)0x000000ff; /* 255 or 1.25987e-321f */ ~ ^~~~~~~~~~~~~~~
That should still be doing what is intended, but we should fix orc to generate code for this properly
Created attachment 340787 [details] [review] orc: Explicitly define unsigned integer literals as unsigned And cast constant loads to their correct target type instead of int. clang complains about such implicit conversions in the latest version: error: implicit conversion from 'int' to 'orc_int8' (aka 'signed char') changes value from 255 to -1 [-Werror,-Wconstant-conversion] var36 = (int)0x000000ff; /* 255 or 1.25987e-321f */
Comment on attachment 340787 [details] [review] orc: Explicitly define unsigned integer literals as unsigned This fixes the compiler warnings but breaks the tests, also with gcc this time (with clang they are broken anyway, orc does not work with clang, see bug #728129, bug #728738). The C backend should really be cleaned up for this, with clang becoming more common and compilers becoming more irrational with regard to undefined behaviour. The simplest way to solve this seems to be to rewrite all the generated code so that each variable and constant has an explicit cast to the expected type first (which we know anyway). And then we can start fixing up implementations that now fail.
Just rebuild orc with clang ... and it doesn't seem to fail anymore. Can someone else confirm ?
Works here with clang 3.9.1 (also the tests succeed now). Will try with a newer version later.
I just tried to build the gstreamer module from git and it fails with a different error regarding linking, so I can't re-test this right now: make[4]: Entering directory '/mnt/ram/gstreamer/gst' GEN Gst-1.0.gir g-ir-scanner: link: /bin/sh ../libtool --mode=link --tag=CC clang -o /mnt/ram/gstreamer/gst/tmp-introspectzxs68ceb/Gst-1.0 -export-dynamic -g -O2 tmp-introspectzxs68ceb/mnt/ram/gstreamer/gst/tmp-introspectzxs68ceb/Gst-1.0.o -L. libgstreamer-1.0.la -lgio-2.0 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lgobject-2.0 -lgmodule-2.0 -pthread -lglib-2.0 libtool: link: clang -o /mnt/ram/gstreamer/gst/tmp-introspectzxs68ceb/.libs/Gst-1.0 -g -O2 tmp-introspectzxs68ceb/mnt/ram/gstreamer/gst/tmp-introspectzxs68ceb/Gst-1.0.o -Wl,--export-dynamic -pthread -pthread -L. ./.libs/libgstreamer-1.0.so /usr/lib64/libunwind.so -lc -lgcc_s -ldw -lelf -lm -lrt -ldl -lgio-2.0 -lgobject-2.0 -lgmodule-2.0 -lglib-2.0 -pthread clang-5.0: error: no such file or directory: './.libs/libgstreamer-1.0.so' linking of temporary binary failed: Command '['/bin/sh', '../libtool', '--mode=link', '--tag=CC', 'clang', '-o', '/mnt/ram/gstreamer/gst/tmp-introspectzxs68ceb/Gst-1.0', '-export-dynamic', '-g', '-O2', 'tmp-introspectzxs68ceb/mnt/ram/gstreamer/gst/tmp-introspectzxs68ceb/Gst-1.0.o', '-L.', 'libgstreamer-1.0.la', '-lgio-2.0', '-Wl,--export-dynamic', '-lgmodule-2.0', '-pthread', '-lgobject-2.0', '-lgmodule-2.0', '-pthread', '-lglib-2.0']' returned non-zero exit status 1
(In reply to Sebastian Dröge (slomo) from comment #5) > Works here with clang 3.9.1 (also the tests succeed now). Will try with a > newer version later. Cool ! (In reply to Hanno Boeck from comment #6) > I just tried to build the gstreamer module from git and it fails with a > different error regarding linking, so I can't re-test this right now: > Hanno, this looks like it's a completely different error. Ok to open a new bug report for that ?
Hanno's error is because he configured with CC=clang-5.0 but there is no clang-5.0 available on his system anymore. No bug there. Before closing this, someone should try with clang 5.0 or newer, I'll do so later today if nobody else is faster.
Just did a full orc+gst* build with clang-5. Closing. Hanno, if you still see issues, please open a new bug report, thanks.