Closed Bug 778980 Opened 12 years ago Closed 12 years ago

Enable gcc -Werror=conversion-null for gcc >= 4.5

Categories

(Firefox Build System :: General, defect, P3)

All
Linux
defect

Tracking

(firefox17 wontfix, firefox18 fixed)

RESOLVED FIXED
mozilla18
Tracking Status
firefox17 --- wontfix
firefox18 --- fixed

People

(Reporter: cpeterson, Assigned: cpeterson)

References

(Blocks 1 open bug)

Details

Attachments

(5 files, 1 obsolete file)

To make gcc's NULL/nullptr warnings fatal like clang's nullptr errors, we may want to add -Werror=conversion-null to Linux's CFLAGS/CXXFLAGS for gcc >= 4.5. (The -Wconversion-null flag was new in gcc 4.5.)

If a developer overlooks these gcc warnings, then they may not realize their code change will break the OS X's clang build until they push to the tryserver. This a waste of developer time and tryserver resources.
For example, given the following code:

  char a = nullptr;
  int  b = nullptr;

* gcc 4.5 emits these warnings on Linux:

  warning: converting to non-pointer type 'char' from NULL
  warning: converting to non-pointer type 'int' from NULL

* clangs emits these nullptr errors on OS X:

  error: assigning to 'char' from incompatible type 'nullptr_t'
  error: assigning to 'int' from incompatible type 'nullptr_t'
OS: Mac OS X → Linux
Blocks: buildwarning
Component: MFBT → Build Config
hii i would like ot work on this .. can you tell me what shld i do...
hi Sadineni, this code change should be pretty straightforward. The most time-consuming part will be configuring the build and fixing any NULL warnings that become compile errors. The only Firefox platforms that use gcc today are Linux and Android.

gcc's -Wconversion-null flag is only available in recent versions of gcc, so you will need to add a "configure" check that tests for this compiler flag at build time. We would like gcc to treat these warnings as compile errors, so we need to add "-Werror=conversion-null" to our CXXFLAGS.

The "configure" check should be added to configure.in and js/src/configure.in. It will look something like this:

--- a/configure.in
+++ b/configure.in
@@ -1477,21 +1477,23 @@ if test "$GNU_CXX"; then
     # Turn on GNU-specific warnings:
     # -Wall - turn on a lot of warnings
     # -pedantic - this is turned on below
     # -Wpointer-arith - enabled with -pedantic, but good to have even if not
     # -Woverloaded-virtual - ???
     # -Werror=return-type - catches missing returns, zero false positives
     # -Wtype-limits - catches overflow bugs, few false positives
     # -Wempty-body - catches bugs, e.g. "if (c); foo();", few false positives
+    # -Werror=conversion-null - catches conversions between NULL and other types
     #
     _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wall -Wpointer-arith -Woverloaded-virtual"
     MOZ_CXX_SUPPORTS_WARNING(-W, error=return-type, ac_cxx_has_werror_return_type)
     MOZ_CXX_SUPPORTS_WARNING(-W, type-limits, ac_cxx_has_wtype_limits)
     MOZ_CXX_SUPPORTS_WARNING(-W, empty-body, ac_cxx_has_wempty_body)
+    MOZ_CXX_SUPPORTS_WARNING(-W, error=conversion-null, ac_cxx_has_werror_conversion_null)
 
     # Turn off the following warnings that -Wall/-pedantic turn on:
     # -Wno-ctor-dtor-privacy - ???
     # -Wno-overlength-strings - we exceed the minimum maximum length frequently 
     # -Wno-invalid-offsetof - we use offsetof on non-POD types frequently
     # -Wno-variadic-macros - ???
     #
     _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-ctor-dtor-privacy"
Sadineni, have you had a chance to look at this bug? If you have any questions, just let me know.
Assignee: nobody → cpeterson
Status: NEW → ASSIGNED
Priority: -- → P3
Hardware: x86 → All
Attached patch part-1-fix-gfx-warnings.patch (deleted) — Splinter Review
Part 1: Fix gcc -Wconversion-null warnings in gfx/gl

Fix some gcc warnings about NULL conversions that clang treats as errors.
Attachment #661418 - Flags: review?(joe)
Attached patch part-2-fix-js-warnings.patch (obsolete) (deleted) — Splinter Review
Part 2: Fix gcc -Wconversion-null warnings in js

Fix some gcc warnings about NULL conversions that clang treats as errors.
Attachment #661419 - Flags: review?(dmandelin)
Part 3: Fix gcc -Wconversion-null warnings in widget/android
Attachment #661421 - Flags: review?(blassey.bugs)
Part 4: Fix gcc -Wconversion-null warnings in ipc/chromium and toolkit/crashreporter

Fix some gcc warnings about NULL conversions that clang treats as errors.
Attachment #661422 - Flags: review?(benjamin)
Part 6: Treat gcc -Wconversion-null warnings as errors (like clang)

Here is a green try build:
https://tbpl.mozilla.org/?tree=Try&rev=cd2f6a06f90d
Attachment #661424 - Flags: review?(benjamin)
Comment on attachment 661419 [details] [diff] [review]
part-2-fix-js-warnings.patch

Review of attachment 661419 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/jsapi.h
@@ +3809,5 @@
>   */
>  #ifdef JS_GC_ZEAL
>  # define JS_SET_TRACING_LOCATION(trc, location)                               \
>      JS_BEGIN_MACRO                                                            \
> +        if (!(trc)->realLocation || (location) == NULL)                       \

What's this supposed to fix?
(In reply to :Ms2ger from comment #10)
> Comment on attachment 661419 [details] [diff] [review]
> part-2-fix-js-warnings.patch
> 
> Review of attachment 661419 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: js/src/jsapi.h
> @@ +3809,5 @@
> >   */
> >  #ifdef JS_GC_ZEAL
> >  # define JS_SET_TRACING_LOCATION(trc, location)                               \
> >      JS_BEGIN_MACRO                                                            \
> > +        if (!(trc)->realLocation || (location) == NULL)                       \
> 
> What's this supposed to fix?

The JS_SET_TRACING_LOCATION() macro had been called with a NULL constant and, after the macro was expanded, gcc -Wconversion-null did not like |!(NULL)|.

However, it looks like this change is no longer necessary because cset 8464ed98f78b introduced a new JS_UNSET_TRACING_LOCATION() macro to fix clang's NULL-to-bool warnings:

https://hg.mozilla.org/mozilla-central/rev/8464ed98f78b
Why are these patches using NULL instead of nullptr? I thought we standardized on nullptr.
(In reply to Benjamin Smedberg  [:bsmedberg] from comment #12)
> Why are these patches using NULL instead of nullptr? I thought we
> standardized on nullptr.

nsnulls had been replaced with nullptrs, but existing NULLs had not been replaced with nullptrs. In my patches that introduce NULLs, I was just following the existing coding style in each file.
Attached patch part-2-fix-js-warnings-v2.patch (deleted) — Splinter Review
Patch 2 v2 no longer changes JS_SET_TRACING_LOCATION() because cset 8464ed98f78b already fixed this issue for clang's NULL-to-bool warnings.
Attachment #661419 - Attachment is obsolete: true
Attachment #661419 - Flags: review?(dmandelin)
Attachment #661835 - Flags: review?(dmandelin)
Attachment #661421 - Flags: review?(blassey.bugs) → review+
Attachment #661418 - Flags: review?(joe) → review+
Attachment #661835 - Flags: review?(dmandelin) → review+
Comment on attachment 661422 [details] [diff] [review]
part-4-fix-ipc-and-toolkit-warnings.patch

r=me for the chromium bits. Please do not check in the google-breakpad bit: we import that directly from upstream and it needs to be fixed there.
Attachment #661422 - Flags: review?(benjamin) → review+
Attachment #661424 - Flags: review?(benjamin) → review+
(In reply to Benjamin Smedberg  [:bsmedberg] from comment #17)
> Comment on attachment 661422 [details] [diff] [review]
> part-4-fix-ipc-and-toolkit-warnings.patch
> 
> r=me for the chromium bits. Please do not check in the google-breakpad bit:
> we import that directly from upstream and it needs to be fixed there.

I just went to submit my google-breakpad fix upstream, but they have already fixed the warning in SVN r939. <:)

Bug 791775 tried to merge breakpad SVN r1044, but it was backed out. Once bug 791775 lands, I can land patch 5 (treat-warning-as-error).
Depends on: 791775
Landed patches 2 and 4a (patch 4 without breakpad change):
https://hg.mozilla.org/integration/mozilla-inbound/rev/224ba5e9fb70
https://hg.mozilla.org/integration/mozilla-inbound/rev/081b9207fe4e

Once breakpad bug 791775 lands, I can land patch 5 and close this bug.
https://hg.mozilla.org/mozilla-central/rev/cc505740ad56
Status: ASSIGNED → RESOLVED
Closed: 12 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla18
Does this break comm-central by itself or do we need to port it to c-c makefiles?
Depends on: 797316
(In reply to :aceman from comment #24)
> Does this break comm-central by itself or do we need to port it to c-c
> makefiles?

aceman, the configure.in change enables some gcc warnings-as-errors. comm-central shouldn't break if this patch is not applied, though changes merged from comm-central to mozilla-central may hit these new warnings-as-errors.
Blocks: 798789
Depends on: 798800
Part 5 of this seems to break compilation with clang on Mac for me.  I can't tell how our builders are managing to build, since I'm using the same clang revision.  :(
Following up on comment 26, for archeological purposes: Bug 798800 backed out part 5, reverting the "-Werror=conversion-null" in configure.in.

We still have -Werror=conversion-null in js/src/configure.in, though, FWIW. (That surprised me -- I thought we had a build-time check that those two configure.in files were identical in order to build, but apparently this section can differ without triggering that check.)
The configure.in files are not checked, they're very different. It's only the build/ and config/ dirs that are checked:
http://mxr.mozilla.org/mozilla-central/source/client.mk#418
Product: Core → Firefox Build System
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: