From patchwork Wed May 29 13:30:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1941261 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=VHgOxBUK; 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 4Vq9HY3HYhz20Pc for ; Wed, 29 May 2024 23:30:33 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AECC3384AB44 for ; Wed, 29 May 2024 13:30:31 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 6D3D23858C50 for ; Wed, 29 May 2024 13:30:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6D3D23858C50 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 6D3D23858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716989414; cv=none; b=sKOZlPDlOrBHJM9b1/M0Ccfr1+1IgtZOn113v+VNN2PBmW7rD7+BIKtr0CGCOJ9zySqiiznhiboeYP+npH/nFZ91gJb932Oh55MbiUAqZOgNOkuxR3fat1vmNpw6rQ8RLv3PQFiZsTIYoIg4vNMX/Rft0hPIN2JlVSCo3YQLt/c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716989414; c=relaxed/simple; bh=eiIwjs9rc9sDxMVFXju2CBjJwXiPAtndlBXl1ig1am8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tdPYtgEfW3XNAMySiqInrvP5Q+XlgGdtraCHZH3ciEQo9Kxz+C19vx5TizSMW5LBF3GKWeeEOuQYRK3WS0tXySV9g8UKvL9TKl62JgtwNWCupnDUPGbTJKnBMgasc6bsHRQ3rCte4AwwCs0ccbY1eJ/v5JU1oz/AYrDab4BkVCc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1f082d92864so15176955ad.1 for ; Wed, 29 May 2024 06:30:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1716989411; x=1717594211; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=RqqA1x7oBxYwchpIqqx3XZNfKOx1c6ddJAo08Jw3A4o=; b=VHgOxBUK9AO9EZK9XvdCn0BKIXuWW4DJMs7xx5SrlpAkgkAg0N2+JTq79jyTvthFpZ /ST/GjihQQnVMQ1ZnKhtg2X72F3qwMZs+WU0Myh08zq64u44v1zKzs3kOBfJD+nfxvQv g/MKNQ7kBJJqDRE7CL8T4SnUUawnQvSgbZj+8nCI0Z7w7QaL/erWKkteeZWRP4LnXJnv PvHPYfEBh8d0vuRM6POmNX9qH1FfbsZv9TJyDuQCpD7NcWEA/TBjTmCvlLHDTfpSmRjt 1XQJklMUSiEvH9WjkQkg3XsOcmmvyvebVkfKRHcf5afokq6/7/8Q9USgYuMC1RzJ6O/Y lMgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716989411; x=1717594211; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RqqA1x7oBxYwchpIqqx3XZNfKOx1c6ddJAo08Jw3A4o=; b=PnxvNItY0Hg2nyPrg68p0IqDYuN3Zvt9agPXX7xaK5CvqUuX63Uk/6XXu2xBZ2WrLK y/qqTQ2UXI7X7rbVqSbwO+eakbCxTLlPGaPdJ2UF4FInzzpOF6GzZkkCpLU7M5X1Uv1e PAHo4I7kgg2Wjh6SyWVAH1Y46iZP1o6BI3ejWJVTCscEYj0tI/lGKvTbLzFrJOb/Q9bc xfJv2+m0YOxzByfYa3e2rYE27qr47b23bRQfeUJvM7euGr6WXrbzwv/in1gahQcSKDcX G8BMShHc/hjHTNVDWCbgdAcnPKD5SBonPlUsY//Fbiltg2mbBXjBJnIQo3m16uoQnRj5 Bkaw== X-Gm-Message-State: AOJu0YxwkTw0YegP6/a928jyQeispTd8lH3I3pS3P7DKnoti2PqDKtUm MXNGev9fOKreBEcKD1yc2iPCV0CmFVEqncbsw7m2t+nEWegMuWXn95s/ojnwZMqKf+Id9utH8pU = X-Google-Smtp-Source: AGHT+IFAKMKkHMtKBGDUfQRl0nAKlTM8Ak4s4VcZZn3dMeeHivo3dtrNIZJH8w8w5YQpFTRaFO3EOw== X-Received: by 2002:a17:903:1251:b0:1e6:11ae:dcde with SMTP id d9443c01a7336-1f4497dd043mr174273105ad.58.1716989410983; Wed, 29 May 2024 06:30:10 -0700 (PDT) Received: from fomalhaut.localnet ([2a01:e0a:8d5:d990:e654:e8ff:fe8f:2ce6]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1f49486fc6esm60680985ad.221.2024.05.29.06.30.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 May 2024 06:30:10 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix LTO type mismatch warning on transparent union Date: Wed, 29 May 2024 15:30:03 +0200 Message-ID: <3506200.QJadu78ljV@fomalhaut> MIME-Version: 1.0 X-Spam-Status: No, score=-11.0 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, T_SCC_BODY_TEXT_LINE 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 Hi, Ada doesn't have an equivalent to transparent union types in GNU C so, when it needs to interface a C function that takes a parameter of a transparent union type, GNAT uses the type of the first member of the union on the Ada side (which is the type used to determine the passing mechanism of the parameter). This works fine, except that LTO may warn about it; for the attached testcase: .> gcc -c t.c -O2 -flto -D_GNU_SOURCE .> gnatmake -q p -O2 -flto -largs t.o q.ads:6:12: warning: type of 'q__c_getpeername' does not match original declaration [-Wlto-type-mismatch] 6 | function C_Getpeername | ^ /usr/include/sys/socket.h:130:12: note: type mismatch in parameter 2 130 | extern int getpeername (int __fd, __SOCKADDR_ARG __addr, | ^ /usr/include/sys/socket.h:130:12: note: 'getpeername' was previously declared here /usr/include/sys/socket.h:130:12: note: code may be misoptimized unless '-fno- strict-aliasing' is used The attached patch recognizes the situation and checks the compatibility with the type of the first member of the union in this case. Tested on x86-64/Linux, OK for the mainline? 2024-05-29 Eric Botcazou * lto/lto-symtab.cc (warn_type_compatibility_p): Deal with parameters whose type is a transparent union specially. diff --git a/gcc/lto/lto-symtab.cc b/gcc/lto/lto-symtab.cc index a40218beac5..ca5a79610bb 100644 --- a/gcc/lto/lto-symtab.cc +++ b/gcc/lto/lto-symtab.cc @@ -233,8 +233,20 @@ warn_type_compatibility_p (tree prevailing_type, tree type, parm1 && parm2; parm1 = TREE_CHAIN (parm1), parm2 = TREE_CHAIN (parm2)) - lev |= warn_type_compatibility_p (TREE_VALUE (parm1), - TREE_VALUE (parm2), false); + /* If a function with a transparent union parameter is interfaced + with another type, check that the latter is compatible with the + type of the first field of the union, which is the type used to + set the calling convention for the argument. */ + if (TREE_CODE (TREE_VALUE (parm1)) == UNION_TYPE + && TYPE_TRANSPARENT_AGGR (TREE_VALUE (parm1)) + && TREE_CODE (TREE_VALUE (parm2)) != UNION_TYPE + && common_or_extern) + lev |= warn_type_compatibility_p + (TREE_TYPE (TYPE_FIELDS (TREE_VALUE (parm1))), + TREE_VALUE (parm2), false); + else + lev |= warn_type_compatibility_p (TREE_VALUE (parm1), + TREE_VALUE (parm2), false); if (parm1 || parm2) lev |= odr_p ? 3 : 1; }