tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] -Werror=X (but ugly)


From: Steffen Nurpmeso
Subject: Re: [Tinycc-devel] -Werror=X (but ugly)
Date: Wed, 28 Jul 2021 16:51:06 +0200
User-agent: s-nail v14.9.22-173-g196623ce38

Hello.

grischka wrote in
 <61013BA4.4000001@gmx.de>:
 |Steffen Nurpmeso wrote:
 |>|      gcc -Wwrite-strings -Werror=discarded-qualifiers
 |>
 |> Hm.  Well then this part is not compatible it seems.
 |
 |Not compatible and cannot work:
 |
 |     const char *xxx = "123"; /* no warning or error here */
 |     foo(); /* nobody said we would want this to stop */
 |
 |     $ tcc -Werror=write-strings ...
 |     test.c:8: error: implicit declaration of function 'foo'
 |
 |Because -Wwrite-strings is NOT a warning option, really.
 |
 |And with
 |     const char *xxx = "123";
 |     strcpy(xxx,"456");
 |tcc would complain the "discarded const qualifier" but it cannot
 |track variables and code flow at compile-time in order to know
 |that some pointer came from a string, originally.
 |
 |Forget it.

I.. have a hard time parsing that, there already is
-Wwrite-strings and -Werror=write-strings just propagates the
according bit to make it an error state?  That is all i know.

For me the -Werror thing is done for now, sorry for the necessary
fixups, i am a bit chaotic, for public shared repos i should just
let things rest for a few days and when it is still ok, then push.

In order to be better than what is now in -- what is missing is
that "-Werror -Wno-error=write-strings" does not error out for any
write-strings error, i.e., that specific errors can be disabled --
i had to wrap my head around the control flow of the code
generator, because for write-strings (all others would work out),
it just sets a VT_CONSTANT bit or so, then the generator continues
over several levels, then some *_cast_* function actually emits
a tcc_warning() (i could not figure out when the *_cast_* function
that actually emits the write-strings is actually called, from
looking say ten minutes).  I thought about "quick and dirties":

  - Just call tcc_warning() directly: would result in two log
    messages unless the first would error out.
    I could rename NEED_WARNING() to WANT_WARNING() and add
    a WANT_ERROR(), and call tcc_warning() only then, in order to
    error out.

  - Add some field and another VT_ bit to indicate that field is
    set, in order to pick it up later.
    Then there could be another tcc_warn_or_err() which takes the
    actual "enum warn_option" as its first argument.
    I actually had this implementation fully implemented
    yesterday, with error1() still backing all of the warn
    functions, but for the write-strings case in the generator.

  - Add a bit like WARN_IGNORE_ERR_NEXT, set this from within
    NEED_WARNING() when a specific error is disabled but the
    warning as such shall occur.  Then clear that bit again in
    tcc_warning() (aka error1()).
    I was thinking of this, and it also would work everywhere, but
    i did not know whether it will work out for the code generator
    and the write-strings thing.  Because _if_ another error
    occurs in the generator _before_ we actually call
    tcc_warning(), then of course a hard error could be falsely
    ignored.

 |> I have never
 |> tested it that much, i usually step in when somewhere the build
 |> fails or spits warnings like grazy.  Actually i have given up on
 |> managing the mess that happens from compiler development.
 |
 |Yes, the mess ... eventually it can be reduced:
 |
 |$ git log -1 --shortstat --oneline eadcee65
 |eadcee65 macos: yet another tbd adjustment
 |8 files changed, 155 insertions(+), 169 deletions(-)
 |
 |14 lines less, same functionality (although Christian claims that
 |it's broken since, who knows... ;)
 |
 |> Unfortunately tcc_warning() does not take arguments itself ...
 |
 |I would (maybe) go for
 |     tcc_warning(On_warn_badthing "bad thing did happen with %s", stuff);
 |with say
 |     #define On_warn_badthing "\005"
 |
 |While not sooo nice without a comma, it would allow to "manage away"
 |quite a few existing 'if (s1->warn_...)' clauses already and seems
 |somewhat easily extensible.

Linux syslog thing is also an idea, but not for code generator :)

 |With some luck one might be able to implement the feature (-Werror= etc.)
 |and come out with +/- zero or even less additional lines required.
 |
 |Currently it still adds 78 lines total though:
 |$ git diff --shortstat a7a138~1 2709b7
 |8 files changed, 126 insertions(+), 48 deletions(-)

The enum adds quite a bit on top of it; the addition of
set_W_flag() is, hmm, not nice, but i hope the current approach is
not too heavy.

Keep on going tcc :)

Ciao,

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)



reply via email to

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