From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id 6FDD33858403 for ; Mon, 1 Nov 2021 19:36:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6FDD33858403 Received: by mail-qk1-x72a.google.com with SMTP id bp7so12377186qkb.10 for ; Mon, 01 Nov 2021 12:36:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=kXQsUopmnkIkWpUXQ/A+oL/WYCjUvqTbEEg9nnYnc/4=; b=bVBdLR57lWiBRxueOOdresnKVN3bNPa7p2xwIKDA59JGU4w8FxMu34BsoruYZ7R+Ni DOj0pfYFYR7jPlIk+4EzeRU+xX0MPOTrdT+Dan2rTKrh/K48UbY6oj+d8I50d6+eQtZe C4RX6Rsk0gL5MtV2mXu2SUV+caCipiSpOf0EXP7LPGstaR6FtIs2Qif/AXoOBDyWwO+T VEzMEupNPXgBRaDYAS2M4LStwgNtpFkCaj/8dngSjqk4hxO2wpTQSL7R4asNrvrBCqEm cg7I4AxIr7UFgvLJD2uXIV/wK9KOVp81XcH0pioTP7IY+5whjNISxDAcuphws6CeAi6i 8Dhw== X-Gm-Message-State: AOAM531p+wOmmUCM6q3FEaeklBmmrAN1/MxgdTLGWdQhobRMs2C2cpoZ EtvG//Nay2kb02TWogtP2ODD1ji5GV3Xa5CmeiWER17oR/o= X-Google-Smtp-Source: ABdhPJw8OyDdTvFcw/l7MuS8j9yVu7nnsdccxoe5h4/wZ86sKN9bGRQqKMyORCE8kiTI22PQmv0DB3ZCZgsuSEAWgiY= X-Received: by 2002:a37:a954:: with SMTP id s81mr25640699qke.188.1635795362624; Mon, 01 Nov 2021 12:36:02 -0700 (PDT) MIME-Version: 1.0 References: <20211101034519.29154-1-vapier@gentoo.org> In-Reply-To: From: Christian Biesinger Date: Mon, 1 Nov 2021 15:35:23 -0400 Message-ID: Subject: Re: [PATCH] sim: mn10300: clean up pointer casts To: Christian Biesinger via Gdb-patches , Christian Biesinger Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-18.0 required=5.0 tests=BAYES_00, DKIMWL_WL_MED, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Mon, 01 Nov 2021 19:36:06 -0000 On Mon, Nov 1, 2021 at 2:59 PM Mike Frysinger wrote: > > On 01 Nov 2021 14:28, Christian Biesinger via Gdb-patches wrote: > > On Mon, Nov 1, 2021 at 12:22 PM Mike Frysinger wrote: > > > On 01 Nov 2021 12:07, Christian Biesinger wrote: > > > > On Sun, Oct 31, 2021 at 11:45 PM Mike Frysinger via Gdb-patches > > > > wrote: > > > > > --- a/sim/mn10300/dv-mn103ser.c > > > > > +++ b/sim/mn10300/dv-mn103ser.c > > > > > @@ -238,7 +238,7 @@ do_polling_event (struct hw *me, > > > > > { > > > > > SIM_DESC sd = hw_system (me); > > > > > struct mn103ser *serial = hw_data(me); > > > > > - long serial_reg = (long) data; > > > > > + long serial_reg = (uintptr_t) data; > > > > > > > > Shouldn't you change the variable type too? > > > > > > the types are already confused, but long here is fine as any other. uintptr_t > > > is not really any more correct. serial_reg comes in as an unsigned_word via > > > the memory read/write callbacks, (encoded) cast to void*, and (decoded) cast > > > to long. the memory read/write callbacks verify the values are always within > > > the serial_register_types enum range which looks like [0,16] range, so any of > > > these types work. > > > > > > > Otherwise this patch seems to be somewhat pointless? > > > > if ( nr_bytes == 1 ) > > > > > > i don't know which one you mean, or why you think any of them are pointless. > > > the nr_bytes checks are in the read/write code paths of the memory mapped > > > register callbacks. so nr_bytes is needed & correct there. > > > > I forgot to delete that nr_bytes line; the pointless comment was about > > casting to uintprtr_t but still storing the result in a long. Why not > > keep it as a cast to long then? > > that was the point of the patch in the first place :). i prob should have > included the compiler errors in the log, but basically any target where the > sizeof(long) != sizeof(void*) will generate an error. LLP64 systems is where > you'll find this, and most notably, 64-bit Windows does it. > warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] > > since sizeof(uintptr_t) is guaranteed to equal sizeof(void*), it's the "right" > way to convert integers to/from pointers. in this case, the event framework > is using void* as an opaque storage, and this particular model is (ab)using > that to pass values rather than pointers to larger storage. I see, so what the patch does is to cast to uintptr_t to avoid the compile error about losing precision and rely on an implicit conversion to long? My suggestion would be to make that a bit clearer in the commit message and perhaps explicitly convert from uintptr_t to long. Christian