From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id 900663833025 for ; Sun, 2 May 2021 15:06:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 900663833025 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 142F6FL7011747 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 2 May 2021 11:06:19 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 142F6FL7011747 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 2CDCE1E54D for ; Sun, 2 May 2021 11:06:15 -0400 (EDT) Subject: Re: [PATCH] sim: add default cases to two switches in sim-options.c To: gdb-patches@sourceware.org References: <20210502141724.442932-1-simon.marchi@polymtl.ca> From: Simon Marchi Message-ID: Date: Sun, 2 May 2021 11:06:14 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Sun, 2 May 2021 15:06:15 +0000 X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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:06:22 -0000 On 2021-05-02 11:01 a.m., Mike Frysinger wrote: > 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. Indeed, I agree. Pushed, thanks! Simon