Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.compilers > #1751
| Path | csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end |
|---|---|
| From | BartC <bc@freeuk.com> |
| Newsgroups | comp.compilers |
| Subject | Re: Alternative C compilers on x86_64 Linux? |
| Date | Tue, 6 Sep 2016 21:35:30 +0100 |
| Organization | A noiseless patient Spider |
| Lines | 77 |
| Sender | news@iecc.com |
| Approved | comp.compilers@iecc.com |
| Message-ID | <16-09-012@comp.compilers> (permalink) |
| References | <16-09-001@comp.compilers> <16-09-005@comp.compilers> <16-09-009@comp.compilers> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 8bit |
| Injection-Info | miucha.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="87943"; mail-complaints-to="abuse@iecc.com" |
| Keywords | C, optimize, errors |
| Posted-Date | 08 Sep 2016 11:11:44 EDT |
| X-submission-address | compilers@iecc.com |
| X-moderator-address | compilers-request@iecc.com |
| X-FAQ-and-archives | http://compilers.iecc.com |
| Xref | csiph.com comp.compilers:1751 |
Show key headers only | View raw
On 06/09/2016 03:15, Kaz Kylheku wrote:
> On 2016-09-05, BartC <bc@freeuk.com> wrote:
>> I suspect [TCC] just compiles switch as an if-else chain. Which might
>> explain why duplicate case labels are ignored if that conversion is done
>> at at early stage.
>>
>> (Because a duplicate condition in an if-else chain is fine. For a
>> jump-table of course, a duplicate label is ambiguous so can't be allowed.)
>
> A duplicate condition in an if-else chain is unreachable code, which is
> probably a bug.
>
> if (foo) {
> ...
> } else if (foo) {
> /* unreachable */
> } else if (bar) {
> ...
> }
It's not necessarily unreachable. For example:
if (foo()) { ...}
elsif if (foo()) { ... }
foo() could return false the first time and true the second time.
In general detecting duplication conditions for if-else can involve
comparing expressions of arbitrary complexity, and it can be harder to
determine if they will always yield the same value.
(Unreachable code can also be made reachable by inserting a label with a
goto from elsewhere.)
> Duplicate cases are a constraint violation in ISO C, requiring a
> diagnostic.
> A duplicate label can also be just as "fine". Look, you can build a jump
> table, and then just fill it without caring about duplicates:
>
> case 42:
> ...
> case 42:
>
> No problem: just write to jumptable[42] twice, letting it the most
> recently established address overrule the previous one.
Some duplicate cases might be fine:
case 10: case 10:
as they both end up at the same place (and the 10s can be hidden behind
different macros or enums). But an error is still reported.
> Duplicate case label code can still be reachable, making the bugs
> potentially more interesting:
>
> case 42: // suppose this is used
> ...
> break;
> case 19:
> ...
> /* fallthrough */
> case 42: // this isn't used, but fallthrough makes it reachable
That's another way for duplicate cases to be meaningful, except that you
can't control which of the case 42s is put into the jump table. Unless
(in this case) you only use the first, so writing to jumptable[42] once
not twice.
But the sensible thing for switch is to report all duplicates (with a
possible concession when labels are at the same location, although that
could mask an error).
--
Bartc
Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-02 03:01 +0000
Re: Alternative C compilers on x86_64 Linux? jacobnavia <jacob@jacob.remcomp.fr> - 2016-09-05 00:20 +0200
Re: Alternative C compilers on x86_64 Linux? alexfrunews@gmail.com - 2016-09-05 17:26 -0700
Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-09 12:31 +0100
Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-09 16:06 +0000
Re: diagnosing C errors, was Alternative C compilers on x86_64 Linux? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2016-09-10 00:38 +0200
Re: Alternative C compilers on x86_64 Linux? Nemo <nemo@invalid.invalid> - 2016-09-04 18:32 -0400
Re: Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-04 23:48 +0000
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-05 13:19 +0100
Re: Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-06 02:15 +0000
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-06 21:35 +0100
Re: dead code or otherwise, was Alternative C compilers on x86_64 Linux? George Neuner <gneuner2@comcast.net> - 2016-09-08 11:58 -0400
Re: dead code or otherwise, was Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-08 22:54 +0000
Re: dead code or otherwise, was Alternative C compilers on x86_64 Linux? George Neuner <gneuner2@comcast.net> - 2016-09-09 00:51 -0400
Re: dead code or otherwise, was Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-09 06:05 +0000
Re: dead code or otherwise, was Alternative C compilers on x86_64 Linux? George Neuner <gneuner2@comcast.net> - 2016-09-09 14:02 -0400
Re: dead code or otherwise, was Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-09 19:57 +0000
Re: duplicate cases, was Alternative C compilers on x86_64 Linux? Andy Walker <anw@cuboid.co.uk> - 2016-09-07 17:01 +0100
Re: Alternative C compilers on x86_64 Linux? Florian Weimer <fw@deneb.enyo.de> - 2016-09-05 20:06 +0200
Re: Alternative C compilers on x86_64 Linux? alexfrunews@gmail.com - 2016-09-05 17:22 -0700
Re: Alternative C compilers on x86_64 Linux? Kaz Kylheku <221-501-9011@kylheku.com> - 2016-09-06 02:18 +0000
Re: Alternative C compilers on x86_64 Linux? rockbrentwood@gmail.com - 2016-09-07 17:00 -0700
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-12 18:42 +0000
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-12 22:37 +0100
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-13 17:35 +0000
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-14 18:14 +0000
Re: Alternative C compilers on x86_64 Linux? rugxulo@gmail.com - 2016-09-26 15:29 -0700
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-27 05:40 +0000
Re: Alternative C compilers on x86_64 Linux? rugxulo@gmail.com - 2016-09-27 16:36 -0700
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-28 18:16 +0100
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-29 14:03 +0100
Re: Alternative C compilers on x86_64 Linux? George Neuner <gneuner2@comcast.net> - 2016-09-29 22:57 -0400
Re: Alternative C compilers on x86_64 Linux? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2016-09-30 05:03 +0200
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-30 12:00 +0100
Re: Alternative C compilers on x86_64 Linux? Hans-Peter Diettrich <DrDiettrich1@netscape.net> - 2016-09-30 20:15 +0200
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-10-01 22:17 +0100
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-09-30 12:28 +0100
Re: Alternative C compilers on x86_64 Linux? BartC <bc@freeuk.com> - 2016-10-17 22:49 +0100
Re: Alternative C compilers on x86_64 Linux? George Neuner <gneuner2@comcast.net> - 2016-09-28 21:24 -0400
Re: Alternative C compilers on x86_64 Linux? George Neuner <gneuner2@comcast.net> - 2016-09-28 01:01 -0400
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-29 02:55 +0000
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com - 2016-09-29 05:30 -0600
Re: Alternative C compilers on x86_64 Linux? arnold@skeeve.com (Aharon Robbins) - 2016-09-30 10:13 +0000
csiph-web