Christopher, I'll cut short a few citations: On 2026-11-21 15:30, Christopher Bazley wrote: > Good morning, Michael, > > I haven't investigated implementing -Wnull-dereference in TCC; > however, I think it would be complementary to _Optional rather than an > alternative.
Avoiding null-dereference seems a key issue to cope with. In case of C lang that is the programmer's task to take care of. Too heavy-weight static code analysis exist with gcc (which is where this belongs, as compiler switch, without a language feature extension, and outside tcc due to it's design) > A compiler can diagnose dereferencing a pointer that is known to be > null, but what should it do when the pointer's value is unknown? Occasionally it's the programmer's responsibility to ensure correctness of control flow in C lang, even when there is no static code analysis available supported by code instrumentation/qualifier entangled as core language feature. C lang remained relatively stable for decades. > Assuming that every pointer might be null would produce too many > warnings, whereas assuming that unknown pointers are non-null would > miss potentially dangerous dereferences. OK, the programmer should know, and implement related control flow. > The _Optional qualifier provides information that helps resolve this > ambiguity: it distinguishes pointers whose referenced objects may > legitimately be absent from those whose interfaces require an object > to be present. A compiler can use that distinction to decide when an > unknown pointer value warrants a diagnostic. I've lost here. At some point a test for NULL is necessary. > > - mentioning SDCC as a reference compiler is inappropriate because this > > compiler's many internals itself are implemented in C++, not C nor leave > > alone > > In fact, SDCC is predominantly written in C. In its src directory, > 97.3% of the code (excluding comments and blank lines) is C, according > to cloc: Sigh. You've forgotten the 100million lines of code transitive compile-time dependencies inside c++ toolchain to compile those 2.7% of c++. Remarkable in a way, because SDCC never could become self-hosting on the target's it's compiling for (such as Z80 which i doubt ever could host a c++ compiler sufficient to compile/bootstrap SDCC) tcc instead can be compiled by even smaller pnut-cc/mes-cc type compilers, but not any asm-written one such as cc_x86 (see oriansj on github, myself isn't the expert in this) > > There is a pinciple tradeoff between bootstrapping and language features > > added > > (discussed before here on the list). > > I understand the importance of bootstrapping, but I think there is a > crucial distinction between the language features that TCC supports > and the language features required to compile TCC. Supporting > _Optional adds a very small amount of implementation complexity, but > does not require a more sophisticated compiler to bootstrap TCC. tcc already cannot be compiled with asm-written cc_x86 (stage0-posix project) tcc already did regress with it's complexity beyond feasibility. (myself among many others were working on a few pieces still, and bootstrappable remained blocked at tcc-0.9.26 even, plus some pnut-cc related patchset which was not yet rebased onto mob HEAD, which i'll try soon once some other recent regressions were coped with and tcc HEAD is STABLE again, currently it isn't) > > - finally _Optional language extension isn't the only i remain sceptical > > about. > > pointer semantics in C are clear, these can be NULL and must be tested for > > carefully, with or without a language extension for this. I could name a few more language extensions which did not belong into any ANSI/ISO/IEC C99, C11 together with some more or less conclusive explanation WHY that is. Too there was some language features pointed to by pnut-cc patchset which features might not belong into tcc internally itself, when it's HEAD should remain bootstrappable. mes-cc situation is even more complicated (it's been discussed on this list occasionally). -- Michael
signature.asc
Description: Digital signature
_______________________________________________ Tinycc-devel mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/tinycc-devel
