diff mbox

tci: Use uintptr_t for the GETPC() macro

Message ID 1334680565-17024-1-git-send-email-sw@weilnetz.de
State Superseded
Headers show

Commit Message

Stefan Weil April 17, 2012, 4:36 p.m. UTC
This completes commit 2050396801ca0c8359364d61eaadece951006057
and fixes builds with TCI.

Signed-off-by: Stefan Weil <sw@weilnetz.de>
---
 exec-all.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

Comments

Eric Blake April 17, 2012, 4:40 p.m. UTC | #1
On 04/17/2012 10:36 AM, Stefan Weil wrote:
> This completes commit 2050396801ca0c8359364d61eaadece951006057
> and fixes builds with TCI.
> 
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>  exec-all.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/exec-all.h b/exec-all.h
> index a963fd4..e766f9d 100644
> --- a/exec-all.h
> +++ b/exec-all.h
> @@ -284,7 +284,7 @@ extern int tb_invalidated_flag;
>     For all others, GETPC remains undefined (which makes TCI a little faster. */
>  # if defined(CONFIG_SOFTMMU) || defined(TARGET_ALPHA) || defined(TARGET_SH4)
>  extern void *tci_tb_ptr;
> -#  define GETPC() tci_tb_ptr
> +#  define GETPC() (uintptr_t)tci_tb_ptr

Missing ().  Any time you add a cast to a macro, you need to fully
parenthesize the entire expression.
Stefan Weil April 17, 2012, 4:49 p.m. UTC | #2
Am 17.04.2012 18:40, schrieb Eric Blake:
> On 04/17/2012 10:36 AM, Stefan Weil wrote:
>> This completes commit 2050396801ca0c8359364d61eaadece951006057
>> and fixes builds with TCI.
>>
>> Signed-off-by: Stefan Weil<sw@weilnetz.de>
>> ---
>>   exec-all.h |    2 +-
>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>
>> diff --git a/exec-all.h b/exec-all.h
>> index a963fd4..e766f9d 100644
>> --- a/exec-all.h
>> +++ b/exec-all.h
>> @@ -284,7 +284,7 @@ extern int tb_invalidated_flag;
>>      For all others, GETPC remains undefined (which makes TCI a little faster. */
>>   # if defined(CONFIG_SOFTMMU) || defined(TARGET_ALPHA) || defined(TARGET_SH4)
>>   extern void *tci_tb_ptr;
>> -#  define GETPC() tci_tb_ptr
>> +#  define GETPC() (uintptr_t)tci_tb_ptr
> Missing ().  Any time you add a cast to a macro, you need to fully
> parenthesize the entire expression.

This is a good rule in general, but not needed here, because
tci_tb_ptr is not a macro argument nor a macro!

The declaration of tci_tb_ptr is preceding the GETPC() macro.

Cheers,
Stefan W.
Eric Blake April 17, 2012, 5:02 p.m. UTC | #3
On 04/17/2012 10:49 AM, Stefan Weil wrote:
> Am 17.04.2012 18:40, schrieb Eric Blake:
>> On 04/17/2012 10:36 AM, Stefan Weil wrote:
>>> This completes commit 2050396801ca0c8359364d61eaadece951006057
>>> and fixes builds with TCI.
>>>
>>> Signed-off-by: Stefan Weil<sw@weilnetz.de>
>>> ---
>>>   exec-all.h |    2 +-
>>>   1 files changed, 1 insertions(+), 1 deletions(-)
>>>
>>> diff --git a/exec-all.h b/exec-all.h
>>> index a963fd4..e766f9d 100644
>>> --- a/exec-all.h
>>> +++ b/exec-all.h
>>> @@ -284,7 +284,7 @@ extern int tb_invalidated_flag;
>>>      For all others, GETPC remains undefined (which makes TCI a
>>> little faster. */
>>>   # if defined(CONFIG_SOFTMMU) || defined(TARGET_ALPHA) ||
>>> defined(TARGET_SH4)
>>>   extern void *tci_tb_ptr;
>>> -#  define GETPC() tci_tb_ptr
>>> +#  define GETPC() (uintptr_t)tci_tb_ptr
>> Missing ().  Any time you add a cast to a macro, you need to fully
>> parenthesize the entire expression.
> 
> This is a good rule in general, but not needed here, because
> tci_tb_ptr is not a macro argument nor a macro!

Not true.  You _don't_ know how GETPC() will be used in context in
future code, and there are operators with higher precedence than
casting.  Consider:

GETPC()++ is silently accepted by your code, but with proper parentheses:

#define GETPC() ((uintptr_t)tci_tb_ptr)

then GETPC()++ will be a compilation error.
Stefan Weil April 17, 2012, 5:11 p.m. UTC | #4
Am 17.04.2012 19:02, schrieb Eric Blake:
> On 04/17/2012 10:49 AM, Stefan Weil wrote:
>> Am 17.04.2012 18:40, schrieb Eric Blake:
>>> On 04/17/2012 10:36 AM, Stefan Weil wrote:
>>>> This completes commit 2050396801ca0c8359364d61eaadece951006057
>>>> and fixes builds with TCI.
>>>>
>>>> Signed-off-by: Stefan Weil<sw@weilnetz.de>
>>>> ---
>>>> exec-all.h | 2 +-
>>>> 1 files changed, 1 insertions(+), 1 deletions(-)
>>>>
>>>> diff --git a/exec-all.h b/exec-all.h
>>>> index a963fd4..e766f9d 100644
>>>> --- a/exec-all.h
>>>> +++ b/exec-all.h
>>>> @@ -284,7 +284,7 @@ extern int tb_invalidated_flag;
>>>> For all others, GETPC remains undefined (which makes TCI a
>>>> little faster. */
>>>> # if defined(CONFIG_SOFTMMU) || defined(TARGET_ALPHA) ||
>>>> defined(TARGET_SH4)
>>>> extern void *tci_tb_ptr;
>>>> -# define GETPC() tci_tb_ptr
>>>> +# define GETPC() (uintptr_t)tci_tb_ptr
>>> Missing (). Any time you add a cast to a macro, you need to fully
>>> parenthesize the entire expression.
>>
>> This is a good rule in general, but not needed here, because
>> tci_tb_ptr is not a macro argument nor a macro!
>
> Not true. You _don't_ know how GETPC() will be used in context in
> future code, and there are operators with higher precedence than
> casting. Consider:
>
> GETPC()++ is silently accepted by your code, but with proper parentheses:
>
> #define GETPC() ((uintptr_t)tci_tb_ptr)
>
> then GETPC()++ will be a compilation error.

tci_tb_ptr is a void pointer. Therefore the ++ operator will either
raise a compilation error or gcc will handle it as if it were a
char pointer. In that case the code would even work :-)

Are there other operators with higher precedence which might
be critical?

Nevertheless I see your point, so I'll send a new patch which
works without any doubt.
diff mbox

Patch

diff --git a/exec-all.h b/exec-all.h
index a963fd4..e766f9d 100644
--- a/exec-all.h
+++ b/exec-all.h
@@ -284,7 +284,7 @@  extern int tb_invalidated_flag;
    For all others, GETPC remains undefined (which makes TCI a little faster. */
 # if defined(CONFIG_SOFTMMU) || defined(TARGET_ALPHA) || defined(TARGET_SH4)
 extern void *tci_tb_ptr;
-#  define GETPC() tci_tb_ptr
+#  define GETPC() (uintptr_t)tci_tb_ptr
 # endif
 #elif defined(__s390__) && !defined(__s390x__)
 # define GETPC() \