From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 984C6C54EE9 for ; Tue, 27 Sep 2022 16:46:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233143AbiI0QqR (ORCPT ); Tue, 27 Sep 2022 12:46:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233015AbiI0Qph (ORCPT ); Tue, 27 Sep 2022 12:45:37 -0400 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A1071BEBB for ; Tue, 27 Sep 2022 09:45:30 -0700 (PDT) Received: by mail-pf1-x42d.google.com with SMTP id b75so10178244pfb.7 for ; Tue, 27 Sep 2022 09:45:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date; bh=ghIr72d2MFWvVwzY3IxpJDMS5fyhMuvWUPUhopPN/qk=; b=K48GzDxdHhXcap5UllwByJj0tI7kwKfo9xjWBjGAHwE5rdcf9RcSbdsQfKAwyhHc7N o4P8EyCHs8tKNMTikv/JzA9qUP9dYc49/+OSdohoV4ceYj2l82iv5RLw4hxz4877Qtxi hZnpBGv7DyN1hlKa2RbKrC1zGiLQyOxO2pNfNh8BfexgGU/po7eZA9sZY18TSzNHNlkJ chr/K0WNdWeoDHzAZWRcwj5/ppCKpgZtCalznQKf7LLqa7c19cBf4wosicUeGoVcNfDJ GnaP5a5XS9iXSDcGeexRAa+IjyGQLWV89KCZnbZOWGWgBRQYczARFSjMOtEnvt3BS8rv UD/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date; bh=ghIr72d2MFWvVwzY3IxpJDMS5fyhMuvWUPUhopPN/qk=; b=vXqG1gbZhj1mSMQIrwJ27uh4GnQSOSv+mek5ty6+2NQDEOx3F+z/sW52TXH43jPFAQ OqYqYKcpS0QUiupMQ2Hsds5CdzEqBR8FT8al4jd6wREtBn8uyPOmDY00vtNh4iix+w5N BZCNi9yQH9j/upR6o28HJAkzYwj/fQSHRc1t/iXJ7g2DdUcdGQ+oZwmM1bW5Sq9B8BZw sWqADLj/qaEc/J07hZs7KYB3HNKl2kOVsfwJOHAJddN8+6A4Vupkb9oGVpIyAHgu7MP2 xgW+e99sp8FmSaGlpcPvqCOsXW4Dnmd1ICyssejEaBbMgV/dz7aA7tzR3yb8VuIj/FIa wK5Q== X-Gm-Message-State: ACrzQf3Jf8flc4los5hMWmmKJAlhZ5v8HjKdPa2O+3ZxujGjv/EWwf2Y 7hQ4lfK0Sq1IHvq2/mbnT3cpQnLOLWD5NOfsoqkaYA== X-Google-Smtp-Source: AMsMyM43m6tgs4G5qKkkxE77ZyJQmNDRdrfNh2BPt8T8lYzbrTNppaqkTELd+catwTn4ZNL8SRmR5P3qzcrLknIA/xI= X-Received: by 2002:a63:e709:0:b0:438:98e8:d1c with SMTP id b9-20020a63e709000000b0043898e80d1cmr25730430pgi.403.1664297129249; Tue, 27 Sep 2022 09:45:29 -0700 (PDT) MIME-Version: 1.0 References: <20220927153125.811911-1-zengheng4@huawei.com> In-Reply-To: <20220927153125.811911-1-zengheng4@huawei.com> From: Nick Desaulniers Date: Tue, 27 Sep 2022 09:45:17 -0700 Message-ID: Subject: Re: [PATCH -next] Makefile: add implicit enum-conversion check for compile build To: Zeng Heng Cc: masahiroy@kernel.org, michal.lkml@markovi.net, akpm@linux-foundation.org, peterz@infradead.org, keescook@chromium.org, davidgow@google.com, nathan@kernel.org, jpoimboe@kernel.org, dan.j.williams@intel.com, ojeda@kernel.org, isabbasso@riseup.net, dmitrii.bundin.a@gmail.com, vbabka@suse.cz, linux@rasmusvillemoes.dk, linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org, liwei391@huawei.com, weiyongjun1@huawei.com, clang-built-linux , linux-toolchains Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Tue, Sep 27, 2022 at 8:15 AM Zeng Heng wrote: > > Provide implicit enum-conversion warning option > in general build. When it set enabled, it can > detect implicit enum type conversion and find > potential conversion errors like below > (use "allmodconfig"): > > drivers/gpu/drm/amd/amdgpu/../display/dc/dml/dcn20/display_mode_vba_20.c:= 3904:46: > error: implicit conversion from =E2=80=98enum =E2=80=99 to =E2= =80=98enum odm_combine_mode=E2=80=99 [-Werror=3Denum-conversion] > 3904 | locals->ODMCombineEnablePerState[i][k] =3D true; > | ^ > > The '-Wenum-conversion' could be regarded as > effective check on compile runtime and > call attention on potential mistakes. > > Anothor practical example could be referred to: > https://lore.kernel.org/all/CADnq5_OE0yZvEYGu82QJHL9wvVcTFZrmeTgX7URgh7FV= A=3DjqYg@mail.gmail.com > > "-Wenum-conversion" was firstly introduced from > GNU gcc-10. What about clang? ;) > > Although "-Wenum-conversion" could be enabled > by "-Wextra" when compiling with 'W=3D1' option, > there are many warnings generated by '-Wextra' > that cause too much noise in a build. With clang, I believe that -Wenum-conversion is part of -Wall or -Wextra; so enabling this explicitly is only necessary for GCC. I wonder why it's not part of -Wall or -Wextra for GCC? Perhaps worth a bug report/feature request? > > Seeing the details from the following link: > https://gcc.gnu.org/onlinedocs/gcc-11.3.0/gcc/Warning-Options.html > > Because there are still some concerned warnings > exist, the patch marks the option disabled in default > for avoiding compile failed like using "allmodconfig". > > Signed-off-by: Zeng Heng > --- > Makefile | 5 +++++ > lib/Kconfig.debug | 7 +++++++ > 2 files changed, 12 insertions(+) > > diff --git a/Makefile b/Makefile > index ebd48fc956a3..1790a3624358 100644 > --- a/Makefile > +++ b/Makefile > @@ -880,6 +880,11 @@ endif > KBUILD_CFLAGS +=3D $(call cc-disable-warning, unused-but-set-variable) > KBUILD_CFLAGS +=3D $(call cc-disable-warning, unused-const-variable) > > +# check implicit enum conversion > +ifdef CONFIG_ENUM_CONVERSION > +KBUILD_CFLAGS +=3D -Wenum-conversion > +endif Having a kconfig for this is overkill. cc-option with a comment about the compiler default versions is the way to go. > + > # These result in bogus false positives > KBUILD_CFLAGS +=3D $(call cc-disable-warning, dangling-pointer) > > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug > index 4f2b81229a2f..a64e06a747d8 100644 > --- a/lib/Kconfig.debug > +++ b/lib/Kconfig.debug > @@ -417,6 +417,13 @@ config FRAME_WARN > Setting this too low will cause a lot of warnings. > Setting it to 0 disables the warning. > > +config ENUM_CONVERSION > + bool "Warn for implicit enum conversion" > + depends on GCC_VERSION >=3D 100300 > + default n > + help > + Tell gcc to warn at build time for implicit enum conversion. > + > config STRIP_ASM_SYMS > bool "Strip assembler-generated symbols during link" > default n > -- > 2.25.1 > --=20 Thanks, ~Nick Desaulniers