qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: Stefan Weil <sw@weilnetz.de>
Cc: peter.maydell@linaro.org, pburton@wavecomp.com,
	smarkovic@wavecomp.com, riku.voipio@iki.fi,
	richard.henderson@linaro.org, qemu-devel@nongnu.org,
	laurent@vivier.eu,
	Aleksandar Markovic <aleksandar.markovic@rt-rk.com>,
	philippe.mathieu.daude@gmail.com, amarkovic@wavecomp.com,
	pjovanovic@wavecomp.com, aurelien@aurel32.net
Subject: Re: [Qemu-devel] Handling of fall through code (was: [PATCH v8 04/87] target/mips: Mark switch fallthroughs with interpretable comments
Date: Mon, 08 Jul 2019 06:40:38 +0200	[thread overview]
Message-ID: <87imsdcf5l.fsf@dusky.pond.sub.org> (raw)
In-Reply-To: <4da49ffe-902f-2cf2-8a21-2bbd511b17a4@weilnetz.de> (Stefan Weil's message of "Sun, 7 Jul 2019 22:26:22 +0200")

Stefan Weil <sw@weilnetz.de> writes:

> Am 13.08.18 um 19:52 schrieb Aleksandar Markovic:
>
>> From: Aleksandar Markovic <amarkovic@wavecomp.com>
>>
>> Mark switch fallthroughs with comments, in cases fallthroughs
>> are intentional.
>
>
> This is a general problem all over the QEMU code. I usually compile
> with nearly all warnings enabled and get now lots of errors with the
> latest code and after updating to gcc-8.3.0 (Debian buster). It should
> be reproducible by enabling -Werror=implicit-fallthrough.
>
> The current situation is like this:
>
> - Some code has fallthrough comments which are accepted by the compiler.
>
> - Other code has fallthrough comments which are not accepted
> (resulting in a compiler error).
>
> - Some code is correct, but has no indication that the fallthrough is
> intentional.

I'd treat that as a bug.

> - There is also fallthrough code which is obviously not correct (even
> in target/mips/translate.c).

Bug.

> I suggest to enable -Werror=implicit-fallthrough by default and add a
> new macro to mark all fallthrough locations which are correct, but not
> accepted by the compiler.
>
> This can be done with a definition for GCC compatible compilers in
> include/qemu/compiler.h:
>
> #define QEMU_FALLTHROUGH __attribute__ ((fallthrough))
>
> Then fallthrough code would look like this:
>
>     case 1:
>         do_something();
>         QEMU_FALLTHROUGH;
>
>     case 2:
>
>
> VIXL_FALLTHROUGH also needs a similar definition to work with gcc-8.3.0.
>
> Please comment. Would you prefer another macro name or a macro with
> parentheses like this:
>
> #define QEMU_FALLTHROUGH() __attribute__ ((fallthrough))

In my opinion, the macro is no clearer than proper comments.

I'd prefer -Wimplicit-fallthrough=1 or 2.  The former makes gcc accept
any comment.  The latter makes it accept '.*falls?[ \t-]*thr(ough|u).*',
which should still match the majority of our comments.  Less churn than
the macro.

> As soon as there is consensus on the macro name and form, I can send a
> patch which adds it (but would not mind if someone else adds it).
>
> Then I suggest that the maintainers build with the fallthrough warning
> enabled and fix all warnings, either by using the new macro or by
> adding the missing break.
>
> Finally we can enforce the warning by default.
>
>
> Another macro which is currently missing is a scanf variant of GCC_FMT_ATTR.
>
> I suggest to add and use a GCC_SCANF_ATTR macro:
>
> #define GCC_SCANF_ATTR(n, m) __attribute__((format(gnu_scanf, n, m)))

Do we define our own scanf()-like functions?  If yes, decorating them
with the attribute is a good idea.

However, the gnu_ in gnu_scanf tells the compiler we're linking with the
GNU C Library, which seems unwise.  Hmm, we already use gnu_printf.
Commit 9c9e7d51bf0:

    Newer gcc versions support format gnu_printf which is
    better suited for use in QEMU than format printf
    (QEMU always uses standard format strings (even with mingw32)).

Should we limit the use of gnu_printf to #ifdef _WIN32?

> A more regular solution would require renaming GCC_FMT_ATTR to
> GCC_FMT_PRINTF and use GCC_FMT_SCANF for the new macro.

Quite some churn, but regularity matters.


  reply	other threads:[~2019-07-08  4:41 UTC|newest]

Thread overview: 120+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-13 17:52 [Qemu-devel] [PATCH v8 00/87] Add nanoMIPS support to QEMU Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 01/87] MAINTAINERS: Update target/mips maintainer's email addresses Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 02/87] target/mips: Avoid case statements formulated by ranges - part 1 Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 03/87] target/mips: Avoid case statements formulated by ranges - part 2 Aleksandar Markovic
2018-08-14 11:13   ` Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 04/87] target/mips: Mark switch fallthroughs with interpretable comments Aleksandar Markovic
2019-07-07 20:26   ` [Qemu-devel] Handling of fall through code (was: " Stefan Weil
2019-07-08  4:40     ` Markus Armbruster [this message]
2019-07-08  4:52       ` [Qemu-devel] Handling of fall through code Stefan Weil
2019-07-09  5:40         ` Markus Armbruster
2019-07-08  8:14     ` [Qemu-devel] Handling of fall through code (was: [PATCH v8 04/87] target/mips: Mark switch fallthroughs with interpretable comments Aleksandar Markovic
2019-07-08 12:04       ` Stefan Weil
2019-07-08 12:08         ` Daniel P. Berrangé
2019-07-08 19:39         ` Aleksandar Markovic
2019-07-09  8:25           ` Peter Maydell
2019-07-21 16:39             ` [Qemu-devel] Handling of fall through code Stefan Weil
2019-07-22  9:09               ` Peter Maydell
2019-07-08  8:42     ` [Qemu-devel] Handling of fall through code (was: [PATCH v8 04/87] target/mips: Mark switch fallthroughs with interpretable comments Peter Maydell
2019-07-09  5:42       ` Markus Armbruster
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 05/87] target/mips: Fix two instances of shadow variables Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 06/87] target/mips: Update some CP0 registers bit definitions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 07/87] target/mips: Add CP0 BadInstrX register Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 08/87] target/mips: Add support for availability control via bit XNP Aleksandar Markovic
2018-08-14 12:23   ` Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 09/87] target/mips: Add support for availability control via bit MT Aleksandar Markovic
2018-08-13 18:13   ` Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 10/87] target/mips: Fix MT ASE instructions' availability control Aleksandar Markovic
2018-08-13 18:23   ` Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 11/87] target/mips: Implement CP0 Config1.WR bit functionality Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 12/87] target/mips: Don't update BadVAddr register in Debug Mode Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 13/87] target/mips: Check ELPA flag only in some cases of MFHC0 and MTHC0 Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 14/87] target/mips: Add gen_op_addr_addi() Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 15/87] elf: Remove duplicate preprocessor constant definition Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 16/87] elf: Add ELF flags for MIPS machine variants Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 17/87] linux-user: Update MIPS syscall numbers up to kernel 4.18 headers Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 18/87] linux-user: Add preprocessor availability control to some syscalls Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 19/87] qemu-doc: Amend MIPS-related items Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 20/87] target/mips: Add preprocessor constants for nanoMIPS Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 21/87] target/mips: Add nanoMIPS base instruction set opcodes Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 22/87] target/mips: Add nanoMIPS DSP ASE opcodes Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 23/87] target/mips: Add placeholder and invocation of decode_nanomips_opc() Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 24/87] target/mips: Add nanoMIPS decoding and extraction utilities Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 25/87] target/mips: Add emulation of nanoMIPS 16-bit arithmetic instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 26/87] target/mips: Add emulation of nanoMIPS 16-bit branch instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 27/87] target/mips: Add emulation of nanoMIPS 16-bit shift instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 28/87] target/mips: Add emulation of nanoMIPS 16-bit misc instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 29/87] target/mips: Add emulation of nanoMIPS 16-bit load and store instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 30/87] target/mips: Add emulation of nanoMIPS 16-bit logic instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 31/87] target/mips: Add emulation of nanoMIPS 16-bit save and restore instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 32/87] target/mips: Add emulation of some common nanoMIPS 32-bit instructions Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 33/87] target/mips: Add emulation of nanoMIPS instructions MOVE.P and MOVE.PREV Aleksandar Markovic
2018-08-13 17:52 ` [Qemu-devel] [PATCH v8 34/87] target/mips: Add emulation of nanoMIPS 48-bit instructions Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 35/87] target/mips: Add emulation of nanoMIPS FP instructions Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 36/87] target/mips: Add emulation of misc nanoMIPS instructions (pool32a0) Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 37/87] target/mips: Add emulation of misc nanoMIPS instructions (pool32axf) Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 38/87] target/mips: Add emulation of misc nanoMIPS instructions (p_lsx) Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 39/87] target/mips: Implement emulation of nanoMIPS ROTX instruction Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 40/87] target/mips: Implement emulation of nanoMIPS EXTW instruction Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 41/87] target/mips: Add emulation of nanoMIPS 32-bit load and store instructions Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 42/87] target/mips: Implement emulation of nanoMIPS LLWP/SCWP pair Aleksandar Markovic
2018-08-14 12:20   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 43/87] target/mips: Add emulation of nanoMIPS 32-bit branch instructions Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 44/87] target/mips: Implement MT ASE support for nanoMIPS Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 45/87] target/mips: Add emulation of DSP ASE for nanoMIPS - part 1 Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 46/87] target/mips: Add emulation of DSP ASE for nanoMIPS - part 2 Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 47/87] target/mips: Add emulation of DSP ASE for nanoMIPS - part 3 Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 48/87] target/mips: Add emulation of DSP ASE for nanoMIPS - part 4 Aleksandar Markovic
2018-08-16 12:31   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 49/87] target/mips: Add emulation of DSP ASE for nanoMIPS - part 5 Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 50/87] target/mips: Add emulation of DSP ASE for nanoMIPS - part 6 Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 51/87] disas: Add support for microMIPS and nanoMIPS Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 52/87] target/mips: Add handling of branch delay slots for nanoMIPS Aleksandar Markovic
2018-08-16 13:01   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 53/87] target/mips: Add updating BadInstr, BadInstrP, BadInstrX " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 54/87] target/mips: Adjust exception_resume_pc() " Aleksandar Markovic
2018-08-16 12:56   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 55/87] target/mips: Adjust set_hflags_for_handler() " Aleksandar Markovic
2018-08-16 12:05   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 56/87] target/mips: Adjust set_pc() " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 57/87] target/mips: Fix ERET/ERETNC behavior related to ADEL exception Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 58/87] elf: Add EM_NANOMIPS value as a valid one for e_machine field Aleksandar Markovic
2018-08-16 12:55   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 59/87] elf: Relax MIPS' elf_check_arch() to accept EM_NANOMIPS too Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 60/87] elf: Don't check FCR31_NAN2008 bit for nanoMIPS Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 61/87] elf: On elf loading, treat both EM_MIPS and EM_NANOMIPS as legal for MIPS Aleksandar Markovic
2018-08-16 12:28   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 62/87] mips_malta: Add basic nanoMIPS boot code for Malta board Aleksandar Markovic
2018-08-16 11:59   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 63/87] mips_malta: Add setting up GT64120 BARs to the nanoMIPS bootloader Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 64/87] mips_malta: Fix semihosting argument passing for nanoMIPS bare metal Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 65/87] target/mips: Add definition of nanoMIPS I7200 CPU Aleksandar Markovic
2018-08-16 12:26   ` Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 66/87] elf: Add nanoMIPS specific variations in ELF header fields Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 67/87] linux-user: Add syscall numbers for nanoMIPS Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 68/87] linux-user: Add target_signal.h header " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 69/87] linux-user: Add termbits.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 70/87] linux-user: Update syscall_defs.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 71/87] linux-user: Add target_fcntl.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 72/87] linux-user: Add sockbits.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 73/87] linux-user: Add target_syscall.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 74/87] linux-user: Add target_cpu.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 75/87] linux-user: Add target_structs.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 76/87] linux-user: Add target_elf.h " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 77/87] linux-user: Add signal.c " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 78/87] linux-user: Add support for nanoMIPS signal trampoline Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 79/87] linux-user: Add cpu_loop.c for nanoMIPS Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 80/87] linux-user: Amend support for sigaction() syscall " Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 81/87] linux-user: Add support for statx() syscall for all platforms Aleksandar Markovic
2018-08-20  7:48   ` Timothy Baldwin
2018-08-20  9:45     ` Aleksandar Markovic
2018-08-29 15:38       ` Timothy Baldwin
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 82/87] linux-user: Add support for nanoMIPS core files Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 83/87] linux-user: Add nanoMIPS linux user mode configuration support Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 84/87] linux-user: Add nanoMIPS support in scripts/qemu-binfmt-conf.sh Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 85/87] gdbstub: Disable handling of nanoMIPS ISA bit in the MIPS gdbstub Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 86/87] gdbstub: Add XML support for GDB for nanoMIPS Aleksandar Markovic
2018-08-13 17:53 ` [Qemu-devel] [PATCH v8 87/87] qemu-doc: Add nanoMIPS-related items Aleksandar Markovic
2018-08-14 15:52 ` [Qemu-devel] [PATCH v8 00/87] Add nanoMIPS support to QEMU Aleksandar Markovic
2018-08-16  8:16 ` no-reply
2018-08-16 11:43   ` Aleksandar Markovic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87imsdcf5l.fsf@dusky.pond.sub.org \
    --to=armbru@redhat.com \
    --cc=aleksandar.markovic@rt-rk.com \
    --cc=amarkovic@wavecomp.com \
    --cc=aurelien@aurel32.net \
    --cc=laurent@vivier.eu \
    --cc=pburton@wavecomp.com \
    --cc=peter.maydell@linaro.org \
    --cc=philippe.mathieu.daude@gmail.com \
    --cc=pjovanovic@wavecomp.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=riku.voipio@iki.fi \
    --cc=smarkovic@wavecomp.com \
    --cc=sw@weilnetz.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).