From patchwork Tue Nov 13 19:15:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 997380 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-489936-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (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.b="MWYp3P5P"; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ICyhq/qB"; 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 42vcmt5tr1z9s5c for ; Wed, 14 Nov 2018 06:16:29 +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:from :subject:to:message-id:date:mime-version:content-type; q=dns; s= default; b=lETB7cGaUm+5DBCV/s11ccXx2FPI2PO20/zrDr9iU8MDh0+9KdZjh SLIhVfdYPM0v9Ba2rQ0+7DL34aSEcAjO61oc3Tfe6mII0E5FMapmbAeosInqyBhu 4bg4nmv+R6tkE8NUl8jmM4QoLLWLIUUvvB2uPGJiKa4SKeRgAIqzvE= 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:from :subject:to:message-id:date:mime-version:content-type; s= default; bh=X4qL30qrEcTRCLh5vTz+qKEnZPk=; b=MWYp3P5PWGDoU79LwpBz eNBT/hZNQTbOOU1sXBkiSYMXm2Xbcek94h6bd8xuoKgGEp9LLXieoxdelCJmlODB F2C24O23LjYltNUk+Kf2rzPb6WcLgaULp3RaSZ5+aHvL8+8tiN/xJ4z6dQdY8Vyb UVSf9yUtTwbQHa7e3rw7dio= Received: (qmail 52377 invoked by alias); 13 Nov 2018 19:15:51 -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 52327 invoked by uid 89); 13 Nov 2018 19:15:49 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=duration, REF X-HELO: mail-qk1-f193.google.com Received: from mail-qk1-f193.google.com (HELO mail-qk1-f193.google.com) (209.85.222.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 13 Nov 2018 19:15:40 +0000 Received: by mail-qk1-f193.google.com with SMTP id 189so21473536qkj.8 for ; Tue, 13 Nov 2018 11:15:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version; bh=5a9HYnVGy85j403+5Xg9jvdE5Icjm8C0D9kYovhn/vg=; b=ICyhq/qBnET2sFEJzt3KGsU5TlYNaOB8p5WlSZfmHLIgtGv+5hPIzfyJ/GXVBap6JA YDObMic2ACzD35njgFvKxN66Qe26wrq9BwDP6ekALishy5VvGmGEXeBa64kxooI24XCD XG1s4MtklRDzLAZuszPrSBGz74n7f1J4TUuC/cd8vOK1E1vvO2TbXOAaoVPopYAami3/ DCY153uxe7M3ZcyCrquQUzvSi4PimsUtm8i4tWv2CCSFKYI8wvrsttGCcbPayjozj30L CAvY+sC4dlWJO21zHJLVkCAGARzA/lMn8fQG1olWMsob3nFqpvcgoHtQDMxk2IsUYPEU lCng== Received: from localhost.localdomain (184-96-239-209.hlrn.qwest.net. [184.96.239.209]) by smtp.gmail.com with ESMTPSA id n3sm8294862qtc.81.2018.11.13.11.15.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Nov 2018 11:15:37 -0800 (PST) From: Martin Sebor Subject: [PATCH] avoid copying inlining attributes in attribute copy To: Joseph Myers , Gcc Patch List Message-ID: <92db8771-071a-f2f2-dd58-92c9b94b11b4@gmail.com> Date: Tue, 13 Nov 2018 12:15:35 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-IsSubscribed: yes Enabling in Glibc the recent enhancement to detect attribute mismatches in alias declarations (PR 81824) revealed a use case where aliases are being declared for targets declared with the always_inline attribute. Copying the always_inline attribute to the declaration of the alias would then trigger error: always_inline function might not be inlinable [-Werror=attributes] due to the alias not being inlinable in some contexts where (presumably) the target would be. To avoid the warning for this use case the attached patch excludes all attributes that affect inlining from being copied by attribute copy. While testing this I also more thoroughly exercised attribute tls_target (which also came up during the Glibc deployment), and improved the diagnostics for the attribute to make their root cause easier to understand (printing "attribute ignored" alone isn't very informative without also explaining why). Martin PS While testing this I also opened bug 88010 where inlining attributes on aliases seem to be silently ignored in favor of those on their targets. I'm wondering what the expected (or preferred) behavior is. gcc/c-family/ChangeLog: * c-attribs.c (handle_copy_attribute): Exclude inlining attributes. (handle_tls_model_attribute): Improve diagnostics. (has_attribute): Fix a typo. gcc/testsuite/ChangeLog: * gcc.dg/attr-copy-5.c: New test. * gcc.dg/tls/diag-6.c: Adjust expected diagnostics. Index: gcc/c-family/c-attribs.c =================================================================== --- gcc/c-family/c-attribs.c (revision 266033) +++ gcc/c-family/c-attribs.c (working copy) @@ -2239,13 +2239,15 @@ handle_copy_attribute (tree *node, tree name, tree /* Copy decl attributes from REF to DECL. */ for (tree at = attrs; at; at = TREE_CHAIN (at)) { - /* Avoid copying attributes that affect a symbol linkage or - visibility since those in all likelihood only apply to - the target. + /* Avoid copying attributes that affect a symbol linkage, + inlining, or visibility since those in all likelihood + only apply to the target. FIXME: make it possible to specify which attributes to copy or not to copy in the copy attribute itself. */ tree atname = get_attribute_name (at); if (is_attribute_p ("alias", atname) + || is_attribute_p ("always_inline", atname) + || is_attribute_p ("gnu_inline", atname) || is_attribute_p ("ifunc", atname) || is_attribute_p ("visibility", atname) || is_attribute_p ("weak", atname) @@ -2458,17 +2460,26 @@ handle_tls_model_attribute (tree *node, tree name, tree decl = *node; enum tls_model kind; - if (!VAR_P (decl) || !DECL_THREAD_LOCAL_P (decl)) + if (!VAR_P (decl)) { - warning (OPT_Wattributes, "%qE attribute ignored", name); + warning (OPT_Wattributes, "%qE attribute ignored because %qD " + "is not a variable", + name, decl); return NULL_TREE; } + if (!DECL_THREAD_LOCAL_P (decl)) + { + warning (OPT_Wattributes, "%qE attribute ignored because %qD does " + "not have thread storage duration", name, decl); + return NULL_TREE; + } + kind = DECL_TLS_MODEL (decl); id = TREE_VALUE (args); if (TREE_CODE (id) != STRING_CST) { - error ("tls_model argument not a string"); + error ("%qE argument not a string", name); return NULL_TREE; } @@ -2481,7 +2492,9 @@ handle_tls_model_attribute (tree *node, tree name, else if (!strcmp (TREE_STRING_POINTER (id), "global-dynamic")) kind = TLS_MODEL_GLOBAL_DYNAMIC; else - error ("tls_model argument must be one of \"local-exec\", \"initial-exec\", \"local-dynamic\" or \"global-dynamic\""); + error ("%qE argument must be one of %qs, %qs, %qs, or %qs", + name, + "local-exec", "initial-exec", "local-dynamic", "global-dynamic"); set_decl_tls_model (decl, kind); return NULL_TREE; Index: gcc/testsuite/gcc.dg/attr-copy-5.c =================================================================== --- gcc/testsuite/gcc.dg/attr-copy-5.c (nonexistent) +++ gcc/testsuite/gcc.dg/attr-copy-5.c (working copy) @@ -0,0 +1,57 @@ +/* PR middle-end/81824 - Warn for missing attributes with function aliases + Verify that attributes always_inline, gnu_inline, and noinline aren't + copied. Also verify that copying attribute tls_model to a non-thread + variable triggers a warning. + { dg-do compile } + { dg-options "-Wall" } + { dg-require-effective-target tls } */ + +#define ATTR(...) __attribute__ ((__VA_ARGS__)) + +ATTR (always_inline, gnu_inline, noreturn) inline int +finline_noret (void) +{ + __builtin_abort (); + /* Expect no -Wreturn-type. */ +} + +int call_finline_noret (void) +{ + finline_noret (); + /* Expect no -Wreturn-type. */ +} + + +ATTR (copy (finline_noret)) int +fnoret (void); + +int call_fnoret (void) +{ + fnoret (); + /* Expect no -Wreturn-type. */ +} + + +/* Verify that attribute always_inline on an alias target doesn't + get copied and interfere with attribute noinline on the alias + (trigger a warning due to a conflict). */ + +ATTR (always_inline) static inline int +finline (void) { return 0; } + +ATTR (alias ("finline"), noinline) int +fnoinline (void); + +ATTR (copy (finline)) int +fnoinline (void); + + +ATTR (tls_model ("global-dynamic")) __thread int + tls_target; + +ATTR (alias ("tls_target"), copy (tls_target)) extern __thread int + thread_alias; + + +ATTR (alias ("tls_target"), copy (tls_target)) extern int + alias; /* { dg-warning ".tls_model. attribute ignored because .alias. does not have thread storage duration" } */ Index: gcc/testsuite/gcc.dg/tls/diag-6.c =================================================================== --- gcc/testsuite/gcc.dg/tls/diag-6.c (revision 266033) +++ gcc/testsuite/gcc.dg/tls/diag-6.c (working copy) @@ -4,5 +4,5 @@ int v __attribute__((tls_model("initial-exec"))); /* { dg-warning "attribute ignored" } */ typedef int X __attribute__((tls_model("initial-exec"))); /* { dg-warning "attribute ignored" } */ void f(int x __attribute__((tls_model("initial-exec")))); /* { dg-warning "attribute ignored" } */ -__thread int a __attribute__((tls_model(1))); /* { dg-error "tls_model argument not a string" } */ -__thread int b __attribute__((tls_model("unknown"))); /* { dg-error "tls_model argument must be one of" } */ +__thread int a __attribute__((tls_model(1))); /* { dg-error ".tls_model. argument not a string" } */ +__thread int b __attribute__((tls_model("unknown"))); /* { dg-error ".tls_model. argument must be one of" } */