History

Handle always_inline as GNU inline

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.

Michael Matz committed 6 years ago

Commit f18f8651 parent 5d2f4cb3 files · +23 −5Browse files

Unified · Split

3 files
  1. tcc.h +3 −1
  2. tccgen.c +18 −4
  3. tcctok.h +2 −0
tcc.h+3−1
@@ -494,7 +494,9 @@ struct FuncAttr { · 493 unmodified lines
494 func_noreturn : 1, /* attribute((noreturn)) */494 func_noreturn : 1, /* attribute((noreturn)) */
495 func_ctor : 1, /* attribute((constructor)) */495 func_ctor : 1, /* attribute((constructor)) */
496 func_dtor : 1, /* attribute((destructor)) */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/* symbol management */502/* symbol management */
tccgen.c+18−4
@@ -4075,14 +4075,18 @@ redo: · 4074 unmodified lines
4075 skip(')');4075 skip(')');
4076 break;4076 break;
4077 }4077 }
4078 case TOK_CONSTRUCTOR1:4078 case TOK_CONSTRUCTOR1:
4079 case TOK_CONSTRUCTOR2:4079 case TOK_CONSTRUCTOR2:
4080 ad->f.func_ctor = 1;4080 ad->f.func_ctor = 1;
4081 break;4081 break;
4082 case TOK_DESTRUCTOR1:4082 case TOK_DESTRUCTOR1:
4083 case TOK_DESTRUCTOR2:4083 case TOK_DESTRUCTOR2:
4084 ad->f.func_dtor = 1;4084 ad->f.func_dtor = 1;
4085 break;4085 break;
4086 case TOK_ALWAYS_INLINE1:
4087 case TOK_ALWAYS_INLINE2:
4088 ad->f.func_alwinl = 1;
4089 break;
4086 case TOK_SECTION1:4090 case TOK_SECTION1:
4087 case TOK_SECTION2:4091 case TOK_SECTION2:
4088 skip('(');4092 skip('(');
@@ -8225,6 +8229,16 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 4136 unmodified lines
8225 sym = type.ref;8229 sym = type.ref;
8226 if (sym->f.func_type == FUNC_OLD && l == VT_CONST)8230 if (sym->f.func_type == FUNC_OLD && l == VT_CONST)
8227 decl0(VT_CMP, 0, sym);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 /* always compile 'extern inline' */8242 /* always compile 'extern inline' */
8229 if (type.t & VT_EXTERN)8243 if (type.t & VT_EXTERN)
8230 type.t &= ~VT_INLINE;8244 type.t &= ~VT_INLINE;
tcctok.h+2−0
@@ -132,6 +132,8 @@ · 131 unmodified lines
132 DEF(TOK_CONSTRUCTOR2, "__constructor__")132 DEF(TOK_CONSTRUCTOR2, "__constructor__")
133 DEF(TOK_DESTRUCTOR1, "destructor")133 DEF(TOK_DESTRUCTOR1, "destructor")
134 DEF(TOK_DESTRUCTOR2, "__destructor__")134 DEF(TOK_DESTRUCTOR2, "__destructor__")
135 DEF(TOK_ALWAYS_INLINE1, "always_inline")
136 DEF(TOK_ALWAYS_INLINE2, "__always_inline__")
135 137
136 DEF(TOK_MODE, "__mode__")138 DEF(TOK_MODE, "__mode__")
137 DEF(TOK_MODE_QI, "__QI__")139 DEF(TOK_MODE_QI, "__QI__")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t