public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] document that alias and target must have the same type
@ 2020-02-05  1:05 Martin Sebor
  2020-02-05 20:13 ` Martin Sebor
  2020-02-13 22:45 ` Sandra Loosemore
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Sebor @ 2020-02-05  1:05 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 440 bytes --]

GCC diagnoses declarations of function aliases whose type doesn't
match that of the target (ditto for attribute weakref).  It doesn't
yet diagnose such incompatbilities for variable aliases but that's
just an oversight that I will try to remember to correct in GCC 11.
The attached patch updates the manual to make it clear that
aliases must have the same type as their targets, or the behavior
is undefined (and may be diagnosed).

Martin

[-- Attachment #2: gcc-doc-attr-alias.diff --]
[-- Type: text/x-patch, Size: 2877 bytes --]

gcc/ChangeLog:

	* doc/extend.texi (attribute alias, weak, weakref): Mention that
	the target of an alias must have the same type as the alias itself.

diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index ec99c38a607..6f602140bfa 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2558,7 +2558,9 @@ __attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (c
 @item alias ("@var{target}")
 @cindex @code{alias} function attribute
 The @code{alias} attribute causes the declaration to be emitted as an
-alias for another symbol, which must be specified.  For instance,
+alias for another symbol, which must have been previously declared with
+the same type.  Declaring an alias with a different type than the target
+is undefined and may be diagnosed.  For instance,
 
 @smallexample
 void __f () @{ /* @r{Do something.} */; @}
@@ -3922,9 +3924,10 @@ results in warning on line 5.
 The @code{weak} attribute causes the declaration to be emitted as a weak
 symbol rather than a global.  This is primarily useful in defining
 library functions that can be overridden in user code, though it can
-also be used with non-function declarations.  Weak symbols are supported
-for ELF targets, and also for a.out targets when using the GNU assembler
-and linker.
+also be used with non-function declarations.  The overriding symbol must
+have the same type as the declaration of the weak symbol.  Weak symbols
+are supported for ELF targets, and also for a.out targets when using
+the GNU assembler and linker.
 
 @item weakref
 @itemx weakref ("@var{target}")
@@ -3932,7 +3935,8 @@ and linker.
 The @code{weakref} attribute marks a declaration as a weak reference.
 Without arguments, it should be accompanied by an @code{alias} attribute
 naming the target symbol.  Optionally, the @var{target} may be given as
-an argument to @code{weakref} itself.  In either case, @code{weakref}
+an argument to @code{weakref} itself.  The the @var{target} must have
+the same type as the declaration.  In either case, @code{weakref}
 implicitly marks the declaration as @code{weak}.  Without a
 @var{target}, given as an argument to @code{weakref} or to @code{alias},
 @code{weakref} is equivalent to @code{weak}.
@@ -3951,7 +3955,9 @@ definition to be given for the target symbol.  If the target symbol is
 only referenced through weak references, then it becomes a @code{weak}
 undefined symbol.  If it is directly referenced, however, then such
 strong references prevail, and a definition is required for the
-symbol, not necessarily in the same translation unit.
+symbol, not necessarily in the same translation unit.  The definition
+must have the same type as the alias, otherwise the behavior is
+undefined.
 
 The effect is equivalent to moving all references to the alias to a
 separate translation unit, renaming the alias to the aliased symbol,

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-02-15  0:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05  1:05 [PATCH] document that alias and target must have the same type Martin Sebor
2020-02-05 20:13 ` Martin Sebor
2020-02-12 21:02   ` [PING PATCH] " Martin Sebor
2020-02-13 22:55   ` [PATCH] " Sandra Loosemore
2020-02-14 18:30     ` Martin Sebor
2020-02-15  0:08       ` Sandra Loosemore
2020-02-13 22:45 ` Sandra Loosemore

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).