Message ID | df9f403f4e3c1f9ad620e8d5e38adaa59be2332b.camel@microchip.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4145673vqr; Tue, 20 Jun 2023 22:58:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5cMpY5wadsEGoiVNMb4XeYei8wNWreJlKYGPRAkN7aTYazmQQhFKTHbjufdy+tRjOzCtg1 X-Received: by 2002:a17:907:3ea3:b0:977:4b19:97a with SMTP id hs35-20020a1709073ea300b009774b19097amr14712852ejc.73.1687327098230; Tue, 20 Jun 2023 22:58:18 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m6-20020a17090679c600b00988907e3aaesi2084171ejo.428.2023.06.20.22.58.17 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jun 2023 22:58:18 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=DiTZCn6O; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1089E385828E for <ouuuleilei@gmail.com>; Wed, 21 Jun 2023 05:58:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1089E385828E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687327097; bh=cXgeLEvsefyRwv4O7GsOU+eDhorSjQgQOBNN14fTRDA=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=DiTZCn6Ofj+Pr3dLmt/OB0WypIniyGOyTmVNHibXENgSPjlGe3UEhXBIxc8a3iLph PwA6L2EsONAWRUP5lTmgPnDd6ipB5NEW6J53bUzgsVhbOMQflUCo2v9u6g40j+WW+Z YEs96Aw+NJWC+AXJl+vZw6e2YBaLWxEWcfwZsnvo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa.microchip.iphmx.com (esa.microchip.iphmx.com [68.232.154.123]) by sourceware.org (Postfix) with ESMTPS id 6972E3858D1E for <gcc-patches@gcc.gnu.org>; Wed, 21 Jun 2023 05:57:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6972E3858D1E X-IronPort-AV: E=Sophos;i="6.00,259,1681196400"; d="scan'208";a="216951260" X-Amp-Result: SKIPPED(no attachment in message) Received: from unknown (HELO email.microchip.com) ([170.129.1.10]) by esa4.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 20 Jun 2023 22:57:27 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Tue, 20 Jun 2023 22:57:24 -0700 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (10.10.215.89) by email.microchip.com (10.10.87.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21 via Frontend Transport; Tue, 20 Jun 2023 22:57:24 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KJMi7xR9+B9qmgilFRWklg77w52U1+r3ld7PlJUJP536xGSFLsXp8uEX0ppxiicE9TZjqTSqRpglzvPtI9mP/3zjXTvu0Oo+v9/gtSwgFrL1g6g1Qo2YeaRu7oucKCGA5SbrOvNAPMoVUoqBekerJYWD0wfLuqZwGeYFdmKJwN+0EWmUsfz8fYaxb3GF3ewcU7yZu+ValW1iiTvdUHnMO8ngv/jvb6ekOIBrj6kSHhbsvziEueuvkRLGS/yl2qfgniZigL/iCZ4UFO/KBquuzTS/N1RZ8OAeLE3R+daNqU7f9Gqmv4XKrBoFvJ/8RN6WP2gJmS+70+MYZspjSQSONQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=cXgeLEvsefyRwv4O7GsOU+eDhorSjQgQOBNN14fTRDA=; b=FFC9sEsIffHBfPz1kzBnkS/68bXAJ1sP8TEXpBLwOsmiVssFINDwR4ZVJdvD8VvsgfUbfTTn0D/4Sxf4fTCj2zjrwGXnxjVPclPtcspaC4xmeCp7WWwEu4akRaBu1df89lwlx9tmhM9iShV6asrQXQv4WyFACo1DtlvB0NMh9TipgpAGZsgpFLgAf3b40UZwnkb2HIoSR6TnHOK0PBmXSl8i6TvrHEX007laccMLTZKCHDgnB1ARtVQxB0X70ayFUniTyTI8hn81Ixt89WQE2r2Nt9XnXpZzduHahUIlHBRC9wzuGM0R/YG+LDyRD5R25ZQd9bMK7hznAGArLMfD3A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=microchip.com; dmarc=pass action=none header.from=microchip.com; dkim=pass header.d=microchip.com; arc=none Received: from DS0PR11MB7877.namprd11.prod.outlook.com (2603:10b6:8:f4::7) by SJ0PR11MB5647.namprd11.prod.outlook.com (2603:10b6:a03:3af::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6500.37; Wed, 21 Jun 2023 05:57:21 +0000 Received: from DS0PR11MB7877.namprd11.prod.outlook.com ([fe80::c669:ab93:b961:d74b]) by DS0PR11MB7877.namprd11.prod.outlook.com ([fe80::c669:ab93:b961:d74b%3]) with mapi id 15.20.6521.020; Wed, 21 Jun 2023 05:57:20 +0000 To: <gcc-patches@gcc.gnu.org> CC: <richard.guenther@gmail.com> Subject: [PATCH] Update array address space in c_build_qualified_type Thread-Topic: [PATCH] Update array address space in c_build_qualified_type Thread-Index: AQHZpAU9iMRo9TOwNket7bvPnj+Cew== Date: Wed, 21 Jun 2023 05:57:20 +0000 Message-ID: <df9f403f4e3c1f9ad620e8d5e38adaa59be2332b.camel@microchip.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Evolution 3.36.5-0ubuntu1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DS0PR11MB7877:EE_|SJ0PR11MB5647:EE_ x-ms-office365-filtering-correlation-id: 482692e1-1558-4320-33cf-08db721c603a x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: AGlt0g06VOh67eXTRlxtrxFYgio5iH4Z1xs40yquUGjTodybdWZImWvDrppb+1RJVk36+3mw5njX2a/veh2XQtTv/KN9DFFveHpjFgA0zxPdPGWWtrKWiR1dxS9mr+rM2g/NZfKS/mjipaB7xMxr0B1NbOeEDuY/SCfn/Z0gUdfYJGyRu9X6ay/axPLhN1cDMIJgJyBEH/T/p/i0vdJ5h4/oPsHy+J3XWbaPVBRHwTZro1bY4CNyyBL40Dvwk29np8bF3sPbXRRmH6a5G2zfLyx4mCkLFnlJ6NxFIPIwWxbB+xpGHXe+FcYzyNntsgotDuUy2dtJ74WHG7uNdOP84hBIjz2/EgImsKGmPyUKxjDbVZj+rG3B8ICyA5wUD7diX0qXGVyzu3zzWTUpkpsbYAEfpNqsUavye+Z4E6XJ0RDVcmJ8+e4f/v1QtFrjjLgiiNZe/DSKm9/YdCnqZhff77IvKnPAAUwTQXgW+6uocmClHAIDm+GmwG05GyBdAtXTRUftiG9Nb59OlVA5++xCm+Lnn65cm/pr6zRFVsF/X1UGMgBiuJm6C1+YApUCPILnwLk4mR+FvugVxis5lR2UBYpFlGSRuYYUz8M6EQeiUog= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS0PR11MB7877.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230028)(376002)(396003)(39860400002)(366004)(346002)(136003)(451199021)(2906002)(966005)(2616005)(6486002)(86362001)(478600001)(71200400001)(122000001)(38070700005)(36756003)(26005)(186003)(6512007)(6506007)(66446008)(64756008)(8936002)(76116006)(66476007)(66946007)(66556008)(8676002)(5660300002)(4326008)(38100700002)(91956017)(6916009)(316002)(83380400001)(84970400001)(41300700001); DIR:OUT; SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?kDJMMFQ9XvLddfLjUlVYr8qlJNkp?= =?utf-8?q?Jsu1gHY86B1w0Fzku179nU6TFyDIUvxZ7qkmDeYjMj0C6REi9eLkQe23I+SiXmL49?= =?utf-8?q?ZcXa8qrjZAGskQgcGbD5FI81ZX6igir1arNUxUXMi091GUbVLfeGF8DlK0lllfvoi?= =?utf-8?q?iWrooGvZg9oTcqytJliIX1/diSpFgAHfBhPOSWjZvJDkvm4qvvU+zn39K8BICo7qT?= =?utf-8?q?xkNWgU+gck6RdTOK3T7eiwFSrG6bqV5tikCZI43zganLXrdBZPV8waMuwmTZPBHm3?= =?utf-8?q?tkRAYVrzPUTpSnF9pZeP0ontXo0trKiXtdc15PVMD9Era0YEXxjYPbbwwMEY66K++?= =?utf-8?q?ehlxXmkhEJFsnpjqNaDZBRxEYm5ao0obaU8epySByZutao/gRs4syNeBTFnH3Wv2X?= =?utf-8?q?K6mCstc6g2q6h7qJa3HK+cOVT0FHQrTEz1f01+7ODqcfj3aa2HP4rE99lNQfOdGiL?= =?utf-8?q?bgcIi3YLnxD0a0uj17t9jMpPEBeZ1ocRkUnwTLsje1E2mnhb9M1esgoGXGCdBVQ8x?= =?utf-8?q?4q++1TY3NsdFHBOB8Rzef/UyBZyIkKHx82UlPJyuyUKAw/tF2INj3y/p395sVLgiM?= =?utf-8?q?FmfQw4RXHZXymOkmnPqHNLTtn0EUEwQttZdR1e2aMYyAMRsFivHa1eFwM0OMoTBDJ?= =?utf-8?q?sBw6XWbiRWFUWds6BamzgcLrUBq707eajbK6v2j9ePv2ZbaDtnm/9CodmwNiez1jT?= =?utf-8?q?d6nSIw6qXWNdbuLbUCOJlGVdJfWOVcQQK3fJ8z6GU0rdsX0cm//JO6fkBRn7PXH33?= =?utf-8?q?DNKe2mAq3m5VK5X5OrtA+lmyjf/Dr2nQrvaYmKFjemfaPleubyhgy2/pLEgh3LV71?= =?utf-8?q?UQRnskaE+jF4lz4gGw0SCFoiQhXUmd8NgINHWm7aav92Ju++QzOjwnTLjKfZG1qGk?= =?utf-8?q?Uixv+pBs0ZRSXGrSu0iKNn0pNCU+Q47Cj19Bjbro2cXAyFbVWHRIRyAm0yGBHGMIW?= =?utf-8?q?Eqg7tIV4TwkuMBKHDdwtcYuYjEZQHHt0nBN4mXqypb2qu4CJ9SjApoYQxz94DZq8P?= =?utf-8?q?7kMc8fmrRTGQoobouqV1ErUUHL0aiuMTCbFR/Ybm6R/n0j2lKFMPRvTTCinepxX8y?= =?utf-8?q?q+5FRh91o4igYd8eeZuV196r6SuG2tuqbSDZucjSkL+WUIdcJBw2+hklU+0Xehm3A?= =?utf-8?q?JLsTNPrr5TFxNkuqRkeCXegpZmgFvnfztcxoj2j3fnVXHChMYn7NU878UK3nDa17u?= =?utf-8?q?Kwj0df8HxHK0I2GAd18Mzu3HecgcuPgPwu1Qd4YCKVLvbJhdjMWwnkt9+GtMnKTee?= =?utf-8?q?MQIj+ymbxeDzplH0yOAVNw1beannCCXBzCkBLsNf0Vsv8qFBI1jpj1PRiGXGFDcVQ?= =?utf-8?q?laOrnpINFz6iFz81kQeppHviCVl1HcfLie8IsLv/7qAYJENbqmjNLUqwcetxLHvVA?= =?utf-8?q?LMXJ/SmBsgKVP9LdKdeQEptkDCfPKdWdMB/2CE7Tp3FcG25D3ZB0pOqVkzisrQfOS?= =?utf-8?q?9mfCY1RgdENP09CryiOqN+neqZw7VqbWOygyR/zNnWTaPnnwrFroq68y6IYESVOX+?= =?utf-8?q?gnaeqBnVmqEHkFdyOZ2p034Vb/Tk5wYAi5VFwQD0LvNE5hc6E8cSMO8=3D?= Content-Type: text/plain; charset="utf-8" Content-ID: <38433F1C2C41FD46A1BD6A85E2CD4E92@namprd11.prod.outlook.com> Content-Transfer-Encoding: base64 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DS0PR11MB7877.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 482692e1-1558-4320-33cf-08db721c603a X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Jun 2023 05:57:20.2054 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3f4057f3-b418-4d4e-ba84-d55b4e897d88 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ebWJrWbMQqheY0mSIUtunbGXRjj+pZ6LyXNGpIdbEyzEpfmegLQGcuWWAJ2MWO/KgFWjt0zkittPYGf6l3/m7DtoxDcCFezc8iMWa8HiATl8DV54pHE1g+5ok4ZMVfYF X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR11MB5647 X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_PASS, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: "SenthilKumar.Selvaraj--- via Gcc-patches" <gcc-patches@gcc.gnu.org> Reply-To: SenthilKumar.Selvaraj@microchip.com Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769290699029061662?= X-GMAIL-MSGID: =?utf-8?q?1769290699029061662?= |
Series |
Update array address space in c_build_qualified_type
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Li, Pan2 via Gcc-patches
June 21, 2023, 5:57 a.m. UTC
Hi, When c-typeck.cc:c_build_qualified_type builds an array type from its element type, it does not copy the address space of the element type to the array type itself. This is unlike tree.cc:build_array_type_1, which explicitly does TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type); This causes the ICE described in https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86869. struct S { char y[2]; }; extern const __memx struct S *s; extern void bar(const __memx void*); void foo(void) { bar(&s->y); } build_component_ref calls c_build_qualified_type, passing in the array type and quals including the address space (ADDR_SPACE_MEMX in this case). Because of this missing address space copy, the returned array type remains in the generic address space. Later down the line, expand_expr_addr_expr detects the mismatch in address space/mode and tries to convert, and that leads to the ICE described in the bug. This patch sets the address space of the array type to that of the element type. Regression tests for avr look ok. Ok for trunk? Regards Senthil PR 86869 gcc/c/ChangeLog: * c-typeck.cc (c_build_qualified_type): Set TYPE_ADDR_SPACE for ARRAY_TYPE. gcc/testsuite/ChangeLog: * gcc.target/avr/pr86869.c: New test.
Comments
On Wed, Jun 21, 2023 at 7:57 AM <SenthilKumar.Selvaraj@microchip.com> wrote: > > Hi, > > When c-typeck.cc:c_build_qualified_type builds an array type > from its element type, it does not copy the address space of > the element type to the array type itself. This is unlike > tree.cc:build_array_type_1, which explicitly does > > TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (elt_type); > > This causes the ICE described in > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86869. > > struct S { > char y[2]; > }; > > extern const __memx struct S *s; > > extern void bar(const __memx void*); > > void foo(void) { > bar(&s->y); > } > > build_component_ref calls c_build_qualified_type, passing in the > array type and quals including the address space (ADDR_SPACE_MEMX > in this case). Because of this missing address space copy, the > returned array type remains in the generic address space. Later > down the line, expand_expr_addr_expr detects the mismatch in > address space/mode and tries to convert, and that leads to the > ICE described in the bug. > > This patch sets the address space of the array type to that of the > element type. > > Regression tests for avr look ok. Ok for trunk? The patch looks OK to me but please let a C frontend maintainer double-check (I've CCed Joseph for this). Thanks, Richard. > Regards > Senthil > > PR 86869 > > gcc/c/ChangeLog: > > * c-typeck.cc (c_build_qualified_type): Set > TYPE_ADDR_SPACE for ARRAY_TYPE. > > gcc/testsuite/ChangeLog: > > * gcc.target/avr/pr86869.c: New test. > > diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc > index 22e240a3c2a..d4ab1d1bd46 100644 > --- a/gcc/c/c-typeck.cc > +++ b/gcc/c/c-typeck.cc > @@ -16284,6 +16284,7 @@ c_build_qualified_type (tree type, int type_quals, tree orig_qual_type, > > t = build_variant_type_copy (type); > TREE_TYPE (t) = element_type; > + TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type); > > if (TYPE_STRUCTURAL_EQUALITY_P (element_type) > || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain))) > diff --git a/gcc/testsuite/gcc.target/avr/pr86869.c b/gcc/testsuite/gcc.target/avr/pr86869.c > new file mode 100644 > index 00000000000..54cd984276e > --- /dev/null > +++ b/gcc/testsuite/gcc.target/avr/pr86869.c > @@ -0,0 +1,13 @@ > +/* { dg-do compile } */ > +/* { dg-options "-std=gnu99" } */ > + > +extern void bar(const __memx void* p); > + > +struct S { > + char y[2]; > +}; > +extern const __memx struct S *s; > + > +void foo(void) { > + bar(&s->y); > +}
On Wed, 21 Jun 2023, Richard Biener via Gcc-patches wrote: > > This patch sets the address space of the array type to that of the > > element type. > > > > Regression tests for avr look ok. Ok for trunk? > > The patch looks OK to me but please let a C frontend maintainer > double-check (I've CCed Joseph for this). The question would be whether there are any TYPE_QUALS uses in the C front end that behave incorrectly given TYPE_ADDR_SPACE (acting as qualifiers) being set on an array type - conceptually, before C2x, array types are unqualified, only the element types are qualified. The fact that this changed in C2x gives a shortcut to doing that analysis - you don't need to check all TYPE_QUALS uses in the front end, only a limited number of places that might handle qualifiers on arrays that already have conditionals to do things differently in C2x mode. But some sort of analysis of those places, to see how they'd react to an array type itself having TYPE_ADDR_SPACE set, would be helpful. If you're lucky, all those places only care about TYPE_QUALS on the element type and not on the array type itself.
On Wed, 2023-06-21 at 18:37 +0000, Joseph Myers wrote: > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe > > On Wed, 21 Jun 2023, Richard Biener via Gcc-patches wrote: > > > > This patch sets the address space of the array type to that of the > > > element type. > > > > > > Regression tests for avr look ok. Ok for trunk? > > > > The patch looks OK to me but please let a C frontend maintainer > > double-check (I've CCed Joseph for this). > > The question would be whether there are any TYPE_QUALS uses in the C front > end that behave incorrectly given TYPE_ADDR_SPACE (acting as qualifiers) > being set on an array type - conceptually, before C2x, array types are > unqualified, only the element types are qualified. Hmm, but tree.cc:build_array_type_1 sets the address space of the element type to the array type, and the relevant commit's ChangeLog entry (from 2009) says "Inherit array address space from element type." On the avr target, for an array like const __flash int arr[] = {1,2,3}; I can see that the array type gets the address space of the element type already, even before this patch. Surely that must have caused any code that doesn't expect address space in array type quals to be broken then? Regards Senthil
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc index 22e240a3c2a..d4ab1d1bd46 100644 --- a/gcc/c/c-typeck.cc +++ b/gcc/c/c-typeck.cc @@ -16284,6 +16284,7 @@ c_build_qualified_type (tree type, int type_quals, tree orig_qual_type, t = build_variant_type_copy (type); TREE_TYPE (t) = element_type; + TYPE_ADDR_SPACE (t) = TYPE_ADDR_SPACE (element_type); if (TYPE_STRUCTURAL_EQUALITY_P (element_type) || (domain && TYPE_STRUCTURAL_EQUALITY_P (domain))) diff --git a/gcc/testsuite/gcc.target/avr/pr86869.c b/gcc/testsuite/gcc.target/avr/pr86869.c new file mode 100644 index 00000000000..54cd984276e --- /dev/null +++ b/gcc/testsuite/gcc.target/avr/pr86869.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-std=gnu99" } */ + +extern void bar(const __memx void* p); + +struct S { + char y[2]; +}; +extern const __memx struct S *s; + +void foo(void) { + bar(&s->y); +}