From patchwork Wed Apr 27 15:19:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 53267 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C97893857829 for ; Wed, 27 Apr 2022 15:20:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C97893857829 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1651072832; bh=RiuO62OpkSabNlbduJ4t3OEhQz5y54/nbUuoP/cOXzA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=fK1uXGC7dA0dRQJw5cI5hpp4qW7VyaXUjFPXJsKRt2rc7kPPDYQFHz59tu3GvCLHZ UnSUNtO90GiG2glRnkPDVnd0LKE83wyebxG9Usvf+7WLv3jKo4YQ2PLLIk4JPxbqRO vL37OlQ6pW1/iZMeDVcxj3ifrwiT0rszB92EhzUg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 E7B5D385842B for ; Wed, 27 Apr 2022 15:20:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7B5D385842B Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-382-rsMbCCz7PYm_N_Nco-aIoQ-1; Wed, 27 Apr 2022 11:20:02 -0400 X-MC-Unique: rsMbCCz7PYm_N_Nco-aIoQ-1 Received: by mail-qv1-f70.google.com with SMTP id 13-20020a0562140d6d00b004563de53d74so1477014qvs.11 for ; Wed, 27 Apr 2022 08:20:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=RiuO62OpkSabNlbduJ4t3OEhQz5y54/nbUuoP/cOXzA=; b=AjeUveBA46elwALo0LLM5S2dwmHDpR4GGIwMpC3dfAPCcMrEARBt0gjbOURRjpANil NgmBz7lLrC/pZDvWj5jeT/0dLBCB6ZRmy4hWqAwpO8lwySA0/V29L7KpeMoOr4PdJ79n 1XtvKaE7QD4871i0U1ohPuReoDqFiAfiAD6VvNrZRiOnqqsw9p9bUy/GwuTII+jdkkSa /gWvmyPm8Znw1o/d5PbTHVwPSAJ8Dg4zqBD3/o7P00ZVmSCPqvL48noA/Ctx9J0OtD9X o0H2q80ZvFoYBAFPyC635Rc4mrcuA1g7dwhR6E/h6CT6btlPIdUCSENfgpCR179CWHqq qQAw== X-Gm-Message-State: AOAM530wrTMIujMp472pgPi5cIHwQ7D+APTXdR5AjEay0jF3EgOnF1qh UmM650GJgL8NytolOZpJ3LnVxPNlU3tK4JMT0FbjnvQa3iiPWW0Ym9dJ5c8SZYHIOrQzhhPkFD7 FsHURNNCTubgrpQMUffOCDSGkg9vogqJmO8Ir6IqQt4wHEsOQyFg8Hj1PjlzIpKlCMQ== X-Received: by 2002:a05:622a:40c:b0:2f3:402f:26e2 with SMTP id n12-20020a05622a040c00b002f3402f26e2mr19141737qtx.309.1651072801698; Wed, 27 Apr 2022 08:20:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfWvzOQvTw/e9wOBn7+eeI+BXACxK3MqWcpm01ELCA+E+R6zQs/jh0p22atp/SB7FCWoNOXQ== X-Received: by 2002:a05:622a:40c:b0:2f3:402f:26e2 with SMTP id n12-20020a05622a040c00b002f3402f26e2mr19141707qtx.309.1651072801245; Wed, 27 Apr 2022 08:20:01 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id y18-20020ac85f52000000b002ed08a7dc8dsm9815505qta.13.2022.04.27.08.19.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 08:20:00 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH RFA] c-family: attribute ((aligned, mode)) [PR100545] Date: Wed, 27 Apr 2022 11:19:57 -0400 Message-Id: <20220427151957.795214-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.4 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-Patchwork-Original-From: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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? 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 base-commit: 6a460a2007dd9c527c5f9d5bbbedb852db7c1373 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) 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)));