[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 Martin Sebor changed: What|Removed |Added Known to fail||10.2.0, 7.3.0, 8.2.0, 9.1.0 Target Milestone|--- |11.0 Resolution|--- |FIXED Known to work||11.0 Status|NEW |RESOLVED --- Comment #11 from Martin Sebor --- Fixed for GCC 11 in r11-3239.
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #10 from CVS Commits --- The master branch has been updated by Martin Sebor : https://gcc.gnu.org/g:71ad0b5dde449ee1f6b755a99f5c52152e375835 commit r11-3239-g71ad0b5dde449ee1f6b755a99f5c52152e375835 Author: Martin Sebor Date: Wed Sep 16 14:04:01 2020 -0600 Detect conflicts between incompatible uses of the same attribute (PR c/78666). Resolves: PR c/78666 - conflicting attribute alloc_size accepted PR c/96126 - conflicting attribute section accepted on redeclaration gcc/c-family/ChangeLog: PR c/78666 PR c/96126 * c-attribs.c (validate_attr_args): New function. (validate_attr_arg): Same. (handle_section_attribute): Call it. Introduce a local variable. (handle_alloc_size_attribute): Same. (handle_alloc_align_attribute): Same. gcc/testsuite/ChangeLog: PR c/78666 PR c/96126 * gcc.dg/attr-alloc_align-5.c: New test. * gcc.dg/attr-alloc_size-13.c: New test. * gcc.dg/attr-section.c: New test. * c-c++-common/builtin-has-attribute-3.c: Add xfails due to expected warnings to be cleaned up.
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 Martin Sebor changed: What|Removed |Added Keywords||patch --- Comment #9 from Martin Sebor --- Patch: https://gcc.gnu.org/pipermail/gcc-patches/2020-July/549686.html
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 Marek Polacek changed: What|Removed |Added Status|ASSIGNED|NEW Assignee|mpolacek at gcc dot gnu.org|unassigned at gcc dot gnu.org
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 Martin Sebor changed: What|Removed |Added See Also||https://gcc.gnu.org/bugzill ||a/show_bug.cgi?id=81871 --- Comment #8 from Martin Sebor --- Whoops. This bug is about alloc_size and my comment about alloc_align. I think that needs a bug of its own. I opened pr81871 for it.
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #7 from Martin Sebor --- The following nonsensical declaration is also not diagnosed: void __attribute__ ((alloc_align (1))) f (void*); The attribute handler should check that the referenced argument has integer type and that the function returns a pointer.
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #6 from joseph at codesourcery dot com --- On Thu, 8 Dec 2016, msebor at gcc dot gnu.org wrote: > But what is specifying multiple declarations of the same function with > different sets of attributes supposed to mean? Is it supposed to apply the > union of all of them? How should conflicts be resolved? Should the rules be > expected to be consistent across attributes with different names? It should be the result of merging them (taking the union), with conflicts diagnosed. What conflicts depends on the attribute in question. We have e.g. the comp_type_attributes hook for targets to use to detect conflicts (which x86 uses for regparm and other calling convention attributes). Note that glibc relies on being able to apply both attributes (hidden visibility, at least) and asm renaming to built-in functions after their built-in and explicit declarations (see include/string.h).
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #5 from Martin Sebor --- They sure are! (We should document it.) But what is specifying multiple declarations of the same function with different sets of attributes supposed to mean? Is it supposed to apply the union of all of them? How should conflicts be resolved? Should the rules be expected to be consistent across attributes with different names? FWIW, I would be inclined to accept just the set of attributes on the first declaration and ignore all the others (with a warning), and give an error on conflicts in the same declaration. Alternatively, take a union of non-conflicting attributes across all declarations and warn about conflicts. This would suffer from the problem that if the function were called after only a subset of its declarations were seen only the set of attributes seen so far would likely apply (and it would likely change with optimization and inlining.)
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #4 from joseph at codesourcery dot com --- Multiple format attributes for the same function, naming different arguments as a format string, are perfectly valid; they mean the function uses multiple format strings (each of which has to match the arguments indicated by the attribute).
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #3 from Martin Sebor --- Attribute format suffers from a similar problem. (I'm not looking for ways to break things, btw., but rather trying to come up with a test to exercise my patch for bug 78673 in whose review Jeff pointed out I wasn't handling attribute nonnull quite right. I'm looking at how other attributes are being handled to make sure they're all consistent.) $ cat a.c && /build/gcc-git/gcc/xgcc -B /build/gcc-git/gcc -S -Wall -Wextra a.c #define P(f, a) __attribute__ ((format (printf, f, a))) void P (1, 3) P (2, 3) f1 (const char*, const char *, ...); void P (1, 3) f2 (const char*, const char *, ...); void P (2, 3) f2 (const char*, const char *, ...); void g (void) { f1 ("%i", "%s", "123"); f2 ("%i", "%s", "123"); } a.c: In function ‘g’: a.c:10:9: warning: format ‘%i’ expects argument of type ‘int’, but argument 3 has type ‘char *’ [-Wformat=] f1 ("%i", "%s", "123"); ~^ ~ %s a.c:12:9: warning: format ‘%i’ expects argument of type ‘int’, but argument 3 has type ‘char *’ [-Wformat=] f2 ("%i", "%s", "123"); ~^ ~ %s
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 Marek Polacek changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |mpolacek at gcc dot gnu.org
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 --- Comment #2 from Marek Polacek --- And nonnull, sentinel, destructor, constructor too.
[Bug c/78666] conflicting attribute alloc_size accepted
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78666 Marek Polacek changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2016-12-05 CC||mpolacek at gcc dot gnu.org Ever confirmed|0 |1 --- Comment #1 from Marek Polacek --- diagnose_mismatched_attributes should diagnose this -- it needs to look at TYPE_ATTRIBUTES, too. At least assume_aligned and alloc_align should be diagnosed, too.