public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-8381] c-family: copy attribute diagnostic fixes [PR113262]
@ 2024-03-02 0:38 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2024-03-02 0:38 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:7d49a382a6b1b08bda6761b93c27de13397aa630
commit r13-8381-g7d49a382a6b1b08bda6761b93c27de13397aa630
Author: Jakub Jelinek <jakub@redhat.com>
Date: Tue Jan 9 15:37:04 2024 +0100
c-family: copy attribute diagnostic fixes [PR113262]
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.
2024-01-09 Jakub Jelinek <jakub@redhat.com>
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.
(cherry picked from commit c9fc7f398e8b330ff12ec8a29bfa058b6daf6624)
Diff:
---
gcc/c-family/c-attribs.cc | 32 ++++++++++++++------------------
gcc/testsuite/gcc.dg/pr113262.c | 6 ++++++
2 files changed, 20 insertions(+), 18 deletions(-)
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 072cfb69147..67709912a11 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -2892,13 +2892,14 @@ handle_copy_attribute (tree *node, tree name, tree args,
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;
}
@@ -2909,10 +2910,8 @@ handle_copy_attribute (tree *node, tree name, tree args,
/* 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;
}
@@ -2920,12 +2919,11 @@ handle_copy_attribute (tree *node, tree name, tree args,
{
/* 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;
}
@@ -2945,7 +2943,8 @@ handle_copy_attribute (tree *node, tree name, tree args,
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:
@@ -2977,8 +2976,7 @@ handle_copy_attribute (tree *node, tree name, tree args,
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);
@@ -3028,9 +3026,7 @@ handle_copy_attribute (tree *node, tree name, tree args,
}
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;
}
diff --git a/gcc/testsuite/gcc.dg/pr113262.c b/gcc/testsuite/gcc.dg/pr113262.c
new file mode 100644
index 00000000000..ee55183b587
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr113262.c
@@ -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" } */
+
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-03-02 0:38 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-02 0:38 [gcc r13-8381] c-family: copy attribute diagnostic fixes [PR113262] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).