After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761170 - Warnings building with clang
Warnings building with clang
Status: RESOLVED OBSOLETE
Product: GIMP
Classification: Other
Component: General
git master
Other Linux
: Normal normal
: ---
Assigned To: GIMP Bugs
GIMP Bugs
Depends on:
Blocks:
 
 
Reported: 2016-01-27 11:17 UTC by Massimo
Modified: 2018-05-24 16:04 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix few clang warnings (5.67 KB, patch)
2017-07-14 11:34 UTC, Massimo
committed Details | Review

Description Massimo 2016-01-27 11:17:05 UTC
I've just run

$make -sC app CC=clang &>out.log

$clang -v
clang version 3.7.0 (tags/RELEASE_370/final)
Target: x86_64-redhat-linux-gnu
Thread model: posix
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.3.1
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/5.3.1
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-redhat-linux/5.3.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64

and there are few kind of warnings that might be better to silence:

-Wsometimes-uninitialized
example:
>gimpimage-new.c:349:10: warning: variable 'has_alpha' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]
>    case 3: base_type = GIMP_RGB;
>         ^
>gimpimage-new.c:374:68: note: uninitialized use occurs here
>                                                                   has_alpha),
>                                                                   ^~~~~~~~~


-Wtautological-constant-out-of-range-compare
comparisons of enum with -1 when -1 is not a valid enum value
are apparently evaluated at compile-time, possibly making them
useless, example:

>gimpcomponenteditor.c:619:33: warning: comparison of constant -1 with expression of type 'GimpChannelType' is always true [-Wtautological-constant-out-of-rang
>      editor->clicked_component != -1)
>      ~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~


-Wenum-conversion
example:
>gimpcursorview.c:492:38: warning: implicit conversion from enumeration type 'PangoStyle' to different enumeration type 'PangoAttrType' [-Wenum-conversion]
>  PangoAttrType attribute = italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL;
>                ~~~~~~~~~            ^~~~~~~~~~~~~~~~~~

That's easy to fix, just use a PangoStyle, it is a PangoStyle after all,
perhaps naming it 'style'


-Wabsolute-value
example:
>gimpsheartool.c:185:11: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
>      if (abs (diffx) > 5 || abs (diffy) > 5)
>          ^
>gimpsheartool.c:185:11: note: use function 'fabs' instead
>      if (abs (diffx) > 5 || abs (diffy) > 5)
>          ^~~
>          fabs

obviously it is also possible to use the macro ABS


-Warray-bounds
often refers to the inlined version of strcmp, but comparisons with 
the empty string (the warning message says index 1 is past the end 
of the array) could be changed to comparisons of the 
first char != (or ==) '\0'

example
>gimpsearchpopup.c:523:1845: warning: array index 1 is past the end of the array (which contains 1 element) [-Warray-bounds]
>  if (__extension__ ({ size_t __s1_len, __s2_len; (__builtin_constant_p (entry_text) && __builtin_constant_p ("") && (__s1_len = strlen (entry_text), __s2_len

 if (strcmp (entry_text, "") != 0)
 if (entry_text[0] != '\0')


-Wunused-const-variable
example:
>gimpmotionbuffer.c:85:25: warning: unused variable 'default_coords' [-Wunused-const-variable]
>static const GimpCoords default_coords = { 0.0, 0.0, 1.0, 0.0, 0.0, 0.5, 0.0, 0.0, 1.0, 1.0 };
>lebl-dialog.c:16:21: warning: unused variable 'goatpb2' [-Wunused-const-variable]
>static const guint8 goatpb2[];
>                    ^
>lebl-dialog.c:17:21: warning: unused variable 'goatpb' [-Wunused-const-variable]
>static const guint8 goatpb[];
>                    ^
>lebl-dialog.c:18:21: warning: unused variable 'wanda' [-Wunused-const-variable]
>static const guint8 wanda[];


-Wtautological-compare
enums probably default to unsigned if they do not have any negative values
example:
>gradient-editor-commands.c:123:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare]
>      color_type >= 0 &&
>      ~~~~~~~~~~ ^  ~
>gradient-editor-commands.c:277:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare]
>      color_type >= 0 &&
>      ~~~~~~~~~~ ^  ~
Comment 1 Massimo 2016-01-28 11:51:10 UTC
(In reply to Massimo from comment #0)
> I've just run
> 
> $make -sC app CC=clang &>out.log
> 
> 
...
> 
> -Wtautological-constant-out-of-range-compare
> comparisons of enum with -1 when -1 is not a valid enum value
> are apparently evaluated at compile-time, possibly making them
> useless, example:
> 
> 
...
> 
> -Wtautological-compare
> enums probably default to unsigned if they do not have any negative values
> example:
> >gradient-editor-commands.c:123:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare]
> >      color_type >= 0 &&
> >      ~~~~~~~~~~ ^  ~
> >gradient-editor-commands.c:277:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare]
> >      color_type >= 0 &&
> >      ~~~~~~~~~~ ^  ~

Investigating -Wtautological-constant-out-of-range-compare
and -Wtautological-compare warnings I compiled the following
program:

#include <stdio.h>

enum Enum { A, B, C };

int
main (void)
{
  enum Enum e = -1;

  printf (e >=  0 ? "-1 >= 0\n" : "-1 < 0\n");
  printf (e != -1 ? "-1 != -1\n" : "-1 == -1\n");

  return 0;
}

with different compiler flags -O0 -O2 -O3 -Os -Ofast.

The first test (-1 >= 0) is always true, the second test (-1 != -1)
is true (as the compiler warning suggests) only using -fshort-enums
(gcc and clang)

'$ info gcc' in section 4.9 says -fshort-enums is the default for
some targets whose ABI requires it.

This means GIMP code is not portable to those target platforms,
assuming that the observed behaviour without -fshort-enums is
the intended behaviour
Comment 2 Michael Natterer 2016-02-12 21:47:39 UTC
I don't think it's worth the effort, we use -1 as "none of these values"
all over the place. GIMP would pretty much fall apart if that didn't work.
What platforms are these?
Comment 3 Michael Natterer 2016-02-12 21:49:49 UTC
I think I looked at all those warnings now and they all compare
"foo == -1", never <= or =>, unless I missed one.
Comment 4 Michael Natterer 2016-02-12 21:52:04 UTC
Fixed most other warnings I found:

commit f2d581a53639bef26227edcd21925bf228b0162a
Author: Michael Natterer <mitch@gimp.org>
Date:   Fri Feb 12 22:48:59 2016 +0100

    Bug 761170 - Warnings building with clang
    
    Fix a bunch of clang warnings.

 app/core/gimpcontext.c         | 16 ++++++++++++----
 app/core/gimpimage-new.c       |  2 +-
 app/dialogs/lebl-dialog.c      |  4 ----
 app/display/gimpcursorview.c   |  2 +-
 app/tools/gimpcagetool.c       | 14 +++++++-------
 app/tools/gimpsheartool.c      |  4 ++--
 libgimpbase/gimpenv.c          |  2 +-
 libgimpwidgets/gimpruler.c     |  2 +-
 modules/color-selector-water.c |  5 -----
 9 files changed, 25 insertions(+), 26 deletions(-)
Comment 5 Massimo 2016-02-13 05:33:49 UTC
(In reply to Michael Natterer from comment #3)
> I think I looked at all those warnings now and they all compare
> "foo == -1", never <= or =>, unless I missed one.

(In reply to Massimo from comment #1)
> ...
> > 
> > -Wtautological-compare
> > enums probably default to unsigned if they do not have any negative values
> > example:
> > >gradient-editor-commands.c:123:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare]
> > >      color_type >= 0 &&
> > >      ~~~~~~~~~~ ^  ~
> > >gradient-editor-commands.c:277:18: warning: comparison of unsigned enum expression >= 0 is always true [-Wtautological-compare]
> > >      color_type >= 0 &&
> > >      ~~~~~~~~~~ ^  ~

Only these two:

https://git.gnome.org/browse/gimp/tree/app/actions/gradient-editor-commands.c#n123

they're useless, if gtk_radio_action_get_current_value ever returns
< 0 that expression is true.
Comment 6 Massimo 2016-02-13 05:45:52 UTC
(In reply to Michael Natterer from comment #2)
> I don't think it's worth the effort, we use -1 as "none of these values"
> all over the place. GIMP would pretty much fall apart if that didn't work.
> What platforms are these?

I had the gimp tree configured for gcc, but passed CC=clang
to make.

There are 2 cases that could be refactored to avoid the warnings

https://git.gnome.org/browse/gimp/tree/app/display/gimpimagewindow.c#n868

this basically inlines two g_list_find calls, but two early return
would do the same without the need of the side != -1 check in the
loop condition.

here:

https://git.gnome.org/browse/gimp/tree/app/tools/gimpfreeselecttool.c#n1456

handle_type could be initialized only when used

something like

if (dist <= MAX ({GRAB,SHOW}_THRESHOLD))
  {
     handle_type = ? : ;
Comment 7 Massimo 2017-07-14 07:17:38 UTC
Probably since a few days, GIMP fails to build with clang, it stops at:

>  CC       metadata-impexp.o
>  CC       metadata-xml.o
>In file included from metadata-impexp.c:40:
>./metadata-tags.h:223:27: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
>static const metadata_tag const equivalent_metadata_tags[] =
>                          ^
>1 warning generated.
>In file included from metadata-editor.c:38:
>./metadata-tags.h:223:27: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
>static const metadata_tag const equivalent_metadata_tags[] =
>                          ^
>metadata-editor.c:5266:43: error: invalid suffix 'd' on floating constant
>                alt_d = (alt_d * 12 * 2.54d) / 100;
>                                          ^
>metadata-editor.c:5719:38: error: invalid suffix 'd' on floating constant
>          alt_d = (alt_d * (12 * 2.54d)) / 100;
>                                     ^
>metadata-editor.c:5731:31: error: invalid suffix 'd' on floating constant
>          alt_d = alt_d * 3.28d;
>                              ^
>1 warning and 3 errors generated.
>make[3]: *** [Makefile:765: metadata-editor.o] Error 1

$ git describe
GIMP_2_9_4-1716-ga223ba8f40
Comment 8 Michael Natterer 2017-07-14 10:27:34 UTC
Thanks, fixed those, does it now build again?

commit d315cc1034158cae0d12d9e81557babc550df160
Author: Michael Natterer <mitch@gimp.org>
Date:   Fri Jul 14 12:26:10 2017 +0200

    Bug 761170 - Warnings building with clang
    
    Fix clang warnings along with some other minor stuff, no logic changes.

 plug-ins/metadata/metadata-editor.c |  6 +++---
 plug-ins/metadata/metadata-impexp.c | 10 ++++++++--
 plug-ins/metadata/metadata-tags.h   |  2 +-
 plug-ins/metadata/metadata-xml.c    | 25 +++++++++----------------
 plug-ins/metadata/metadata-xml.h    |  2 +-
 5 files changed, 22 insertions(+), 23 deletions(-)
Comment 9 Michael Natterer 2017-07-14 10:28:59 UTC
Can you perhaps prepare a patch for the other warnings you see?
Comment 10 Massimo 2017-07-14 11:34:29 UTC
Created attachment 355588 [details] [review]
fix few clang warnings

> Can you perhaps prepare a patch for the other warnings you see?


The attached patch should fix the easy ones:


>gimppluginmanager-restore.c:287:44: warning: implicit conversion from enumeration type 'GFileCreateFlags' to different enumeration type 'GFileQueryInfoFlags' [-Wenum-conversion]
>                                           G_FILE_CREATE_NONE,
>                                           ^~~~~~~~~~~~~~~~~~
>1 warning generated.

>gimpcolorprofile.c:855:32: warning: suggest braces around initialization of subobject [-Wmissing-braces]
>  GimpMatrix3       matrix = { 0, };
>                               ^
>                               {}
>gimpcolorprofile.c:855:32: warning: suggest braces around initialization of subobject [-Wmissing-braces]
>  GimpMatrix3       matrix = { 0, };
>                               ^
>                               {}
>2 warnings generated.

>gimpcolorspace.c:1044:18: warning: explicitly assigning value of variable of type 'gdouble' (aka 'double') to itself [-Wself-assign]
>      value      = value; 
>      ~~~~~      ^ ~~~~~
>1 warning generated.

>border-average.c:171:11: warning: variable 'result_color' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>      if (gimp_drawable_is_rgb (drawable_id))
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>border-average.c:200:28: note: uninitialized use occurs here
>  values[1].data.d_color = result_color;
>                           ^~~~~~~~~~~~
>border-average.c:171:7: note: remove the 'if' if its condition is always true
>      if (gimp_drawable_is_rgb (drawable_id)) 
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
>border-average.c:168:7: warning: variable 'result_color' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
>  if (status == GIMP_PDB_SUCCESS)
>      ^~~~~~~~~~~~~~~~~~~~~~~~~~
>border-average.c:200:28: note: uninitialized use occurs here
>  values[1].data.d_color = result_color;
>                           ^~~~~~~~~~~~
>border-average.c:168:3: note: remove the 'if' if its condition is always true
>  if (status == GIMP_PDB_SUCCESS)
>  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>border-average.c:124:3: note: variable 'result_color' is declared here
>  GimpRGB            result_color;
>  ^
>2 warnings generated.

>file-raw-data.c:1071:33: warning: implicit conversion from enumeration type 'GimpImageBaseType' to different enumeration type 'GimpImageType' [-Wenum-conversion]
>  GimpImageType      ltype    = GIMP_RGB;
>                     ~~~~~      ^~~~~~~~
>file-raw-data.c:1072:33: warning: implicit conversion from enumeration type 'GimpImageType' to different enumeration type 'GimpImageBaseType' [-Wenum-conversion]
>  GimpImageBaseType  itype    = GIMP_RGB_IMAGE;
>                     ~~~~~      ^~~~~~~~~~~~~~
>2 warnings generated.

>hot.c:360:57: warning: passing 'guint *' (aka 'unsigned int *') to parameter of type 'gint *' (aka 'int *') converts between pointers to integer types with different sign [-Wpointer-sign]
>                                      &sel_x1, &sel_y1, &width, &height))
>                                                        ^~~~~~
>../../libgimp/gimpdrawable_pdb.h:59:88: note: passing argument to parameter 'width' here
>                                                           gint                       *width,
>                                                                                       ^
>hot.c:360:65: warning: passing 'guint *' (aka 'unsigned int *') to parameter of type 'gint *' (aka 'int *') converts between pointers to integer types with different sign [-Wpointer-sign]
>                                      &sel_x1, &sel_y1, &width, &height))
>                                                                ^~~~~~~
>../../libgimp/gimpdrawable_pdb.h:60:88: note: passing argument to parameter 'height' here
>                                                           gint                       *height);
>                                                                                       ^

>mail.c:378:17: warning: address of array 'mail_info.subject' will always evaluate to 'true' [-Wpointer-bool-conversion]
>  if (mail_info.subject &&
>      ~~~~~~~~~~^~~~~~~ ~~
>mail.c:384:17: warning: address of array 'mail_info.comment' will always evaluate to 'true' [-Wpointer-bool-conversion]
>  if (mail_info.comment &&
>      ~~~~~~~~~~^~~~~~~ ~~
>mail.c:390:17: warning: address of array 'mail_info.receipt' will always evaluate to 'true' [-Wpointer-bool-conversion]
>  if (mail_info.receipt &&
>      ~~~~~~~~~~^~~~~~~ ~~
>3 warnings generated.

>gfig-dialog.c:1904:34: warning: implicit conversion from enumeration type 'FillType' to different enumeration type 'GimpBucketFillMode' [-Wenum-conversion]
>  GimpBucketFillMode fill_mode = FILL_NONE;
>                     ~~~~~~~~~   ^~~~~~~~~
>1 warning generated.

>scheme-wrapper.c:81:28: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
>static const NamedConstant const script_constants[] =
>                           ^
Comment 11 Massimo 2017-07-14 11:36:33 UTC
(In reply to Michael Natterer from comment #8)
> Thanks, fixed those, does it now build again?
> 

Yes, thank you.
Comment 12 Michael Natterer 2017-07-15 19:07:05 UTC
Comment on attachment 355588 [details] [review]
fix few clang warnings

Thanks, pushed to master:

commit f2306abc0a9c6d3c40d0409375e7e03992b58eb7
Author: Massimo Valentini <mvalentini@src.gnome.org>
Date:   Fri Jul 14 13:10:46 2017 +0200

    Bug 761170: Warnings building with clang
    
    Fix some of the warnings.

 app/plug-in/gimppluginmanager-restore.c | 2 +-
 libgimpcolor/gimpcolorprofile.c         | 2 +-
 libgimpcolor/gimpcolorspace.c           | 2 +-
 plug-ins/common/border-average.c        | 2 +-
 plug-ins/common/file-raw-data.c         | 4 ++--
 plug-ins/common/hot.c                   | 2 +-
 plug-ins/common/mail.c                  | 9 +++------
 plug-ins/gfig/gfig-dialog.c             | 2 +-
 plug-ins/script-fu/scheme-wrapper.c     | 2 +-
 9 files changed, 12 insertions(+), 15 deletions(-)
Comment 13 Massimo 2017-12-01 06:48:19 UTC
Clang doesn't build GIMP tree on linux. It stops with:

>   CC       gimpintcombobox.lo
> gimpintcombobox.c:703:1: error: conflicting types for 'gimp_int_combo_box_get_layout'
> gimp_int_combo_box_get_layout (GimpIntComboBox *combo_box)
> ^
> ./gimpintcombobox.h:107:15: note: previous declaration is here
>               gimp_int_combo_box_get_layout      (GimpIntComboBox       *combo_box);
>               ^
> 1 error generated.


The problem is in this commit:

https://git.gnome.org/browse/gimp/commit/?id=47ac6111de4fb77645be257fc4c6820d3ad6cb9c

the declaration with a const on the return value:

+const GimpIntComboBoxLayout
+              gimp_int_combo_box_get_layout      (GimpIntComboBox       *combo_box);
+

and the definition without

+ * Since: 2.10
+ **/
+GimpIntComboBoxLayout
+gimp_int_combo_box_get_layout (GimpIntComboBox *combo_box)
+{

removing the const fixes the build
Comment 14 Ell 2017-12-01 10:14:15 UTC
Thanks.  Fixed in master:

commit 8e51e7c35195c798c1fbecb010d6d5a5be72c9e0
Author: Ell <ell_se@yahoo.com>
Date:   Fri Dec 1 05:11:11 2017 -0500

    libgimpwidgets: fix return type of gimp_int_combo_box_get_layout()
    
    ... and a small cleanup.

 libgimpwidgets/gimpintcombobox.c | 3 ++-
 libgimpwidgets/gimpintcombobox.h | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
Comment 15 GNOME Infrastructure Team 2018-05-24 16:04:45 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to GNOME's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/gimp/issues/835.