From patchwork Tue Jun 30 11:11:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1319750 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.a=rsa-sha256 header.s=nc1116a header.b=jHhff0Sx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49x1rM4KpDz9s6w for ; Tue, 30 Jun 2020 21:11:14 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id DAE043857020; Tue, 30 Jun 2020 11:11:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout1.netcologne.de (cc-smtpout1.netcologne.de [IPv6:2001:4dd0:100:1062:25:2:0:1]) by sourceware.org (Postfix) with ESMTPS id 16A1B385700F; Tue, 30 Jun 2020 11:11:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 16A1B385700F Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tkoenig@netcologne.de Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id AB49613782; Tue, 30 Jun 2020 13:11:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1593515461; bh=Mi/hKCSVph/9Gnp/9k3LMDoHvc5lSwfLObt+jKwvPB8=; h=To:From:Subject:Message-ID:Date:From; b=jHhff0SxQpT3X3I1ZEdkq0/hddxUE5FMe8h3khMSqL2C+9zHbpG7RXguYbeNYGSqx 9bwhnthbKH5JN26TtYAX7p1dJsp7Pdxg6ZDcxYjqWBNHikCUQnHdE2p2XrKUdE+91b EVyLOfQA9dUPXKajh9kz1agWmDJM8YdLTqx6mDbjjpKRyN52RuSPvRAreHHSv+fVYs WHL1XHPP9uJ5fL3qzujtLDgm2Qy8ETCQSw8hP1z9iiF9vPHqHP+2brw/BbDaFJQkY7 9H9MBYpQu/uYwGbw323qY1O37dDj9QoEPWpNHOycHdbMxoTgGYdebUzwShnIjebfGc k3GTSz+LyjjGg== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 9CF9E11F20; Tue, 30 Jun 2020 13:11:01 +0200 (CEST) Received: from [2001:4dd7:d9be:0:5ad3:7b3b:4e4a:96b8] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5efb1dc5-7569-7f0000012729-7f000001ed3c-1 for ; Tue, 30 Jun 2020 13:11:01 +0200 Received: from linux-p51k.fritz.box (2001-4dd7-d9be-0-5ad3-7b3b-4e4a-96b8.ipv6dyn.netcologne.de [IPv6:2001:4dd7:d9be:0:5ad3:7b3b:4e4a:96b8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Tue, 30 Jun 2020 13:11:00 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran, committed] Fix PR 95366, wrong code and ABI breakage Message-ID: <69cd8697-d4e3-8ab5-5fcd-98d25ed0fc16@netcologne.de> Date: Tue, 30 Jun 2020 13:11:00 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 Content-Language: de-DE X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hello world, fortunately, upon inspection the fix for this PR turned out to be obvious (and simple). I have committed it as such. Unless there is unexpected fallout, I intend to backport it to gcc-10 over the weekend so it can still be included into 10.2. Regression-tested on x86_64 and on a big-endian POWER, to make sure the hash values were the same. Regards Thomas Use CHARACTER(kind) string for calculating the type hash. This regression came about because of a change in the way types are displayed in error messages. The character representation is also used to calculate the hashes for our types, so this patch restores the old behavior if we are indeed calculating a hash. The test case also checks for the specific hash value because changing that would be an ABI change, which we should not be doing unintentionally. gcc/fortran/ChangeLog: 2020-06-30 Thomas Koenig PR fortran/95355 * gfortran.h (gfc_typename): Add optional argument for_hash. * misc.c (gfc_typename): When for_hash is true, just return CHARACTER(kind). * class.c (gfc_intrinsic_hash_value): Call gfc_typename with for_hash = true. diff --git a/gcc/fortran/class.c b/gcc/fortran/class.c index 2b760efe8d7..08705c7e95d 100644 --- a/gcc/fortran/class.c +++ b/gcc/fortran/class.c @@ -564,7 +564,7 @@ unsigned int gfc_intrinsic_hash_value (gfc_typespec *ts) { unsigned int hash = 0; - const char *c = gfc_typename (ts); + const char *c = gfc_typename (ts, true); int i, len; len = strlen (c); diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index 836e0b3063d..24c5101c4cb 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2931,7 +2931,7 @@ void gfc_clear_ts (gfc_typespec *); FILE *gfc_open_file (const char *); const char *gfc_basic_typename (bt); const char *gfc_dummy_typename (gfc_typespec *); -const char *gfc_typename (gfc_typespec *); +const char *gfc_typename (gfc_typespec *, bool for_hash = false); const char *gfc_typename (gfc_expr *); const char *gfc_op2string (gfc_intrinsic_op); const char *gfc_code2string (const mstring *, int); diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c index 46c6277c2b9..65bcfa6162f 100644 --- a/gcc/fortran/misc.c +++ b/gcc/fortran/misc.c @@ -122,7 +122,7 @@ gfc_basic_typename (bt type) the argument list of a single statement. */ const char * -gfc_typename (gfc_typespec *ts) +gfc_typename (gfc_typespec *ts, bool for_hash) { static char buffer1[GFC_MAX_SYMBOL_LEN + 7]; /* 7 for "TYPE()" + '\0'. */ static char buffer2[GFC_MAX_SYMBOL_LEN + 7]; @@ -149,6 +149,12 @@ gfc_typename (gfc_typespec *ts) sprintf (buffer, "LOGICAL(%d)", ts->kind); break; case BT_CHARACTER: + if (for_hash) + { + sprintf (buffer, "CHARACTER(%d)", ts->kind); + break; + } + if (ts->u.cl && ts->u.cl->length) length = gfc_mpz_get_hwi (ts->u.cl->length->value.integer); if (ts->kind == gfc_default_character_kind) diff --git a/gcc/testsuite/gfortran.dg/select_type_49.f90 b/gcc/testsuite/gfortran.dg/select_type_49.f90 new file mode 100644 index 00000000000..31203cd18fc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/select_type_49.f90 @@ -0,0 +1,43 @@ +! { dg-do run } +! { dg-additional-options "-fdump-tree-original" } +! PR 95366 - this did not work due the wrong hashes +! being generated for CHARACTER variables. +MODULE mod1 + implicit none + integer :: tst(3) +CONTAINS + subroutine showpoly(poly) + CLASS(*), INTENT(IN) :: poly(:) + SELECT TYPE (poly) + TYPE IS(INTEGER) + tst(1) = tst(1) + 1 + TYPE IS(character(*)) + tst(2) = tst(2) + 1 + class default + tst(3) = tst(3) + 1 + end select + end subroutine showpoly +END MODULE mod1 +MODULE mod2 + implicit none +CONTAINS +subroutine polytest2() + use mod1 + integer :: a(1) + character(len=42) :: c(1) + call showpoly(a) + if (any(tst /= [1,0,0])) stop 1 + call showpoly(c) + if (any(tst /= [1,1,0])) stop 2 +end subroutine polytest2 +END MODULE mod2 +PROGRAM testpoly + use mod2 + CALL polytest2() +END PROGRAM testpoly +! The value of the hashes are also checked. If you get +! a failure here, be aware that changing that value is +! an ABI change. + +! { dg-final { scan-tree-dump-times "== 17759" 1 "original" } } +! { dg-final { scan-tree-dump-times "== 85893463" 1 "original" } }