From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 37D5F385781F for ; Fri, 20 Aug 2021 09:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 37D5F385781F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-477-zT5ggSguMMC2qib9JUsFtw-1; Fri, 20 Aug 2021 05:16:30 -0400 X-MC-Unique: zT5ggSguMMC2qib9JUsFtw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8BB201008063; Fri, 20 Aug 2021 09:16:29 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.120]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AC9B719C87; Fri, 20 Aug 2021 09:16:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 17K9GP2D2768278 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 20 Aug 2021 11:16:25 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 17K9GIWN2768277; Fri, 20 Aug 2021 11:16:18 +0200 Date: Fri, 20 Aug 2021 11:16:18 +0200 From: Jakub Jelinek To: Harald Anlauf Cc: "H.J. Lu" , Tobias Burnus , Harald Anlauf via Gcc-patches , fortran Subject: Re: [PATCH] PR fortran/100950 - ICE in output_constructor_regular_field, at varasm.c:5514 Message-ID: <20210820091618.GB2380545@tucnak> Reply-To: Jakub Jelinek References: <8d25c317-74fa-d8a2-724f-de6944fa602e@codesourcery.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_ASCII_DIVIDERS, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: fortran@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Fortran mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Aug 2021 09:16:43 -0000 On Fri, Aug 20, 2021 at 08:48:57AM +0200, Harald Anlauf via Gcc-patches wrote: > Hi! > > > Gesendet: Freitag, 20. August 2021 um 02:21 Uhr > > Von: "H.J. Lu" > > > This may have broken bootstrap on 32-bit hosts: > > > > https://gcc.gnu.org/pipermail/gcc-regression/2021-August/075209.html > > I do not understand the error message: > > ../../src-master/gcc/fortran/simplify.c: In function ‘bool substring_has_constant_len(gfc_expr*)’: > ../../src-master/gcc/fortran/simplify.c:4557:22: error: unknown conversion type character ‘l’ in format [-Werror=format=] > 4557 | gfc_error ("Substring start index (" HOST_WIDE_INT_PRINT_DEC > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 4558 | ") at %L below 1", > | ~~~~~~~~~~~~~~~~~ > ../../src-master/gcc/fortran/simplify.c:4557:22: error: format ‘%L’ expects argument of type ‘locus*’, but argument 2 has type ‘long long int’ [-Werror=format=] > 4557 | gfc_error ("Substring start index (" HOST_WIDE_INT_PRINT_DEC > | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 4558 | ") at %L below 1", > | ~~~~~~~~~~~~~~~~~ > 4559 | istart, &ref->u.ss.start->where); > | ~~~~~~ > | | > | long long int > ../../src-master/gcc/fortran/simplify.c:4557:22: error: too many arguments for format [-Werror=format-extra-args] > > Is there an issue with HOST_WIDE_INT_PRINT_DEC on 32-bit hosts? > What is the right way to print a HOST_WIDE_INT? > > It works on 64-bit without any warning. gfc_error etc. aren't *printf family, it has its own format specifier handling (e.g. it handles %L and %C), and it is even different from the error/warning handling in middle-end/c-family FEs/backends. HOST_WIDE_INT_PRINT_DEC is wrong in the above spot for 2 reasons: 1) gfc_error etc. argument is automatically marked for translation and translated, having a macro in there that expands to various things depending on host makes it impossible to mark for translation and a lottery for translation. 2) hwint.h defines: #define HOST_LONG_FORMAT "l" #define HOST_LONG_LONG_FORMAT "ll" #if INT64_T_IS_LONG # define GCC_PRI64 HOST_LONG_FORMAT #else # define GCC_PRI64 HOST_LONG_LONG_FORMAT #endif #define PRId64 GCC_PRI64 "d" #define HOST_WIDE_INT_PRINT_DEC "%" PRId64 but xm-mingw32.h overrides #define HOST_LONG_LONG_FORMAT "I64" so effectively HOST_WIDE_INT_PRINT_DEC is "%ld", "%lld" or "%I64d" Now, gfc_error does handle %d or %ld, but doesn't handle %lld nor %I64d, so even if the 1) issue didn't exist, this explains why it works only on some hosts (e.g. x86_64-linux where %ld is used). But e.g. on i686-linux or many other hosts it is %lld which gfc_error doesn't handle and on Windows that %I64d. Now, the non-Fortran FE diagnostic code actually has %wd for this (w modifier like l modifier), which takes HOST_WIDE_INT/unsigned HOST_WIDE_INT argument and prints it. So, either you get through the hops to support that, unfortunately it isn't just adding support for that in fortran/error.c (error_print) and some helper functions, which wouldn't be that hard, just add 'w' next to 'l' handling, TYPE_* for that and union member etc., but one needs to modify c-family/c-format.c too to register the modifier so that gcc doesn't warn about it and knows the proper argument type etc. The other much easier but uglier option is to use a temporary buffer: char buffer[21]; sprintf (buffer, HOST_WIDE_INT_PRINT_DEC, hwint_val); gfc_error ("... %s ...", ... buffer ...); This works, as it uses the host sprintf i.e. *printf family for which HOST_WIDE_INT_PRINT_DEC macro is designed. Jakub