From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by sourceware.org (Postfix) with ESMTP id 9FC473894424 for ; Tue, 15 Jun 2021 05:11:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FC473894424 Received: from vapier.lan (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id DE2CC340E84 for ; Tue, 15 Jun 2021 05:11:43 +0000 (UTC) From: Mike Frysinger To: gdb-patches@sourceware.org Subject: [PATCH 5/6] sim: mips: rework dynamic printf logic to avoid compiler warnings Date: Tue, 15 Jun 2021 01:11:40 -0400 Message-Id: <20210615051141.4801-5-vapier@gentoo.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210615051141.4801-1-vapier@gentoo.org> References: <20210615051141.4801-1-vapier@gentoo.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, 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: Tue, 15 Jun 2021 05:11:45 -0000 The compiler doesn't like passing non-constant strings to printf functions, so tweak the code to always pass one in. This code is a little more verbose, but it's probably the same performance. --- sim/mips/interp.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/sim/mips/interp.c b/sim/mips/interp.c index bccc4c76ed8b..fc7b00324ffb 100644 --- a/sim/mips/interp.c +++ b/sim/mips/interp.c @@ -1388,7 +1388,7 @@ sim_monitor (SIM_DESC sd, { address_word s = A0; unsigned char c; - signed_word *ap = &A1; /* 1st argument */ + address_word *ap = &A1; /* 1st argument */ /* This isn't the quickest way, since we call the host print routine for every character almost. But it does avoid having to allocate and manage a temporary string buffer. */ @@ -1471,18 +1471,43 @@ sim_monitor (SIM_DESC sd, sim_io_printf(sd,""); else { - sprintf (tmp, "%%%s%c", longlong ? "ll" : "", c); - if (longlong) - sim_io_printf(sd, tmp, lv); - else - sim_io_printf(sd, tmp, (int)lv); +#define _P(c, fmt64, fmt32) \ + case c: \ + if (longlong) \ + sim_io_printf (sd, "%" fmt64, lv); \ + else \ + sim_io_printf (sd, "%" fmt32, (int)lv); \ + break; +#define P(c, fmtc) _P(c, PRI##fmtc##64, PRI##fmtc##32) + switch (c) + { + P('d', d) + P('o', o) + P('x', x) + P('X', X) + P('u', u) + } } +#undef P +#undef _P } else if (strchr ("eEfgG", c)) { double dbl = *(double*)(ap++); - sprintf (tmp, "%%%d.%d%c", width, trunc, c); - sim_io_printf (sd, tmp, dbl); + +#define P(c, fmtc) \ + case c: \ + sim_io_printf (sd, "%*.*" #fmtc, width, trunc, dbl); \ + break; + switch (c) + { + P('e', e) + P('E', E) + P('f', f) + P('g', g) + P('G', G) + } +#undef P trunc = 0; } } -- 2.31.1