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 602D6385803F for ; Mon, 15 Jan 2024 22:43:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 602D6385803F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 602D6385803F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705358607; cv=none; b=PCzn/S15omfgIwK21OKH3ta37nCZ0jjRo2vFesfXqKsz7lwoqwf25FCo1555PP1KvT+SGm2sIwEfwXN2N8YssInJKcV9hPdwBpDDOEcxlif4cDVsjp1KFTlcfNV1FH1Qo8OZPm07MEFRpJnxE/PwF+KMadiXfCyLKg5WJ75ahGM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705358607; c=relaxed/simple; bh=Up8zz1IwDBDo18DO0KRBJtW0RMUqWOBJBiY1Ab47HZ4=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=Bnd7zePhNVe8tFRR3LEjgpBinpVs6yR0MwjEVdidzTiYOBOPWtHJzifs2jcIND//iv2gSBxGEobWzoW2cWjWbrIRhrXU2ki7zy8+JWnTOMwpGyurJimCqkPCQV8woiDZVOPsNgZmfhU+t7orpbD3XJ1GrpKslTWETE03OlVbxH4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705358605; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tv8Z5507vFvFHKubaa+vn7ZpHskorbWJ3fnEd/SKAXE=; b=DIF8j8yxR3S6L9JuejD27Oeq1OMUdS6hT4D18eean3/S9HViu1x5zSgkIpYqZpPsFr57X4 GIAqWdAMtAuApgY8oFemC6fVj4Gnt+EyCpxxnLEgske6ey3YpifzQe1xZdZgNkv0LbGZ1O sMOjlf4XaDQGHYKyOy6HSyFTpIPQP4E= Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-60-gjCoMWGsNJ-zJhB_h5pSJA-1; Mon, 15 Jan 2024 17:43:23 -0500 X-MC-Unique: gjCoMWGsNJ-zJhB_h5pSJA-1 Received: by mail-qv1-f71.google.com with SMTP id 6a1803df08f44-6815c3dd94eso28969966d6.0 for ; Mon, 15 Jan 2024 14:43:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705358603; x=1705963403; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Tv8Z5507vFvFHKubaa+vn7ZpHskorbWJ3fnEd/SKAXE=; b=b9JNRlPKkE/C670vi+Ip/C4f7SehywUGRvCzzJx7Ai/LLX3tHc8CO5MxScHoqZdHWr n7dXRPThn+g9DBTLoaZmB/SGlIpwYdBeMVnjQcwAHLj+5NzSysBagJqI90sVzhY+9bc9 65iz+WDFlDGhrbghgYqWFAlVUjQiivV5EN4om4TvLxjQLnEmPqdcwrZXhSQMWTo+0a5g mKEy04urHH9it6KiBPP7Kw1xar/q3ijmfrEFFjs3eUJQY+mRNGwsIwdLHj+7dn3BCPvx DpvlRg2jxz0QW30EIzbdUuPxELVBO6a33M8LuQG9NHuLx8Au+WagNj1BtXZdDGCoquZB 5+0Q== X-Gm-Message-State: AOJu0YxEkP5+bYTgSb7vvL/PXLsbUdJ6Tgd159GZWG8h/00XMniXufe0 P1jXkRZnkrScU9o7Ep1g3IW5cJdCDrSFhBUpmmGL34VdM80mLEKXcJHH3lfV3JGiqx2+/oSIiWX /lApLKip0ycYXG5k1vfi7TDOSKw== X-Received: by 2002:a05:6214:3014:b0:681:5aa6:46f1 with SMTP id ke20-20020a056214301400b006815aa646f1mr4059996qvb.29.1705358602933; Mon, 15 Jan 2024 14:43:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGy3a8Tl2/sXhMU7LIQ473qT9N3ET646F/GpSCt9dYqguoxQ0kmZOvnOAzsWkRPOztaDu7SnQ== X-Received: by 2002:a05:6214:3014:b0:681:5aa6:46f1 with SMTP id ke20-20020a056214301400b006815aa646f1mr4059988qvb.29.1705358602726; Mon, 15 Jan 2024 14:43:22 -0800 (PST) Received: from [192.168.1.146] (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id kk23-20020a056214509700b00680b2339789sm3639483qvb.22.2024.01.15.14.43.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 15 Jan 2024 14:43:22 -0800 (PST) Message-ID: <01c21dac-2f22-4961-9b52-50afffad8f19@redhat.com> Date: Mon, 15 Jan 2024 17:43:21 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c-family: copy attribute diagnostic fixes [PR113262] To: Jakub Jelinek , "Joseph S. Myers" , Marek Polacek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_SORBS_WEB,SPF_HELO_NONE,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 List-Id: On 1/9/24 03:52, Jakub Jelinek wrote: > Hi! > > The copy attributes is allowed on decls as well as types and even has > checks whether decl (set to *node) is DECL_P or TYPE_P, but for diagnostics > unconditionally uses DECL_SOURCE_LOCATION (decl), which obviously only works > if it applies to a decl. In the C++ front-end location_of checks to see if the type has a TYPE_MAIN_DECL to get a location from, you might do that if !DECL_P? OK either way. > The following patch fixes that, bootstrapped/regtested on x86_64-linux and > i686-linux, ok for trunk? > > 2024-01-09 Jakub Jelinek > > PR c/113262 > * c-attribs.cc (handle_copy_attribute): Don't use > DECL_SOURCE_LOCATION (decl) if decl is not DECL_P, use input_location > instead. Formatting fixes. > > * gcc.dg/pr113262.c: New test. > > --- gcc/c-family/c-attribs.cc.jj 2024-01-03 12:07:02.020736256 +0100 > +++ gcc/c-family/c-attribs.cc 2024-01-08 22:10:04.789616664 +0100 > @@ -3143,13 +3143,14 @@ handle_copy_attribute (tree *node, tree > if (ref == error_mark_node) > return NULL_TREE; > > + location_t loc = input_location; > + if (DECL_P (decl)) > + loc = DECL_SOURCE_LOCATION (decl); > if (TREE_CODE (ref) == STRING_CST) > { > /* Explicitly handle this case since using a string literal > as an argument is a likely mistake. */ > - error_at (DECL_SOURCE_LOCATION (decl), > - "%qE attribute argument cannot be a string", > - name); > + error_at (loc, "%qE attribute argument cannot be a string", name); > return NULL_TREE; > } > > @@ -3160,10 +3161,8 @@ handle_copy_attribute (tree *node, tree > /* Similar to the string case, since some function attributes > accept literal numbers as arguments (e.g., alloc_size or > nonnull) using one here is a likely mistake. */ > - error_at (DECL_SOURCE_LOCATION (decl), > - "%qE attribute argument cannot be a constant arithmetic " > - "expression", > - name); > + error_at (loc, "%qE attribute argument cannot be a constant arithmetic " > + "expression", name); > return NULL_TREE; > } > > @@ -3171,12 +3170,11 @@ handle_copy_attribute (tree *node, tree > { > /* Another possible mistake (but indirect self-references aren't > and diagnosed and shouldn't be). */ > - if (warning_at (DECL_SOURCE_LOCATION (decl), OPT_Wattributes, > + if (warning_at (loc, OPT_Wattributes, > "%qE attribute ignored on a redeclaration " > - "of the referenced symbol", > - name)) > - inform (DECL_SOURCE_LOCATION (node[1]), > - "previous declaration here"); > + "of the referenced symbol", name) > + && DECL_P (node[1])) > + inform (DECL_SOURCE_LOCATION (node[1]), "previous declaration here"); > return NULL_TREE; > } > > @@ -3196,7 +3194,8 @@ handle_copy_attribute (tree *node, tree > ref = TREE_OPERAND (ref, 1); > else > break; > - } while (!DECL_P (ref)); > + } > + while (!DECL_P (ref)); > > /* For object pointer expressions, consider those to be requests > to copy from their type, such as in: > @@ -3228,8 +3227,7 @@ handle_copy_attribute (tree *node, tree > to a variable, or variable attributes to a function. */ > if (warning (OPT_Wattributes, > "%qE attribute ignored on a declaration of " > - "a different kind than referenced symbol", > - name) > + "a different kind than referenced symbol", name) > && DECL_P (ref)) > inform (DECL_SOURCE_LOCATION (ref), > "symbol %qD referenced by %qD declared here", ref, decl); > @@ -3279,9 +3277,7 @@ handle_copy_attribute (tree *node, tree > } > else if (!TYPE_P (decl)) > { > - error_at (DECL_SOURCE_LOCATION (decl), > - "%qE attribute must apply to a declaration", > - name); > + error_at (loc, "%qE attribute must apply to a declaration", name); > return NULL_TREE; > } > > --- gcc/testsuite/gcc.dg/pr113262.c.jj 2024-01-08 22:19:07.414588762 +0100 > +++ gcc/testsuite/gcc.dg/pr113262.c 2024-01-08 22:18:51.327815573 +0100 > @@ -0,0 +1,6 @@ > +/* PR c/113262 */ > +/* { dg-do compile } */ > +/* { dg-options "" } */ > + > +int [[gnu::copy ("")]] a; /* { dg-error "'copy' attribute argument cannot be a string" } */ > + > > Jakub >