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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 0440F385842B for ; Wed, 27 Apr 2022 16:58:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0440F385842B Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-66-5p3F_6xWNe6aOXG8CJNOFQ-1; Wed, 27 Apr 2022 12:58:22 -0400 X-MC-Unique: 5p3F_6xWNe6aOXG8CJNOFQ-1 Received: by mail-qk1-f200.google.com with SMTP id bk23-20020a05620a1a1700b0067b32f93b90so1532539qkb.16 for ; Wed, 27 Apr 2022 09:58:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=V1rj1eV1Y6cqHdXJYBn4kjihI/V23UERT/fOm0ykjsY=; b=8SL8QI//ZBW3W+eew67Rb5uUj1VPmm2kn9Jl5bQ5zm298ZqH61iYiVJNnpFp3DCRFz 6JDpULVsKEYKogIv5dILDZPc93iRsmhHrEjCaamlJ2JbNfszYjzGX3OwHyeZE+eoUu8T oh5esEkOOBdAY6qbNpgXXgGoLtibTEveEG1lbs0Q6vd69hhE/JkSpPhBYqyQfpyT7nbR yOmfrAORivW0hKoJ/NWx5KW7w88X+lUhxT2kPRf1Lfl6ESsiql+0d51EuE76dZTdfSwy 0FHp+mMkm9nNLsbol5juOjiVih+Iq0/4HfU3Sn/AaS63BAra6TlKS/HSX+LAVtM0u688 HpTQ== X-Gm-Message-State: AOAM530r4NmwUFGzlrmKiwIaV2Oh92JRdjHus8LZ5tMxqR/+ymT7ulSG WGsyOiH5p9foFQlAbV6aGOT6ueENtBJhrOs9WLjgf0rZfWHqcmgpTslDozz9TRRmwiJRllwwfO7 r/jRMZdiMujtsUDlPNA== X-Received: by 2002:a05:620a:404f:b0:69f:1160:73cc with SMTP id i15-20020a05620a404f00b0069f116073ccmr16657247qko.186.1651078701628; Wed, 27 Apr 2022 09:58:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDee2xCCbiTCcPtechISJfsD0K1kask6UWCwlcX/DQx5I1wNylIcZlJzWBtaOW3PaEOuzH9g== X-Received: by 2002:a05:620a:404f:b0:69f:1160:73cc with SMTP id i15-20020a05620a404f00b0069f116073ccmr16657231qko.186.1651078701360; Wed, 27 Apr 2022 09:58:21 -0700 (PDT) Received: from redhat.com ([2601:184:4780:4310::f826]) by smtp.gmail.com with ESMTPSA id o21-20020a05620a0d5500b0069c59fae1a5sm8014076qkl.96.2022.04.27.09.58.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 09:58:20 -0700 (PDT) Date: Wed, 27 Apr 2022 12:58:19 -0400 From: Marek Polacek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: Re: [PATCH RFA] c-family: attribute ((aligned, mode)) [PR100545] Message-ID: References: <20220427151957.795214-1-jason@redhat.com> MIME-Version: 1.0 In-Reply-To: <20220427151957.795214-1-jason@redhat.com> User-Agent: Mutt/2.1.5 (2021-12-30) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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: 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: , X-List-Received-Date: Wed, 27 Apr 2022 16:58:25 -0000 On Wed, Apr 27, 2022 at 11:19:57AM -0400, Jason Merrill via Gcc-patches wrote: > The problem here was that handle_mode_attribute clobbered the changes of any > previous attribute, only copying type qualifiers to the new type. And > common_handle_aligned_attribute had previously set up the typedef, so when > we later called set_underlying_type it saw DECL_ORIGINAL_TYPE set and just > returned, even though handle_mode_attribute had messed up the TREE_TYPE. > So, let's fix handle_mode_attribute to copy attributes, alignment, and > typedefness to the new type. > > Tested x86_64-pc-linux-gnu, OK for trunk now or after 12.1? I think I'd slightly prefer 12.1, it doesn't seem to be a regression. > PR c/100545 > > gcc/c-family/ChangeLog: > > * c-attribs.cc (handle_mode_attribute): Copy attributes, aligned, > and typedef. > * c-common.cc (set_underlying_type): Add assert. > > gcc/testsuite/ChangeLog: > > * c-c++-common/attr-mode-1.c: New test. > --- > gcc/c-family/c-attribs.cc | 15 ++++++++++++++- > gcc/c-family/c-common.cc | 7 ++++--- > gcc/testsuite/c-c++-common/attr-mode-1.c | 3 +++ > 3 files changed, 21 insertions(+), 4 deletions(-) > create mode 100644 gcc/testsuite/c-c++-common/attr-mode-1.c > > diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc > index 111a33f405a..26876d0f309 100644 > --- a/gcc/c-family/c-attribs.cc > +++ b/gcc/c-family/c-attribs.cc > @@ -2199,7 +2199,20 @@ handle_mode_attribute (tree *node, tree name, tree args, > return NULL_TREE; > } > > - *node = build_qualified_type (typefm, TYPE_QUALS (type)); > + /* Copy any quals and attributes to the new type. */ > + *node = build_type_attribute_qual_variant (typefm, TYPE_ATTRIBUTES (type), > + TYPE_QUALS (type)); > + if (TYPE_USER_ALIGN (type)) > + *node = build_aligned_type (*node, TYPE_ALIGN (type)); > + if (typedef_variant_p (type)) > + { > + /* Set up the typedef all over again. */ > + tree decl = TYPE_NAME (type); > + DECL_ORIGINAL_TYPE (decl) = NULL_TREE; > + TREE_TYPE (decl) = *node; > + set_underlying_type (decl); > + *node = TREE_TYPE (decl); > + } > } > > return NULL_TREE; > diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc > index bb0544eeaea..730faa9e87f 100644 > --- a/gcc/c-family/c-common.cc > +++ b/gcc/c-family/c-common.cc > @@ -8153,15 +8153,16 @@ check_missing_format_attribute (tree ltype, tree rtype) > void > set_underlying_type (tree x) > { > - if (x == error_mark_node) > + if (x == error_mark_node || TREE_TYPE (x) == error_mark_node) Maybe error_operand_p? > return; > if (DECL_IS_UNDECLARED_BUILTIN (x) && TREE_CODE (TREE_TYPE (x)) != ARRAY_TYPE) > { > if (TYPE_NAME (TREE_TYPE (x)) == 0) > TYPE_NAME (TREE_TYPE (x)) = x; > } > - else if (TREE_TYPE (x) != error_mark_node > - && DECL_ORIGINAL_TYPE (x) == NULL_TREE) > + else if (DECL_ORIGINAL_TYPE (x)) > + gcc_checking_assert (TYPE_NAME (TREE_TYPE (x)) == x); > + else > { > tree tt = TREE_TYPE (x); > DECL_ORIGINAL_TYPE (x) = tt; > diff --git a/gcc/testsuite/c-c++-common/attr-mode-1.c b/gcc/testsuite/c-c++-common/attr-mode-1.c > new file mode 100644 > index 00000000000..59b20cd99e8 > --- /dev/null > +++ b/gcc/testsuite/c-c++-common/attr-mode-1.c > @@ -0,0 +1,3 @@ > +// PR c/100545 > + > +typedef int fatp_t __attribute__((aligned, mode(SI))); I think you need to add "dg-options -g", otherwise the bug doesn't manifest. Marek