Print this page
Implement -fstrict-calling-conventions
Stock GCC is overly willing to violate the ABI when calling local functions,
such that it passes arguments in registers on i386.  This hampers debugging
with anything other than a fully-aware DWARF debugger, and is generally not
something we desire.
Implement a flag which disables this behaviour, enabled by default.  The flag is
global, though only effective on i386, to more easily allow its globalization
later which, given the odds, is likely to be necessary.


4386           if (!error_issued && regparm == 3
4387               && decl_function_context (decl)
4388               && !DECL_NO_STATIC_CHAIN (decl))
4389             {
4390               error ("nested functions are limited to 2 register parameters");
4391               error_issued = true;
4392               return 0;
4393             }
4394         }
4395 
4396       return regparm;
4397     }
4398 
4399   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4400     return 2;
4401 
4402   /* Use register calling convention for local functions when possible.  */
4403   if (decl
4404       && TREE_CODE (decl) == FUNCTION_DECL
4405       && optimize

4406       && !profile_flag)
4407     {
4408       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4409       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4410       if (i && i->local)
4411         {
4412           int local_regparm, globals = 0, regno;
4413           struct function *f;
4414 
4415           /* Make sure no regparm register is taken by a
4416              fixed register variable.  */
4417           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4418             if (fixed_regs[local_regparm])
4419               break;
4420 
4421           /* We can't use regparm(3) for nested functions as these use
4422              static chain pointer in third argument.  */
4423           if (local_regparm == 3
4424               && decl_function_context (decl)
4425               && !DECL_NO_STATIC_CHAIN (decl))


4470     {
4471       if (!TARGET_SSE)
4472         {
4473           if (warn)
4474             {
4475               if (decl)
4476                 error ("Calling %qD with attribute sseregparm without "
4477                        "SSE/SSE2 enabled", decl);
4478               else
4479                 error ("Calling %qT with attribute sseregparm without "
4480                        "SSE/SSE2 enabled", type);
4481             }
4482           return 0;
4483         }
4484 
4485       return 2;
4486     }
4487 
4488   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4489      (and DFmode for SSE2) arguments in SSE registers.  */
4490   if (decl && TARGET_SSE_MATH && optimize && !profile_flag)

4491     {
4492       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4493       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4494       if (i && i->local)
4495         return TARGET_SSE2 ? 2 : 1;
4496     }
4497 
4498   return 0;
4499 }
4500 
4501 /* Return true if EAX is live at the start of the function.  Used by
4502    ix86_expand_prologue to determine if we need special help before
4503    calling allocate_stack_worker.  */
4504 
4505 static bool
4506 ix86_eax_live_at_start_p (void)
4507 {
4508   /* Cheat.  Don't bother working forward from ix86_function_regparm
4509      to the function type to whether an actual argument is located in
4510      eax.  Instead just look at cfg info, which is still close enough




4386           if (!error_issued && regparm == 3
4387               && decl_function_context (decl)
4388               && !DECL_NO_STATIC_CHAIN (decl))
4389             {
4390               error ("nested functions are limited to 2 register parameters");
4391               error_issued = true;
4392               return 0;
4393             }
4394         }
4395 
4396       return regparm;
4397     }
4398 
4399   if (lookup_attribute ("fastcall", TYPE_ATTRIBUTES (type)))
4400     return 2;
4401 
4402   /* Use register calling convention for local functions when possible.  */
4403   if (decl
4404       && TREE_CODE (decl) == FUNCTION_DECL
4405       && optimize
4406       && (TARGET_64BIT || !flag_strict_calling_conventions)
4407       && !profile_flag)
4408     {
4409       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4410       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4411       if (i && i->local)
4412         {
4413           int local_regparm, globals = 0, regno;
4414           struct function *f;
4415 
4416           /* Make sure no regparm register is taken by a
4417              fixed register variable.  */
4418           for (local_regparm = 0; local_regparm < REGPARM_MAX; local_regparm++)
4419             if (fixed_regs[local_regparm])
4420               break;
4421 
4422           /* We can't use regparm(3) for nested functions as these use
4423              static chain pointer in third argument.  */
4424           if (local_regparm == 3
4425               && decl_function_context (decl)
4426               && !DECL_NO_STATIC_CHAIN (decl))


4471     {
4472       if (!TARGET_SSE)
4473         {
4474           if (warn)
4475             {
4476               if (decl)
4477                 error ("Calling %qD with attribute sseregparm without "
4478                        "SSE/SSE2 enabled", decl);
4479               else
4480                 error ("Calling %qT with attribute sseregparm without "
4481                        "SSE/SSE2 enabled", type);
4482             }
4483           return 0;
4484         }
4485 
4486       return 2;
4487     }
4488 
4489   /* For local functions, pass up to SSE_REGPARM_MAX SFmode
4490      (and DFmode for SSE2) arguments in SSE registers.  */
4491   if (decl && TARGET_SSE_MATH && optimize && !profile_flag &&
4492     (TARGET_64BIT || !flag_strict_calling_conventions))
4493     {
4494       /* FIXME: remove this CONST_CAST when cgraph.[ch] is constified.  */
4495       struct cgraph_local_info *i = cgraph_local_info (CONST_CAST_TREE(decl));
4496       if (i && i->local)
4497         return TARGET_SSE2 ? 2 : 1;
4498     }
4499 
4500   return 0;
4501 }
4502 
4503 /* Return true if EAX is live at the start of the function.  Used by
4504    ix86_expand_prologue to determine if we need special help before
4505    calling allocate_stack_worker.  */
4506 
4507 static bool
4508 ix86_eax_live_at_start_p (void)
4509 {
4510   /* Cheat.  Don't bother working forward from ix86_function_regparm
4511      to the function type to whether an actual argument is located in
4512      eax.  Instead just look at cfg info, which is still close enough