Quantcast

AC_EGREP_CPP and AC_EGREP_HEADER users - beware of recent gcc

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

AC_EGREP_CPP and AC_EGREP_HEADER users - beware of recent gcc

Bruno Haible
Hi all,

Some uses of AC_EGREP_CPP and AC_EGREP_HEADER probably assume that when
no continuation lines (backslash-newline) and no multiline macro invocations
are involved, each source line produces at most one output line.

This is no longer the case with GCC >= 5.

Example:
=============== foo.c ===============
#include <features.h>
#define FOO 2
#define FOO_VERSION 12

Version FOO . FOO_VERSION
Version __GLIBC__ . __GLIBC_MINOR__

#define show(a,b) Version a . b
show(FOO,FOO_VERSION)
show(__GLIBC__,__GLIBC_MINOR__)
=====================================

With gcc-4.9.4:
$ gcc -E foo.c
[...]

Version 2 . 12
Version 2 . 23


Version 2 . 12
Version 2 . 23

With gcc-5.1.0 and newer:
$ gcc -E foo.c
[...]

Version 2 . 12
Version
# 6 "foo.c" 3 4
       2
# 6 "foo.c"
                 .
# 6 "foo.c" 3 4
                   23



# 9 "foo.c"
Version 2 . 12
Version
# 10 "foo.c" 3 4
2
# 10 "foo.c"
.
# 10 "foo.c" 3 4
23


As you can see, here 1 source line produces up to 4 output lines (ignoring the
line number comment lines). Attempts to use 'grep Version' to find the values of
__GLIBC__ and __GLIBC_VERSION__ don't work any more.

Maybe the documentation of AC_EGREP_CPP and AC_EGREP_HEADER could include
a caveat about this?

Bruno


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AC_EGREP_CPP and AC_EGREP_HEADER users - beware of recent gcc

Eric Blake-3
On 02/15/2017 04:52 AM, Bruno Haible wrote:
> Hi all,
>
> Some uses of AC_EGREP_CPP and AC_EGREP_HEADER probably assume that when
> no continuation lines (backslash-newline) and no multiline macro invocations
> are involved, each source line produces at most one output line.
>
> This is no longer the case with GCC >= 5.

> As you can see, here 1 source line produces up to 4 output lines (ignoring the
> line number comment lines). Attempts to use 'grep Version' to find the values of
> __GLIBC__ and __GLIBC_VERSION__ don't work any more.
>
> Maybe the documentation of AC_EGREP_CPP and AC_EGREP_HEADER could include
> a caveat about this?

Indeed. grep'ping has always been fragile, but adding another warning
can't hurt.  I'll see if I can come up with a patch

--
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


signature.asc (617 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AC_EGREP_CPP and AC_EGREP_HEADER users - beware of recent gcc

Mike Frysinger
In reply to this post by Bruno Haible
On 15 Feb 2017 11:52, Bruno Haible wrote:

> Some uses of AC_EGREP_CPP and AC_EGREP_HEADER probably assume that when
> no continuation lines (backslash-newline) and no multiline macro invocations
> are involved, each source line produces at most one output line.
>
> This is no longer the case with GCC >= 5.
>
> Example:
> =============== foo.c ===============
> #include <features.h>
> #define FOO 2
> #define FOO_VERSION 12
>
> Version FOO . FOO_VERSION
> Version __GLIBC__ . __GLIBC_MINOR__
>
> #define show(a,b) Version a . b
> show(FOO,FOO_VERSION)
> show(__GLIBC__,__GLIBC_MINOR__)
> =====================================
>
> With gcc-4.9.4:
> $ gcc -E foo.c
> [...]
>
> Version 2 . 12
> Version 2 . 23
>
>
> Version 2 . 12
> Version 2 . 23
>
> With gcc-5.1.0 and newer:
> $ gcc -E foo.c
> [...]
>
> Version 2 . 12
> Version
> # 6 "foo.c" 3 4
>        2
> # 6 "foo.c"
>                  .
> # 6 "foo.c" 3 4
>                    23
>
>
>
> # 9 "foo.c"
> Version 2 . 12
> Version
> # 10 "foo.c" 3 4
> 2
> # 10 "foo.c"
> .
> # 10 "foo.c" 3 4
> 23
>
>
> As you can see, here 1 source line produces up to 4 output lines (ignoring the
> line number comment lines). Attempts to use 'grep Version' to find the values of
> __GLIBC__ and __GLIBC_VERSION__ don't work any more.
>
> Maybe the documentation of AC_EGREP_CPP and AC_EGREP_HEADER could include
> a caveat about this?
seems like we be using -P with CPP when it's supported ?
-mike

signature.asc (849 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: AC_EGREP_CPP and AC_EGREP_HEADER users - beware of recent gcc

Bruno Haible
Mike Frysinger wrote:
> > As you can see, here 1 source line produces up to 4 output lines (ignoring the
> > line number comment lines). Attempts to use 'grep Version' to find the values of
> > __GLIBC__ and __GLIBC_VERSION__ don't work any more.
>
> seems like we be using -P with CPP when it's supported ?

Yes, good idea!

Bruno



Loading...