From patchwork Thu Sep 6 03:38:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29211 Received: (qmail 9238 invoked by alias); 6 Sep 2018 03:39:04 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 9216 invoked by uid 89); 6 Sep 2018 03:39:04 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: gateway21.websitewelcome.com Received: from gateway21.websitewelcome.com (HELO gateway21.websitewelcome.com) (192.185.45.228) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Sep 2018 03:39:01 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway21.websitewelcome.com (Postfix) with ESMTP id 09E9E400C97C6 for ; Wed, 5 Sep 2018 22:39:00 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id xl8FfAhn1RPojxl8FfZJsG; Wed, 05 Sep 2018 22:39:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=bZ95vPRFmXlDe5haTs2u1eRFsC69sxdfia/nIxXctak=; b=g9SEqSzqhcQlVgQhimbKx00njg 5czMEaQq3sIWZyr1amhNSXX3qkFjCdbhbqumELpZMBMpJQ3kfqKpNIOw45Cm+Xmk4uw3BselT1SjJ 8fBhEujTXdB/evhBCU/NcDVCL; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:43798 helo=pokyo.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fxl8F-001PJT-ON; Wed, 05 Sep 2018 22:38:59 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [FYI 1/2] Disable -Wformat-nonliteral in parts of printcmd.c Date: Wed, 5 Sep 2018 21:38:54 -0600 Message-Id: <20180906033855.13635-2-tom@tromey.com> In-Reply-To: <20180906033855.13635-1-tom@tromey.com> References: <20180906033855.13635-1-tom@tromey.com> From: Simon Marchi commit 3322c5d9a1 ("Remove unneeded explicit .o targets") broke the build with clang, because -Wformat-nonliteral was in fact needed. This patch fixes the problem by introducing DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL and using it in printcmd.c. This seems preferable to reverting the patch because now the warning suppression is more targeted. gdb/ChangeLog 2018-09-05 Simon Marchi * printcmd.c (printf_c_string): Use DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL. (printf_wide_c_string, printf_pointer, ui_printf): Likewise. include/ChangeLog 2018-09-05 Simon Marchi * diagnostics.h (DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL): New macro. --- gdb/ChangeLog | 6 ++++++ gdb/printcmd.c | 33 +++++++++++++++++++++++++++++++++ include/ChangeLog | 4 ++++ include/diagnostics.h | 12 ++++++++++++ 4 files changed, 55 insertions(+) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 084765d29c..d8ca6d3dab 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-09-05 Simon Marchi + + * printcmd.c (printf_c_string): Use + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL. + (printf_wide_c_string, printf_pointer, ui_printf): Likewise. + 2018-09-05 Tom Tromey * cli/cli-cmds.c (shell_escape, edit_command): Remove cast. diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 1a3d9723d4..8c999188d7 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -2200,7 +2200,10 @@ printf_c_string (struct ui_file *stream, const char *format, tem = value_as_address (value); if (tem == 0) { + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, format, "(null)"); + DIAGNOSTIC_POP return; } @@ -2221,7 +2224,10 @@ printf_c_string (struct ui_file *stream, const char *format, read_memory (tem, str, j); str[j] = 0; + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, format, (char *) str); + DIAGNOSTIC_POP } /* Subroutine of ui_printf to simplify it. @@ -2245,7 +2251,10 @@ printf_wide_c_string (struct ui_file *stream, const char *format, tem = value_as_address (value); if (tem == 0) { + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, format, "(null)"); + DIAGNOSTIC_POP return; } @@ -2272,7 +2281,10 @@ printf_wide_c_string (struct ui_file *stream, const char *format, &output, translit_char); obstack_grow_str0 (&output, ""); + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, format, obstack_base (&output)); + DIAGNOSTIC_POP } /* Subroutine of ui_printf to simplify it. @@ -2400,13 +2412,19 @@ printf_pointer (struct ui_file *stream, const char *format, *fmt_p++ = 'l'; *fmt_p++ = 'x'; *fmt_p++ = '\0'; + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, fmt, val); + DIAGNOSTIC_POP } else { *fmt_p++ = 's'; *fmt_p++ = '\0'; + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, fmt, "(nil)"); + DIAGNOSTIC_POP } } @@ -2507,8 +2525,11 @@ ui_printf (const char *arg, struct ui_file *stream) &output, translit_char); obstack_grow_str0 (&output, ""); + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, current_substring, obstack_base (&output)); + DIAGNOSTIC_POP } break; case long_long_arg: @@ -2516,7 +2537,10 @@ ui_printf (const char *arg, struct ui_file *stream) { long long val = value_as_long (val_args[i]); + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, current_substring, val); + DIAGNOSTIC_POP break; } #else @@ -2526,14 +2550,20 @@ ui_printf (const char *arg, struct ui_file *stream) { int val = value_as_long (val_args[i]); + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, current_substring, val); + DIAGNOSTIC_POP break; } case long_arg: { long val = value_as_long (val_args[i]); + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, current_substring, val); + DIAGNOSTIC_POP break; } /* Handles floating-point values. */ @@ -2557,7 +2587,10 @@ ui_printf (const char *arg, struct ui_file *stream) have modified GCC to include -Wformat-security by default, which will warn here if there is no argument. */ + DIAGNOSTIC_PUSH + DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL fprintf_filtered (stream, current_substring, 0); + DIAGNOSTIC_POP break; default: internal_error (__FILE__, __LINE__, diff --git a/include/ChangeLog b/include/ChangeLog index 63fdde6349..c23c743738 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,7 @@ +2018-09-05 Simon Marchi + + * diagnostics.h (DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL): New macro. + 2018-08-31 Alan Modra * elf/ppc64.h (R_PPC64_REL16_HIGH, R_PPC64_REL16_HIGHA), diff --git a/include/diagnostics.h b/include/diagnostics.h index 9e9d1a832f..79e6779edf 100644 --- a/include/diagnostics.h +++ b/include/diagnostics.h @@ -59,6 +59,10 @@ # define DIAGNOSTIC_IGNORE_SWITCH_DIFFERENT_ENUM_TYPES \ DIAGNOSTIC_IGNORE ("-Wenum-compare-switch") # endif + +# define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ + DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") + #elif defined (__GNUC__) /* GCC */ # define DIAGNOSTIC_IGNORE_UNUSED_FUNCTION \ @@ -66,6 +70,10 @@ # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION \ DIAGNOSTIC_IGNORE ("-Wstringop-truncation") + +# define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL \ + DIAGNOSTIC_IGNORE ("-Wformat-nonliteral") + #endif #ifndef DIAGNOSTIC_IGNORE_SELF_MOVE @@ -92,4 +100,8 @@ # define DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION #endif +#ifndef DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL +# define DIAGNOSTIC_IGNORE_FORMAT_NONLITERAL +#endif + #endif /* DIAGNOSTICS_H */