From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by sourceware.org (Postfix) with ESMTPS id 5A5073814FE7 for ; Mon, 30 May 2022 09:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5A5073814FE7 Received: by mail-pj1-x1031.google.com with SMTP id nn3-20020a17090b38c300b001e0e091cf03so7376881pjb.1 for ; Mon, 30 May 2022 02:35:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EBdK78TsBK+I82/LJO4HZEqX1POleBRJJYp+Ufz6p3U=; b=yUr9zdhUFSnnvNQWLov73GMk/t/WYu+wgycBASfi51/F/vjcsUAt4jgH6/Sbf/tKjL odDg5BbzqwZX+veMaIhdVR2OB+GcUGlwWjbv+7IOXCTlOLB2toUk84CIO4UUFFrFv9J8 wGwkMcJ4bwO8LiDoCw9iUvtRrdH6eki2pl6TPSJQm6xw0eXbMPyRTJN800M8H5g1xLwT /Tt8YJ2FEnDCJ1fbvLP+TOfCe/2svNYC7t2Vi8WQeJiJhJ0lR6mT0dnbD9/j2tlrMNxL lmsb81eWkZrpT1Y+NdbOXzwh5o7ty1XnXkg3VgYnAfJB2TzEQRaPzp3WuSZi+7Ol18jW Ohjg== X-Gm-Message-State: AOAM532AuvoKeDmSijQvCAH7pADy6UkejhfZBFIx9Q+nnRzi4M+MyYuk dtR0l1trxRrhIj5KQ20xr70y90/QCv8= X-Google-Smtp-Source: ABdhPJxNCRVDKPoGUkL7WBn5J3uGHnhFM1SIj0fXof1nFMmZQ+XF4B1hsaZ146lzZxoVygjSASAIFw== X-Received: by 2002:a17:90b:3ec2:b0:1dc:db97:9424 with SMTP id rm2-20020a17090b3ec200b001dcdb979424mr21827857pjb.153.1653903321024; Mon, 30 May 2022 02:35:21 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id w18-20020a170902a71200b001622c377c3esm8678470plq.117.2022.05.30.02.35.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 May 2022 02:35:20 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 1AF76114117E; Mon, 30 May 2022 19:05:18 +0930 (ACST) Date: Mon, 30 May 2022 19:05:18 +0930 From: Alan Modra To: binutils@sourceware.org Subject: Use a union to avoid casts in bfd/doc/chew.c Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3037.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 May 2022 09:35:23 -0000 This fixes -Wpedantic warnings in chew.c. Conversion between function and object pointers is not guaranteed. They can even be different sizes, not that we're likely to encounter build machines like that nowadays. PR 29194 * doc/chew.c (pcu): New union typedef. (dict_type, pc): Use it here. Adjust uses of pc. (add_to_definition): Make "word" param a pcu. Adjust all uses of function. (stinst_type): Delete. diff --git a/bfd/doc/chew.c b/bfd/doc/chew.c index 9722a89f0e6..a12c00370d9 100644 --- a/bfd/doc/chew.c +++ b/bfd/doc/chew.c @@ -101,13 +101,21 @@ typedef struct buffer unsigned long size; } string_type; -typedef void (*stinst_type) (void); +/* Compiled programs consist of arrays of these. */ + +typedef union +{ + void (*f) (void); + struct dict_struct *e; + char *s; + long l; +} pcu; typedef struct dict_struct { char *word; struct dict_struct *next; - stinst_type *code; + pcu *code; int code_length; int code_end; } dict_type; @@ -128,7 +136,7 @@ long *isp = &istack[0]; dict_type *root; -stinst_type *pc; +pcu *pc; static void die (char *msg) @@ -290,16 +298,15 @@ static void exec (dict_type *word) { pc = word->code; - while (*pc) - (*pc) (); + while (pc->f) + pc->f (); } static void call (void) { - stinst_type *oldpc = pc; - dict_type *e; - e = (dict_type *) (pc[1]); + pcu *oldpc = pc; + dict_type *e = pc[1].e; exec (e); pc = oldpc + 2; } @@ -328,7 +335,7 @@ push_number (void) isp++; icheck_range (); pc++; - *isp = (long) (*pc); + *isp = pc->l; pc++; } @@ -339,7 +346,7 @@ push_text (void) check_range (); init_string (tos); pc++; - cattext (tos, *((char **) pc)); + cattext (tos, pc->s); pc++; } @@ -1166,11 +1173,11 @@ free_words (void) { int i; for (i = 0; i < ptr->code_end - 1; i ++) - if (ptr->code[i] == push_text - && ptr->code[i + 1]) + if (ptr->code[i].f == push_text + && ptr->code[i + 1].s) { - free ((char *) ptr->code[i + 1] - 1); - ++ i; + free (ptr->code[i + 1].s - 1); + ++i; } free (ptr->code); } @@ -1228,7 +1235,7 @@ newentry (char *word) } unsigned int -add_to_definition (dict_type *entry, stinst_type word) +add_to_definition (dict_type *entry, pcu word) { if (entry->code_end == entry->code_length) { @@ -1245,8 +1252,10 @@ void add_intrinsic (char *name, void (*func) (void)) { dict_type *new_d = newentry (xstrdup (name)); - add_to_definition (new_d, func); - add_to_definition (new_d, 0); + pcu p = { func }; + add_to_definition (new_d, p); + p.f = 0; + add_to_definition (new_d, p); } void @@ -1261,6 +1270,7 @@ compile (char *string) if (word[0] == ':') { dict_type *ptr; + pcu p; /* Compile a word and add to dictionary. */ free (word); @@ -1283,8 +1293,10 @@ compile (char *string) case '"': /* got a string, embed magic push string function */ - add_to_definition (ptr, push_text); - add_to_definition (ptr, (stinst_type) (word + 1)); + p.f = push_text; + add_to_definition (ptr, p); + p.s = word + 1; + add_to_definition (ptr, p); break; case '0': case '1': @@ -1298,19 +1310,24 @@ compile (char *string) case '9': /* Got a number, embedd the magic push number function */ - add_to_definition (ptr, push_number); - add_to_definition (ptr, (stinst_type) atol (word)); + p.f = push_number; + add_to_definition (ptr, p); + p.l = atol (word); + add_to_definition (ptr, p); free (word); break; default: - add_to_definition (ptr, call); - add_to_definition (ptr, (stinst_type) lookup_word (word)); + p.f = call; + add_to_definition (ptr, p); + p.e = lookup_word (word); + add_to_definition (ptr, p); free (word); } string = nextword (string, &word); } - add_to_definition (ptr, 0); + p.f = 0; + add_to_definition (ptr, p); free (word); string = nextword (string, &word); } -- Alan Modra Australia Development Lab, IBM