diff mbox series

mk: use misleading indentation warning when available

Message ID 20181218102643.4332-1-gaetan.rivet@6wind.com (mailing list archive)
State Rejected, archived
Delegated to: Thomas Monjalon
Headers show
Series mk: use misleading indentation warning when available | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Gaëtan Rivet Dec. 18, 2018, 10:26 a.m. UTC
-Wmisleading-indentation was introduced in GCC 6.0.

Use it at least when available. This should catch most common
error of the types (due to the codebase being properly tabbed),
but will still miss patterns such as

    if (!condition)
    	// commented_fn_call();
    do_stuff();

Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
---

I completely agree that we should change the coding style and force
all if()s to have brackets.

In the meantime, this patch might help alleviate the issue.

 mk/toolchain/gcc/rte.vars.mk | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Ferruh Yigit Dec. 18, 2018, 2:50 p.m. UTC | #1
On 12/18/2018 10:26 AM, Gaetan Rivet wrote:
> -Wmisleading-indentation was introduced in GCC 6.0.

It seems '-Wmisleading-indentation' is part of -Wall, which we already set by
default. If so no need to explicitly add it.

The link I found:
https://www.gnu.org/software/gcc/gcc-6/porting_to.html

copy-paste:
"
A new warning -Wmisleading-indentation was added to -Wall, warning about places
where the indentation of the code might mislead a human reader about the control
flow:
"

Is there a way to confirm it is part of -Wall?

> 
> Use it at least when available. This should catch most common
> error of the types (due to the codebase being properly tabbed),
> but will still miss patterns such as
> 
>     if (!condition)
>     	// commented_fn_call();
>     do_stuff();
> 
> Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> ---
> 
> I completely agree that we should change the coding style and force
> all if()s to have brackets.
> 
> In the meantime, this patch might help alleviate the issue.
> 
>  mk/toolchain/gcc/rte.vars.mk | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk
> index d8b99faf6..2c9bde1d5 100644
> --- a/mk/toolchain/gcc/rte.vars.mk
> +++ b/mk/toolchain/gcc/rte.vars.mk
> @@ -87,5 +87,9 @@ WERROR_FLAGS += -Wimplicit-fallthrough=2
>  WERROR_FLAGS += -Wno-format-truncation
>  endif
>  
> +ifeq ($(shell test $(GCC_VERSION) -gt 60 && echo 1), 1)
> +WERROR_FLAGS += -Wmisleading-indentation
> +endif
> +
>  export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
>  export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
>
Gaëtan Rivet Dec. 19, 2018, 9:24 a.m. UTC | #2
On Tue, Dec 18, 2018 at 02:50:30PM +0000, Ferruh Yigit wrote:
> On 12/18/2018 10:26 AM, Gaetan Rivet wrote:
> > -Wmisleading-indentation was introduced in GCC 6.0.
> 
> It seems '-Wmisleading-indentation' is part of -Wall, which we already set by
> default. If so no need to explicitly add it.
> 
> The link I found:
> https://www.gnu.org/software/gcc/gcc-6/porting_to.html
> 
> copy-paste:
> "
> A new warning -Wmisleading-indentation was added to -Wall, warning about places
> where the indentation of the code might mislead a human reader about the control
> flow:
> "
> 
> Is there a way to confirm it is part of -Wall?
> 

I think you are right, actually the check was already used.
This is worrying, given that the original bug was not seen.

This patch can be left out then, but the problem remains. Maybe an
update to coding style is needed, or an evolution to checkpatch //
preferably something else.

> > 
> > Use it at least when available. This should catch most common
> > error of the types (due to the codebase being properly tabbed),
> > but will still miss patterns such as
> > 
> >     if (!condition)
> >     	// commented_fn_call();
> >     do_stuff();
> > 
> > Signed-off-by: Gaetan Rivet <gaetan.rivet@6wind.com>
> > ---
> > 
> > I completely agree that we should change the coding style and force
> > all if()s to have brackets.
> > 
> > In the meantime, this patch might help alleviate the issue.
> > 
> >  mk/toolchain/gcc/rte.vars.mk | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk
> > index d8b99faf6..2c9bde1d5 100644
> > --- a/mk/toolchain/gcc/rte.vars.mk
> > +++ b/mk/toolchain/gcc/rte.vars.mk
> > @@ -87,5 +87,9 @@ WERROR_FLAGS += -Wimplicit-fallthrough=2
> >  WERROR_FLAGS += -Wno-format-truncation
> >  endif
> >  
> > +ifeq ($(shell test $(GCC_VERSION) -gt 60 && echo 1), 1)
> > +WERROR_FLAGS += -Wmisleading-indentation
> > +endif
> > +
> >  export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
> >  export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS
> > 
>
Anatoly Burakov Dec. 19, 2018, 10:05 a.m. UTC | #3
On 19-Dec-18 9:24 AM, Gaëtan Rivet wrote:
> On Tue, Dec 18, 2018 at 02:50:30PM +0000, Ferruh Yigit wrote:
>> On 12/18/2018 10:26 AM, Gaetan Rivet wrote:
>>> -Wmisleading-indentation was introduced in GCC 6.0.
>>
>> It seems '-Wmisleading-indentation' is part of -Wall, which we already set by
>> default. If so no need to explicitly add it.
>>
>> The link I found:
>> https://www.gnu.org/software/gcc/gcc-6/porting_to.html
>>
>> copy-paste:
>> "
>> A new warning -Wmisleading-indentation was added to -Wall, warning about places
>> where the indentation of the code might mislead a human reader about the control
>> flow:
>> "
>>
>> Is there a way to confirm it is part of -Wall?
>>
> 
> I think you are right, actually the check was already used.
> This is worrying, given that the original bug was not seen.
> 
> This patch can be left out then, but the problem remains. Maybe an
> update to coding style is needed, or an evolution to checkpatch //
> preferably something else.

clang-format? It's not exactly a style *checker*, but if we had a 
.clang-format config file included with DPDK, it would be easy to 1) 
format the code properly before sending out the patches, and 2) convert 
the entire DPDK codebase to the new style, should such need arise.

(also, uncrustify and other code beautifiers...)
diff mbox series

Patch

diff --git a/mk/toolchain/gcc/rte.vars.mk b/mk/toolchain/gcc/rte.vars.mk
index d8b99faf6..2c9bde1d5 100644
--- a/mk/toolchain/gcc/rte.vars.mk
+++ b/mk/toolchain/gcc/rte.vars.mk
@@ -87,5 +87,9 @@  WERROR_FLAGS += -Wimplicit-fallthrough=2
 WERROR_FLAGS += -Wno-format-truncation
 endif
 
+ifeq ($(shell test $(GCC_VERSION) -gt 60 && echo 1), 1)
+WERROR_FLAGS += -Wmisleading-indentation
+endif
+
 export CC AS AR LD OBJCOPY OBJDUMP STRIP READELF
 export TOOLCHAIN_CFLAGS TOOLCHAIN_LDFLAGS TOOLCHAIN_ASFLAGS