rui314 / chibicc

A small C compiler
MIT License
9.57k stars 871 forks source link

Evaluation of constant expression in preprocessing directives may produce incorrect results #94

Open pmor13 opened 2 years ago

pmor13 commented 2 years ago
#if !1u - 1 > 0
#error
#endif 

leads to:

<source>:2:   #error
fuhsnn commented 11 months ago

https://github.com/rui314/chibicc/blob/90d1f7f199cc55b13c7fdb5839d1409806633fdb/parse.c#L1903-L1903

Since the common type of this conditional expression is uint32_t, the int32_t path actually goes like return (int64_t)(uint32_t)(int32_t)val, missing out 64-bit sign-extension.