From patchwork Wed Feb 5 01:05:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1233627 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-518921-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=hv5G2Xb6; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=tqdhNdb9; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48C3JY2qwDz9sSN for ; Wed, 5 Feb 2020 12:05:17 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=FOSai+N38AtpvGKUgmqHudm1lvdsjxdZReYuyrZpX3lxgyR3Mg DaXMr7C5qgpEN3lhLOADi24fzVgCLSSzfzTUMiB+afXCeGBrnRn61YGOQuMKknBd x6mnVCZvK548VTYxM01qyLgO40LiX3AKwKlp61eYKX1UZPdcQa0ClHLyo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=DNU5WyM6EHB9fAseb3AlzzHZ1zA=; b=hv5G2Xb6Hd/2U+3z93tN kbEjXVwm7JHti0Kb6ZnFH3kZZOkds19mxU4V5SEV+ChpCLv38h6yyq8RYRamufBr pm7XIlprR/rqx2jzWNUZrUA7gSY/vgttThep6+vlmxz9kz50XIG4RBRdVzEH9D1J CaLyGTJJPSQDaPoVABFYorU= 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-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@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== 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: Tue, 4 Feb 2020 18:05:04 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 X-IsSubscribed: yes 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 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,