The attached patch corrects a logic error in the validation
of the new attribute access where the code incorrectly expects
the human readable representation of the attribute to match
the terse internal representation of the positional argument.

Committed in ra280124 after bootstrapping it and running
the testsuite with no regressions.

Martin
PR c/93132 - bogus `attribute((access))' warning when size-index is specified

gcc/c-family/ChangeLog:

	PR c/93132
	* c-attribs.c (append_access_attrs): Validate against the translated
	access string rather than the human-readable representation.

gcc/testsuite/ChangeLog:

	PR c/93132
	* gcc.dg/attr-access-read-only-2.c: New test.

Index: gcc/c-family/c-attribs.c
===================================================================
--- gcc/c-family/c-attribs.c	(revision 280108)
+++ gcc/c-family/c-attribs.c	(working copy)
@@ -3970,14 +3970,15 @@ append_access_attrs (tree t, tree attrs, const cha
 	      return NULL_TREE;
 	    }
 
-	  if (n2 && strncmp (attrstr + n1 + 1, pos + n1, n2))
+	  if (n2 && strncmp (attrspec + n1 + 1, pos + n1, n2))
 	    {
 	      /* Mismatch in the value of the size argument.  */
 	      auto_diagnostic_group d;
 	      if (warning (OPT_Wattributes,
-			   "attribute %qs mismatch positional argument "
+			   "attribute %qs mismatched positional argument "
 			   "values %i and %i",
-			   attrstr, atoi (attrstr + n1 + 1), atoi (pos + n1))
+			   attrstr, atoi (attrspec + n1 + 1) + 1,
+			   atoi (pos + n1) + 1)
 		  && DECL_P (t))
 		inform (DECL_SOURCE_LOCATION (t),
 			"previous declaration here");
Index: gcc/testsuite/gcc.dg/attr-access-read-only-2.c
===================================================================
--- gcc/testsuite/gcc.dg/attr-access-read-only-2.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/attr-access-read-only-2.c	(working copy)
@@ -0,0 +1,16 @@
+/* PR c/93132 - bogus 'attribute((access))' warning when size-index
+   is specified
+   { dg-do compile }
+   { dg-options "-Wall" } */
+
+void __attribute__ ((access (read_only, 1, 5)))
+f (void*, int, int, int, int);   // { dg-message "previous declaration" }
+
+void __attribute__ ((access (read_only, 1, 3)))
+f (void*, int, int, int, int);   // { dg-warning "attribute 'access\\\(read_only, 1, 3\\\)' mismatched positional argument values 3 and 5" }
+
+void __attribute__ ((access (read_only, 1, 4)))
+f (void*, int, int, int, int);   // { dg-warning "attribute 'access\\\(read_only, 1, 4\\\)' mismatched positional argument values 4 and 5" }
+
+void __attribute__ ((access (read_only, 1, 5)))
+f (void*, int, int, int, int);

Reply via email to