Skip to content

Support Visual Studio's __forceinline #2560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions regression/ansi-c/forceinline1/main.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#line 1 "test.c"

__inline int foo()
{
return 0;
}

__forceinline int foo()
{
return 1;
}

int main()
{
}
8 changes: 8 additions & 0 deletions regression/ansi-c/forceinline1/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CORE
main.i
--i386-win32
^EXIT=0$
^SIGNAL=0$
--
^warning: ignoring
^CONVERSION ERROR$
10 changes: 6 additions & 4 deletions src/ansi-c/c_typecheck_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,12 @@ void c_typecheck_baset::typecheck_redefinition_non_type(
// gcc allows re-definition if the first
// definition is marked as "extern inline"

if(old_symbol.type.get_bool(ID_C_inlined) &&
(config.ansi_c.mode==configt::ansi_ct::flavourt::GCC ||
config.ansi_c.mode==configt::ansi_ct::flavourt::APPLE ||
config.ansi_c.mode==configt::ansi_ct::flavourt::ARM))
if(
old_symbol.type.get_bool(ID_C_inlined) &&
(config.ansi_c.mode == configt::ansi_ct::flavourt::GCC ||
config.ansi_c.mode == configt::ansi_ct::flavourt::APPLE ||
config.ansi_c.mode == configt::ansi_ct::flavourt::ARM ||
config.ansi_c.mode == configt::ansi_ct::flavourt::VISUAL_STUDIO))
{
// overwrite "extern inline" properties
old_symbol.is_extern=new_symbol.is_extern;
Expand Down
20 changes: 20 additions & 0 deletions src/ansi-c/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ extern char *yyansi_ctext;
%token TOK_MSC_EXCEPT "__except"
%token TOK_MSC_LEAVE "__leave"
%token TOK_MSC_DECLSPEC "__declspec"
%token TOK_MSC_FORCEINLINE "__forceinline"
%token TOK_INTERFACE "__interface"
%token TOK_CDECL "__cdecl"
%token TOK_STDCALL "__stdcall"
Expand Down Expand Up @@ -1384,6 +1385,25 @@ storage_class:
| TOK_THREAD_LOCAL { $$=$1; set($$, ID_thread_local); }
| TOK_GCC_ASM { $$=$1; set($$, ID_asm); }
| msc_declspec { $$=$1; }
| TOK_MSC_FORCEINLINE
{
// equivalent to always_inline, and seemingly also has the semantics
// of extern inline in that multiple definitions can be provided in
// the same translation unit
init($$);
set($$, ID_static);
set($1, ID_inline);
#if 0
// enable once always_inline support is reinstantiated
$1=merge($1, $$);

init($$);
set($$, ID_always_inline);
$$=merge($1, $$);
#else
$$=merge($1, $$);
#endif
}
;

basic_type_name:
Expand Down
2 changes: 1 addition & 1 deletion src/ansi-c/scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ __decltype { if(PARSER.cpp98 &&

"__forceinline" { if(PARSER.mode==configt::ansi_ct::flavourt::VISUAL_STUDIO ||
PARSER.mode==configt::ansi_ct::flavourt::ARM)
{ loc(); return TOK_INLINE; }
{ loc(); return TOK_MSC_FORCEINLINE; }
else
return make_identifier();
}
Expand Down
9 changes: 7 additions & 2 deletions src/cpp/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1952,14 +1952,19 @@ bool Parser::optMemberSpec(cpp_member_spect &member_spec)

int t=lex.LookAhead(0);

while(t==TOK_FRIEND || t==TOK_INLINE || t==TOK_VIRTUAL || t==TOK_EXPLICIT)
while(
t == TOK_FRIEND || t == TOK_INLINE || t == TOK_VIRTUAL ||
t == TOK_EXPLICIT || t == TOK_MSC_FORCEINLINE)
{
cpp_tokent tk;
lex.get_token(tk);

switch(t)
{
case TOK_INLINE: member_spec.set_inline(true); break;
case TOK_INLINE:
case TOK_MSC_FORCEINLINE:
member_spec.set_inline(true);
break;
case TOK_VIRTUAL: member_spec.set_virtual(true); break;
case TOK_FRIEND: member_spec.set_friend(true); break;
case TOK_EXPLICIT: member_spec.set_explicit(true); break;
Expand Down