tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Tinycc-devel] MAJOR bug: tcc doesn't detect duplicate cases in swit


From: Michael Matz
Subject: Re: [Tinycc-devel] MAJOR bug: tcc doesn't detect duplicate cases in switch statements
Date: Sun, 13 Mar 2016 02:14:13 +0100 (CET)
User-agent: Alpine 2.20 (LSU 67 2015-01-07)

Hi,

On Sat, 12 Mar 2016, address@hidden wrote:

First, the bug can't be as MAJOR as the subject wants to make us believe. After all it wasn't noticed since the last $MANY years.

The bug caused me to push bad code to gawk's repo.

I assumed something like that. It still doesn't make the bug any more major than many of the other bugs that tcc has.

It's only luck that it wasn't noticed, but a bug is a bug. Geting the right answer a little more slowly is always better than getting the wrong answer super fast.

No, I don't agree with you that a missed diagnostics is in the same class like wrong-code bugs. Especially if it's costly to implement a diagnostic it's quite reasonable to not implement it in a compiler that's supposed to be quick (at least as long as there's other missing diagnostics). Unlike wrong-code bugs for instance (well, even there the world is not always black and white, only mostly so).

The issue isn't just the lack of diagnostic - what kind of erroneous code is being generated in this case?

Any we want. As the behaviour of the input was undefined the generated code can't be erroneous. In practice I can tell you: tcc translates a switch literally into a sequence of if-else tests, so the code with overlapping cases is simply:
  if (a == 1) ...
  else if (a == 1) ...

So, first one matching wins.

TCC is valuable for being both fast and correct. Lose the correctness and you lose ALL the value.

Given those absolute terms, I don't know of any compiler that's correct.
TCC certainly isn't. TCC isn't bad either in correctness, it's actually quite good, but not 100%. I hope you still continue to find TCC valuable, your use of it for serious development is much welcome :)

And, of course, I'm not dead-set against giving a diagnostic. An implementation that's not making eyes bleed and is fast would be nice. E.g. remember cases in an array of ranges while parsing, qsort them after switch is finished, generated diagnostics on overlap.


Ciao,
Michael.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]