diff mbox

libgcc: quote ARM macro parameters

Message ID 1443891054-24079-1-git-send-email-compnerd@compnerd.org
State New
Headers show

Commit Message

Saleem Abdulrasool Oct. 3, 2015, 4:50 p.m. UTC
For ARM EHABI _Unwind_{G,S}setIP are macros rather than proper functions as they
are extensions to the EHABI specification (though they are part of the Level 1
interface).  Quote the macro parameters, as otherwise, a complex parameter may
be ambiguously mis-expanded.
---
 libgcc/config/arm/unwind-arm.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Andreas Schwab Oct. 3, 2015, 6:29 p.m. UTC | #1
Saleem Abdulrasool <compnerd@compnerd.org> writes:

> For ARM EHABI _Unwind_{G,S}setIP are macros rather than proper functions as they
> are extensions to the EHABI specification (though they are part of the Level 1
> interface).  Quote the macro parameters, as otherwise, a complex parameter may
> be ambiguously mis-expanded.
> ---
>  libgcc/config/arm/unwind-arm.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libgcc/config/arm/unwind-arm.h b/libgcc/config/arm/unwind-arm.h
> index f1f789c..3821c08 100644
> --- a/libgcc/config/arm/unwind-arm.h
> +++ b/libgcc/config/arm/unwind-arm.h
> @@ -74,10 +74,10 @@ extern "C" {
>      }
>    /* Return the address of the instruction, not the actual IP value.  */
>  #define _Unwind_GetIP(context) \
> -  (_Unwind_GetGR (context, 15) & ~(_Unwind_Word)1)
> +  (_Unwind_GetGR ((context), 15) & ~(_Unwind_Word)1)

How can that get mis-expanded (other than cheating with a macro that
expands to a comma)?

Andreas.
Andreas Schwab Oct. 3, 2015, 7:21 p.m. UTC | #2
Saleem Abdulrasool <compnerd@compnerd.org> writes:

> On Saturday, October 3, 2015, Andreas Schwab <schwab@linux-m68k.org> wrote:
>
>> Saleem Abdulrasool <compnerd@compnerd.org <javascript:;>> writes:
>>
>> > For ARM EHABI _Unwind_{G,S}setIP are macros rather than proper functions
>> as they
>> > are extensions to the EHABI specification (though they are part of the
>> Level 1
>> > interface).  Quote the macro parameters, as otherwise, a complex
>> parameter may
>> > be ambiguously mis-expanded.
>> > ---
>> >  libgcc/config/arm/unwind-arm.h | 4 ++--
>> >  1 file changed, 2 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/libgcc/config/arm/unwind-arm.h
>> b/libgcc/config/arm/unwind-arm.h
>> > index f1f789c..3821c08 100644
>> > --- a/libgcc/config/arm/unwind-arm.h
>> > +++ b/libgcc/config/arm/unwind-arm.h
>> > @@ -74,10 +74,10 @@ extern "C" {
>> >      }
>> >    /* Return the address of the instruction, not the actual IP value.  */
>> >  #define _Unwind_GetIP(context) \
>> > -  (_Unwind_GetGR (context, 15) & ~(_Unwind_Word)1)
>> > +  (_Unwind_GetGR ((context), 15) & ~(_Unwind_Word)1)
>>
>> How can that get mis-expanded (other than cheating with a macro that
>> expands to a comma)?
>>
>
> Poor choice of words on my part.  It won't mis-expand, it may expand into
> an "ambiguous" statement (which will be diagnosed with a warning) if the
> argument is an expression in the sense of:
>
> a + b | 1

That cannot happen here, unless the caller already passes such an
expression.

Andreas.
diff mbox

Patch

diff --git a/libgcc/config/arm/unwind-arm.h b/libgcc/config/arm/unwind-arm.h
index f1f789c..3821c08 100644
--- a/libgcc/config/arm/unwind-arm.h
+++ b/libgcc/config/arm/unwind-arm.h
@@ -74,10 +74,10 @@  extern "C" {
     }
   /* Return the address of the instruction, not the actual IP value.  */
 #define _Unwind_GetIP(context) \
-  (_Unwind_GetGR (context, 15) & ~(_Unwind_Word)1)
+  (_Unwind_GetGR ((context), 15) & ~(_Unwind_Word)1)
 
 #define _Unwind_SetIP(context, val) \
-  _Unwind_SetGR (context, 15, val | (_Unwind_GetGR (context, 15) & 1))
+  _Unwind_SetGR ((context), 15, (val) | (_Unwind_GetGR ((context), 15) & 1))
 
 #ifdef __cplusplus
 }   /* extern "C" */