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
494494 func_noreturn : 1, /* attribute((noreturn)) */
495495 func_ctor : 1, /* attribute((constructor)) */
496496 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;
498500 };
499501
500502 /* symbol management */
tccgen.c+18−4
@@ -4075,14 +4075,18 @@ redo: · 4074 unmodified lines
40754075 skip(')');
40764076 break;
40774077 }
4078− case TOK_CONSTRUCTOR1:
4079− case TOK_CONSTRUCTOR2:
4078+ case TOK_CONSTRUCTOR1:
4079+ case TOK_CONSTRUCTOR2:
40804080 ad->f.func_ctor = 1;
40814081 break;
4082− case TOK_DESTRUCTOR1:
4083− case TOK_DESTRUCTOR2:
4082+ case TOK_DESTRUCTOR1:
4083+ case TOK_DESTRUCTOR2:
40844084 ad->f.func_dtor = 1;
40854085 break;
4086+ case TOK_ALWAYS_INLINE1:
4087+ case TOK_ALWAYS_INLINE2:
4088+ ad->f.func_alwinl = 1;
4089+ break;
40864090 case TOK_SECTION1:
40874091 case TOK_SECTION2:
40884092 skip('(');
@@ -8225,6 +8229,16 @@ static int decl0(int l, int is_for_loop_init, Sym *func_sym) · 4136 unmodified lines
82258229 sym = type.ref;
82268230 if (sym->f.func_type == FUNC_OLD && l == VT_CONST)
82278231 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+ }
82288242 /* always compile 'extern inline' */
82298243 if (type.t & VT_EXTERN)
82308244 type.t &= ~VT_INLINE;
tcctok.h+2−0
@@ -132,6 +132,8 @@ · 131 unmodified lines
132132 DEF(TOK_CONSTRUCTOR2, "__constructor__")
133133 DEF(TOK_DESTRUCTOR1, "destructor")
134134 DEF(TOK_DESTRUCTOR2, "__destructor__")
135+ DEF(TOK_ALWAYS_INLINE1, "always_inline")
136+ DEF(TOK_ALWAYS_INLINE2, "__always_inline__")
135137
136138 DEF(TOK_MODE, "__mode__")
137139 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