From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by sourceware.org (Postfix) with ESMTPS id 569EF3858404 for ; Thu, 13 Oct 2022 10:49:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 569EF3858404 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=palves.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wr1-f46.google.com with SMTP id j16so2204060wrh.5 for ; Thu, 13 Oct 2022 03:49:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:content-language:in-reply-to:mime-version :user-agent:date:message-id:from:references:cc:to:subject :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yQj2pARcV8Hw5nvSPhca9cuBhz2zTpGxRxP9LuYDZmE=; b=w/r5QuhpuF2odkuI8plxMu5sEqBNLXS6q7MNs5sYLUVxujWHwbDA4ZdsQlli4O/fMd Nh4NPsbUsbEwjvUp1Za9VRrYlIyeJyFScM1f1aRwykbJ6+5hWATWy6aoJkxpTmnardgg IEDP9L/X7WBq4lsSv5atAoAj0DM42hnk7/94xYVgVjAK4gSq3VnMTOn9KsEiIUd5ms0n 8khrcrJTmfTcJpeBVcBU6VzpKpw2Yfx1dgTMKt/dY0bhRkV0AymtS9EawS81z4IbpBoc 0OxjPGV+usEnR4Eb+EsfaY6idGmLOz0qGPtJo2Pe/qDeuloXR7yIgGXucWMB6nAdR1tb WU4w== X-Gm-Message-State: ACrzQf3UKJcctWDXbEoxZ04g2x+EX9q4lQxWT4jYxUIIExqdqC10YcNq GE7c02URWeu9BpxtRgRtzqdMUyiA2oJg3HXM X-Google-Smtp-Source: AMsMyM7d377bRDN+HnL+WuFU3jO2U4K2Ac0MvPfvvmp/1Q1QLEQpxMAsfN8URqGfobakTz2RcjA6VQ== X-Received: by 2002:a5d:598c:0:b0:22e:3b2a:acaa with SMTP id n12-20020a5d598c000000b0022e3b2aacaamr20876515wri.451.1665658185426; Thu, 13 Oct 2022 03:49:45 -0700 (PDT) Received: from ?IPv6:2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653? ([2001:8a0:f93a:3b00:e038:5cdc:b8bf:4653]) by smtp.gmail.com with ESMTPSA id e10-20020a05600c4e4a00b003b4935f04a4sm5202342wmq.5.2022.10.13.03.49.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Oct 2022 03:49:44 -0700 (PDT) Subject: Re: [PATCH 4/5] sim/erc32: avoid dereferencing type-punned pointer warnings To: Andrew Burgess , Lancelot SIX Cc: gdb-patches@sourceware.org References: <170dc056-7e74-6c15-7131-31943c17be3a@palves.net> <20221012170215.imifj66p6dndtf6p@octopus> <87czawau5m.fsf@redhat.com> From: Pedro Alves Message-ID: <1205589e-d898-1373-2f53-d44fd5555938@palves.net> Date: Thu, 13 Oct 2022 11:49:43 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <87czawau5m.fsf@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.6 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP 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: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Oct 2022 10:49:49 -0000 Hi, On 2022-10-13 11:35 a.m., Andrew Burgess wrote: > Lancelot SIX writes: >> >> Another well defined (at least to my knowledge) solution to this problem >> is memcpy. You could do something like: >> >> memcpy (&sregt->fs[rd], ddata, sizeof (float32)); >> >> I tend to find this more straightforward than the type punning version, >> but I would be happy with either. Yes, memcpy is fine too. > Pedro, Lancelot, thanks for taking the time to give really useful > feedback. > > In the end I went with the memcpy approach. I ran a few tests with GCC, > Clang, and ICC, and in each case the code generated at -O0 was either > identical, or pretty much identical when using memcpy vs using a union. > When switching to -O2 the code was identical in all cases I checked. > > Thoughts? LGTM. Pedro Alves