Patchwork Fix gcov handling directories with periods

login
register
mail settings
Submitter Andreas Schwab
Date Oct. 13, 2012, 3:51 p.m.
Message ID <m2bog69xqx.fsf@igel.home>
Download mbox | patch
Permalink /patch/191299/
State New
Headers show

Comments

Andreas Schwab - Oct. 13, 2012, 3:51 p.m.
PR gcov-profile/44728
	* gcov.c (create_file_names): When stripping extension only look
	at base name.
---
 gcc/gcov.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Ian Taylor - Oct. 13, 2012, 5:53 p.m.
On Sat, Oct 13, 2012 at 8:51 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:
>         PR gcov-profile/44728
>         * gcov.c (create_file_names): When stripping extension only look
>         at base name.

> diff --git a/gcc/gcov.c b/gcc/gcov.c
> index cf26ce1..09831c2 100644
> --- a/gcc/gcov.c
> +++ b/gcc/gcov.c
> @@ -842,7 +842,7 @@ create_file_names (const char *file_name)
>      }
>
>    /* Remove the extension.  */
> -  cptr = strrchr (name, '.');
> +  cptr = strrchr (CONST_CAST (char *, lbasename (name)), '.');
>    if (cptr)
>      *cptr = 0;

Why do you need the CONST_CAST?  strrchr is a standard function and it
takes const char * as the first argument.  There is other code in gcc
that calls strrchr with a const char * argument.

This patch is OK without the CONST_CAST.

Thanks.

Ian
Andreas Schwab - Oct. 13, 2012, 6:23 p.m.
Ian Lance Taylor <iant@google.com> writes:

> Why do you need the CONST_CAST?  strrchr is a standard function and it
> takes const char * as the first argument.  There is other code in gcc
> that calls strrchr with a const char * argument.

strrchr is overloaded as const and non-const in C++.  We need the
non-const version.

Andreas.
Ian Taylor - Oct. 13, 2012, 7:19 p.m.
On Sat, Oct 13, 2012 at 11:23 AM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Ian Lance Taylor <iant@google.com> writes:
>
>> Why do you need the CONST_CAST?  strrchr is a standard function and it
>> takes const char * as the first argument.  There is other code in gcc
>> that calls strrchr with a const char * argument.
>
> strrchr is overloaded as const and non-const in C++.  We need the
> non-const version.

Oh yeah.  Really we should overload lbasename the same way.

Suppose you drop this into include/libiberty.h:

#ifdef __cplusplus
inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); }
#endif

I'll preapprove that if it works.

Ian
Andreas Schwab - Oct. 13, 2012, 8:11 p.m.
Ian Lance Taylor <iant@google.com> writes:

> Suppose you drop this into include/libiberty.h:
>
> #ifdef __cplusplus
> inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); }
> #endif

That doesn't work:

../../gcc/libcpp/../include/libiberty.h: In function ‘char* lbasename(char*)’:
../../gcc/libcpp/../include/libiberty.h:123:31: error: declaration of C function ‘char* lbasename(char*)’ conflicts with
../../gcc/libcpp/../include/libiberty.h:121:20: error: previous declaration ‘const char* lbasename(const char*)’ here

Andreas.
Ian Taylor - Oct. 15, 2012, 4 a.m.
On Sat, Oct 13, 2012 at 1:11 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
> Ian Lance Taylor <iant@google.com> writes:
>
>> Suppose you drop this into include/libiberty.h:
>>
>> #ifdef __cplusplus
>> inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); }
>> #endif
>
> That doesn't work:
>
> ../../gcc/libcpp/../include/libiberty.h: In function ‘char* lbasename(char*)’:
> ../../gcc/libcpp/../include/libiberty.h:123:31: error: declaration of C function ‘char* lbasename(char*)’ conflicts with
> ../../gcc/libcpp/../include/libiberty.h:121:20: error: previous declaration ‘const char* lbasename(const char*)’ here

Hmmm, of course.

OK, your patch with CONST_CAST is OK.

Thanks.

Ian
Pedro Alves - Oct. 15, 2012, 9:59 a.m.
On 10/15/2012 05:00 AM, Ian Lance Taylor wrote:
> On Sat, Oct 13, 2012 at 1:11 PM, Andreas Schwab <schwab@linux-m68k.org> wrote:
>> Ian Lance Taylor <iant@google.com> writes:
>>
>>> Suppose you drop this into include/libiberty.h:
>>>
>>> #ifdef __cplusplus
>>> inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); }
>>> #endif
>>
>> That doesn't work:
>>
>> ../../gcc/libcpp/../include/libiberty.h: In function ‘char* lbasename(char*)’:
>> ../../gcc/libcpp/../include/libiberty.h:123:31: error: declaration of C function ‘char* lbasename(char*)’ conflicts with
>> ../../gcc/libcpp/../include/libiberty.h:121:20: error: previous declaration ‘const char* lbasename(const char*)’ here
> 
> Hmmm, of course.

Wrapping with extern "C++" makes it work:

#ifdef __cplusplus
extern "C++"
{
inline char *lbasename(char *s) { return const_cast<char*>(lbasename (s)); }
}
#endif

> 
> OK, your patch with CONST_CAST is OK.
> 
> Thanks.

Patch

diff --git a/gcc/gcov.c b/gcc/gcov.c
index cf26ce1..09831c2 100644
--- a/gcc/gcov.c
+++ b/gcc/gcov.c
@@ -842,7 +842,7 @@  create_file_names (const char *file_name)
     }
 
   /* Remove the extension.  */
-  cptr = strrchr (name, '.');
+  cptr = strrchr (CONST_CAST (char *, lbasename (name)), '.');
   if (cptr)
     *cptr = 0;