From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by sourceware.org (Postfix) with ESMTP id 73826389440C for ; Sun, 2 May 2021 15:01:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 73826389440C Received: from vapier (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id F38D6340CD6; Sun, 2 May 2021 15:01:56 +0000 (UTC) Date: Sun, 2 May 2021 11:01:55 -0400 From: Mike Frysinger To: Simon Marchi Cc: gdb-patches@sourceware.org Subject: Re: [PATCH] sim: add default cases to two switches in sim-options.c Message-ID: Mail-Followup-To: Simon Marchi , gdb-patches@sourceware.org References: <20210502141724.442932-1-simon.marchi@polymtl.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210502141724.442932-1-simon.marchi@polymtl.ca> X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 02 May 2021 15:02:00 -0000 On 02 May 2021 10:17, Simon Marchi via Gdb-patches wrote: > This is the next compilation error I hit when I build all targets with > Clang: > > /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:234:12: error: no case matching constant switch condition '0' [-Werror] switch (WITH_ENVIRONMENT) > ^~~~~~~~~~~~~~~~ ./config.h:215:26: note: expanded from macro 'WITH_ENVIRONMENT' > #define WITH_ENVIRONMENT ALL_ENVIRONMENT ^~~~~~~~~~~~~~~ > /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-options.c:276:15: error: no case matching constant switch condition '0' [-Werror] switch (WITH_ALIGNMENT) > ^~~~~~~~~~~~~~ /home/simark/src/binutils-gdb/sim/aarch64/../common/sim-config.h:220:24: note: expanded from macro 'WITH_ALIGNMENT' > #define WITH_ALIGNMENT 0 > ^ > > This is a little bit special because these are switches on compile-time > value. But regardless, the idea is that we logically can't reach the > switches if WITH_ENVIRONMENT == 0 or WITH_ALIGNMENT == 0, so the code is > correct. lgtm, thanks > In addition to getting rid of the compiler warning, adding default cases > to these switches ensure that if we do get in an unexpected situation, > it is caught. In GDB, I'd use gdb_assert_not_reached, I don't know if > there is something similar in sim so I went with abort. abort() is what we have atm for things like this. if it were due to a user error (passing wrong values), we'd do something else, but this is a compile time assertion. -mike