From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 96809 invoked by alias); 5 Feb 2020 01:05:09 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 96795 invoked by uid 89); 5 Feb 2020 01:05:09 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-18.8 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f174.google.com Received: from mail-qk1-f174.google.com (HELO mail-qk1-f174.google.com) (209.85.222.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 05 Feb 2020 01:05:08 +0000 Received: by mail-qk1-f174.google.com with SMTP id j20so218872qka.10 for ; Tue, 04 Feb 2020 17:05:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=ji/jzL0/bOpDsZvxZV6ktu21t+RH4alNAJwjbtUvAEY=; b=tqdhNdb9BapXTZYApN+i9jym2jGsGMir2rLDjcQMtFgsu+BRONmLAkqplVsuUZlFMB lHcQfDGuyByKwm5CSej/vlbu3zwQ7n/LPSJVvZEyEfqyAK8ZZn1om1kuH7Q5NrY0QUvt YfSC4MForn3CgczZfOZFY0ZeOU3hPoaV/NNE3NpLXKeh4SFY3QkR5d4fDbreBVBD17FH nYK/phNIDQoyCu0S2RI0XNzK5ruOTYuaFScmpJpHLJxwJ14aS259y47/vAG2q7zKQRPT Tp6Kq5rz92l2/NC187fWdKyLvT1UACmJCP9Zyly7wHuDj01K4RIIQlZqhihHie5CnN7B fq8Q== Return-Path: Received: from [192.168.0.41] (174-16-112-158.hlrn.qwest.net. [174.16.112.158]) by smtp.gmail.com with ESMTPSA id m16sm11826848qka.8.2020.02.04.17.05.05 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Feb 2020 17:05:05 -0800 (PST) To: gcc-patches From: Martin Sebor Subject: [PATCH] document that alias and target must have the same type Message-ID: <850a7bd4-9759-eb9e-54ac-e3022b2fcb83@gmail.com> Date: Wed, 05 Feb 2020 01:05:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------A90397DC63CF9EE1699739AE" X-IsSubscribed: yes X-SW-Source: 2020-02/txt/msg00231.txt.bz2 This is a multi-part message in MIME format. --------------A90397DC63CF9EE1699739AE Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 440 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 --------------A90397DC63CF9EE1699739AE Content-Type: text/x-patch; name="gcc-doc-attr-alias.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="gcc-doc-attr-alias.diff" Content-length: 2877 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, --------------A90397DC63CF9EE1699739AE--