From patchwork Tue Jul 16 11:04:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Oliva X-Patchwork-Id: 1960996 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=bfXU43RO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WNbpw72bLz1xrQ for ; Tue, 16 Jul 2024 21:06:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCD4C385E836 for ; Tue, 16 Jul 2024 11:06:14 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 95E1B3858C33 for ; Tue, 16 Jul 2024 11:05:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95E1B3858C33 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 95E1B3858C33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::630 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721127905; cv=none; b=Lj2ARwlJ+NvxoAvaD4GNMvlDYB2V012K2SlB7zFklRRo2S+E9mK1evdWdnNriAj/6BbE/a5yc2ilRTpxGBvYRsrmoT4300CYQl1cuot6oQTnVcjSRIdNz/4q/GzZKqRWk5HHKdtu0pmdyq/tuCgtIb/r/6NAMbGYm4vRlC8PLIM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721127905; c=relaxed/simple; bh=+HKv0Ic0DRt7YM4Kar5mLdFZGBxSLA3J+9GYKA/bT9I=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Bk179B7TUMfQZ7s6Y33Ljac6xDiemTf1rJdIsEW51ddro6MhK39psNEtZHWv9+O5x6JA1T+VasDJ9NkCvm0BxuBl17FVlWdoug+r1STU7fH/WIR+pn3asu8ldv7uJ7mOvBpw9l1xuSfJw/fpNR8uMfeVrFvVVV/dOtQdvlf9Ea4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1fc2a194750so19250755ad.1 for ; Tue, 16 Jul 2024 04:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1721127900; x=1721732700; darn=gcc.gnu.org; h=mime-version:user-agent:message-id:date:organization:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=YJvozBKTU4Rqmnr6D7uC1+MUGfgpB5eMX24m7u6/8Hw=; b=bfXU43ROhXBm149u87VSr1i6c4o+PkTBdMEaeWqw6BmqtVS31Vcb6a8SVnxNKUlvfu FYwvbgyxh88l2bgRiFxqbFo+QpEuJ9BUaucCHb5gGRvucnMyjyUQnTTxf7BbyR6U+oGk K90AwNxcN+hpYFYBExTR7u8TOuntcjweJ8WNmYUnAPSIJL97IzylcDT/xrhpkz41ANOG fa/nQR5cmh0Ve8IcQ4W2+S0paGHcXfLoUnW6L3gJWBhAvc+TaLi0jZwHe/DbVckUMtGl jz/B+etYiCQTAlNfS7c5rRfUUm19kISEd3kYRjkHuxCCKMG40fgQelf9aA9GCZMLefEQ gW8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1721127900; x=1721732700; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YJvozBKTU4Rqmnr6D7uC1+MUGfgpB5eMX24m7u6/8Hw=; b=JDrAzktmorVoR4OBQbOj2dAye3Q1JONbIUZmiIkIAL849Is6uvK28e4vH58726qeqJ RzQ3WykSvxbbccmdlrXOQNAvoguG3lixzOqwlHXUJVyXdYJXvWX7APcT/EY+9Jnqdq2z mZIqs1ZUzi/xF/sXAiXCyTF3xDaTv6GsBo3fToRDKJslQMkWFaMScMW43sSjLUDDTn2S mkDiBzuQWErroBUTg13YdWu8Oi2qtg3OkXTiOG9YdMPGkVB5AoE5XBXdvr6KjOJ1Eyxu RrMMmiDnLMV8dKNJm3PavcJeSQ9ZnonjEifKTr2+KOFWO3HnDHjsoso3eeKPWfaN+u5h wwXQ== X-Gm-Message-State: AOJu0YyBBvAGONrVu4ZyVxpWHWIWOayT5tbcwi+oWdA7xZjNI3RwlP/3 OIEojGwpuRGeXrshPiSVO2ggesK/28J4GkU7PRbS+KJB64Bh+8wHnhmlNPVHpDE9CtMRmMA1Q72 brex3 X-Google-Smtp-Source: AGHT+IFmlhJTe/vKLoEKBlhqpcN3nOLuAVSRDcyiK33xpnXFrKT0k9aueIH9lTNGwb0Qr+TnMy3Eig== X-Received: by 2002:a17:902:d483:b0:1fb:d126:204 with SMTP id d9443c01a7336-1fc3d9d19b2mr11158055ad.49.1721127900287; Tue, 16 Jul 2024 04:05:00 -0700 (PDT) Received: from free.home ([2804:7f1:218a:d53f:1f12:68c4:3c4:d64a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fc0bc38d93sm55724105ad.210.2024.07.16.04.04.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jul 2024 04:04:59 -0700 (PDT) Received: from livre (livre.home [172.31.160.2]) by free.home (8.15.2/8.15.2) with ESMTPS id 46GB4nR0218348 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 16 Jul 2024 08:04:50 -0300 From: Alexandre Oliva To: gcc-patches@gcc.gnu.org Subject: [PATCH] [strub] adjust all at-calls type variants at once [PR115848] Organization: Free thinker, does not speak for AdaCore Date: Tue, 16 Jul 2024 08:04:49 -0300 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, WEIRD_QUOTING autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org TYPE_ARG_TYPES of type variants must compare equal, according to verify_type, but adjust_at_calls_type didn't preserve this invariant. Adjust the main type variant and propagate TYPE_ARG_TYPES to all variants. While at that, also adjust the canonical type and its variants, and then verify_type. Regstrapped on x86_64-linux-gnu. Ok to install? for gcc/ChangeLog PR c/115848 * ipa-strub.cc (pass_ipa_strub::adjust_at_calls_type_main): Rename from... (pass_ipa_strub::adjust_at_calls_type): ... this. Preserve TYPE_ARG_TYPES across all variants. Adjust TYPE_CANONICAL and verify_type. for gcc/testsuite/ChangeLog PR c/115848 * c-c++-common/strub-pr115848.c: New. * c-c++-common/strub-pr115848-b.c: New. --- gcc/ipa-strub.cc | 41 ++++++++++++++++++++++++- gcc/testsuite/c-c++-common/strub-pr115848-b.c | 6 ++++ gcc/testsuite/c-c++-common/strub-pr115848.c | 8 +++++ 3 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/strub-pr115848-b.c create mode 100644 gcc/testsuite/c-c++-common/strub-pr115848.c diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc index 8fa7bdf530023..15d91c994bf8f 100644 --- a/gcc/ipa-strub.cc +++ b/gcc/ipa-strub.cc @@ -1891,6 +1891,7 @@ public: #undef DEF_IDENT + static inline int adjust_at_calls_type_main (tree); static inline int adjust_at_calls_type (tree); static inline void adjust_at_calls_call (cgraph_edge *, int, tree); static inline void adjust_at_calls_calls (cgraph_node *); @@ -2348,15 +2349,51 @@ strub_watermark_parm (tree fndecl) gcc_unreachable (); } +/* Adjust a STRUB_AT_CALLS function TYPE and all its variants, + preserving TYPE_ARG_TYPES identity, adding a watermark pointer if + it hasn't been added yet. Return the named argument count. */ + +int +pass_ipa_strub::adjust_at_calls_type (tree type) +{ + gcc_checking_assert (same_strub_mode_in_variants_p (type)); + + tree tmain = TYPE_MAIN_VARIANT (type); + tree orig_types = TYPE_ARG_TYPES (tmain); + gcc_checking_assert (TYPE_ARG_TYPES (type) == orig_types); + int named_args = adjust_at_calls_type_main (tmain); + tree mod_types = TYPE_ARG_TYPES (tmain); + + if (mod_types != orig_types) + for (tree other = TYPE_NEXT_VARIANT (tmain); + other != NULL_TREE; other = TYPE_NEXT_VARIANT (other)) + { + gcc_checking_assert (TYPE_ARG_TYPES (other) == orig_types); + TYPE_ARG_TYPES (other) = mod_types; + } + + if (TYPE_CANONICAL (type) + && TYPE_MAIN_VARIANT (TYPE_CANONICAL (type)) != tmain) + { + int ret = adjust_at_calls_type (TYPE_CANONICAL (type)); + gcc_checking_assert (named_args == ret); + } + + if (flag_checking) + verify_type (type); + + return named_args; +} + /* Adjust a STRUB_AT_CALLS function TYPE, adding a watermark pointer if it hasn't been added yet. Return the named argument count. */ int -pass_ipa_strub::adjust_at_calls_type (tree type) +pass_ipa_strub::adjust_at_calls_type_main (tree type) { int named_args = 0; - gcc_checking_assert (same_strub_mode_in_variants_p (type)); + gcc_checking_assert (TYPE_MAIN_VARIANT (type) == type); if (!TYPE_ARG_TYPES (type)) return named_args; diff --git a/gcc/testsuite/c-c++-common/strub-pr115848-b.c b/gcc/testsuite/c-c++-common/strub-pr115848-b.c new file mode 100644 index 0000000000000..9b9e134b3f41a --- /dev/null +++ b/gcc/testsuite/c-c++-common/strub-pr115848-b.c @@ -0,0 +1,6 @@ +/* { dg-skip-if part { *-*-* } } */ +void __attribute__((__strub__)) b(int, int) {} +void c(void); +int main() { + c(); +} diff --git a/gcc/testsuite/c-c++-common/strub-pr115848.c b/gcc/testsuite/c-c++-common/strub-pr115848.c new file mode 100644 index 0000000000000..1586540907213 --- /dev/null +++ b/gcc/testsuite/c-c++-common/strub-pr115848.c @@ -0,0 +1,8 @@ +/* { dg-do link } */ +/* { dg-require-effective-target lto } */ +/* { dg-options "-flto" } */ +/* { dg-additional-sources "strub-pr115848-b.c" } */ + +typedef void __attribute__((__strub__)) a(int, int); +a(b); +void c() { b(0, 0); }