this is needed for multi-file testcases using stdio.h, as the __sputc function is implemented as a extern inline function (with gnu_inline attribute, but we don't support that for now). Without this change that leads to multiply defined symbols when using multiple units including stdio.h. It also has an always_inline attribute, which we can use to guide our behaviour, as in ISO-C an always_inline can't be defined with ISO 'extern inline' semantics. This is the minimal change and not a full implementation of GNU inline semantics, which would require thorough testcases. If __clang__ would be defined the header would make use of C99 semantics, which would work for us. It would also do that if _GNUC_ wouldn't be defined. But we can't do the latter (as the whole MacOSX SDK refuses to be compiled with anything not defining that). I haven't tested defining __clang__, but suspect that's going to be problematic.
Unified · Split
| @@ -494,7 +494,9 @@ struct FuncAttr { · 493 unmodified lines | ||
| 494 | 494 | func_noreturn : 1, /* attribute((noreturn)) */ |
| 495 | 495 | func_ctor : 1, /* attribute((constructor)) */ |
| 496 | 496 | func_dtor : 1, /* attribute((destructor)) */ |
| 497 | − func_args : 8; /* PE __stdcall args */ | |
| 497 | + func_args : 8, /* PE __stdcall args */ | |
| 498 | + func_alwinl : 1, /* always_inline */ | |
| 499 | + xxxx :15; | |
| 498 | 500 | }; |
| 499 | 501 | |
| 500 | 502 | /* symbol management */ |
| @@ -4075,14 +4075,18 @@ redo: · 4074 unmodified lines | ||
| 4075 | 4075 | skip(')'); |
| 4076 | 4076 | break; |
| 4077 | 4077 | } |
| 4078 | − case TOK_CONSTRUCTOR1: | |
| 4079 | − case TOK_CONSTRUCTOR2: | |
| 4078 | + case TOK_CONSTRUCTOR1: | |
| 4079 | + case TOK_CONSTRUCTOR2: | |
| 4080 | 4080 | ad->f.func_ctor = 1; |
| 4081 | 4081 | break; |
| 4082 | − case TOK_DESTRUCTOR1: | |
| 4083 | − case TOK_DESTRUCTOR2: | |
| 4082 | + case TOK_DESTRUCTOR1: | |
| 4083 | + case TOK_DESTRUCTOR2: | |
| 4084 | 4084 | ad->f.func_dtor = 1; |
| 4085 | 4085 | break; |
| 4086 | + case TOK_ALWAYS_INLINE1: | |
| 4087 | + case TOK_ALWAYS_INLINE2: | |
| 4088 | + ad->f.func_alwinl = 1; | |
| 4089 | + break; | |
| 4086 | 4090 | case TOK_SECTION1: |
| 4087 | 4091 | case TOK_SECTION2: |
| 4088 | 4092 | skip('('); |
| @@ -8225,6 +8229,16 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 4136 unmodified lines | ||
| 8225 | 8229 | sym = type.ref; |
| 8226 | 8230 | if (sym->f.func_type == FUNC_OLD && l == VT_CONST) |
| 8227 | 8231 | decl0(VT_CMP, 0, sym); |
| 8232 | + if (sym->f.func_alwinl | |
| 8233 | + && ((type.t & (VT_EXTERN | VT_INLINE)) | |
| 8234 | + == (VT_EXTERN | VT_INLINE))) { | |
| 8235 | + /* always_inline functions must be handled as if they | |
| 8236 | + don't generate multiple global defs, even if extern | |
| 8237 | + inline, i.e. GNU inline semantics for those. Rewrite | |
| 8238 | + them into static inline. */ | |
| 8239 | + type.t &= ~VT_EXTERN; | |
| 8240 | + type.t |= VT_STATIC; | |
| 8241 | + } | |
| 8228 | 8242 | /* always compile 'extern inline' */ |
| 8229 | 8243 | if (type.t & VT_EXTERN) |
| 8230 | 8244 | type.t &= ~VT_INLINE; |
| @@ -132,6 +132,8 @@ · 131 unmodified lines | ||
| 132 | 132 | DEF(TOK_CONSTRUCTOR2, "__constructor__") |
| 133 | 133 | DEF(TOK_DESTRUCTOR1, "destructor") |
| 134 | 134 | DEF(TOK_DESTRUCTOR2, "__destructor__") |
| 135 | + DEF(TOK_ALWAYS_INLINE1, "always_inline") | |
| 136 | + DEF(TOK_ALWAYS_INLINE2, "__always_inline__") | |
| 135 | 137 | |
| 136 | 138 | DEF(TOK_MODE, "__mode__") |
| 137 | 139 | DEF(TOK_MODE_QI, "__QI__") |