Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation warnings with clang 9.0.0 #17015

Closed
p5pRT opened this issue May 23, 2019 · 15 comments
Closed

Compilation warnings with clang 9.0.0 #17015

p5pRT opened this issue May 23, 2019 · 15 comments
Labels
build-time-warnings Replaces [META] Build-time warnings RT #133556 type-core

Comments

@p5pRT
Copy link

p5pRT commented May 23, 2019

Migrated from rt.perl.org#134131 (status was 'open')

Searchable as RT134131$

@p5pRT
Copy link
Author

p5pRT commented May 23, 2019

From @dur-randir

Created by @dur-randir

I get the following warnings when building perl on Debian with clang 9.0.0

Wstring-plus-int​:

sv.c​:12490​:41​: warning​: adding 'int' to a string does not append to
the string [-Wstring-plus-int]
  && strnEQ(q + 1, UTF8f + 2, sizeof(UTF8f) - 3))
  ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
./handy.h​:508​:37​: note​: expanded from macro 'strnEQ'
#define strnEQ(s1,s2,l) (strncmp(s1,s2,l) == 0)
  ^~
sv.c​:12490​:41​: note​: use array indexing to silence this warning
  && strnEQ(q + 1, UTF8f + 2, sizeof(UTF8f) - 3))
  ^
  & [
./handy.h​:508​:37​: note​: expanded from macro 'strnEQ'
#define strnEQ(s1,s2,l) (strncmp(s1,s2,l) == 0)
  ^
1 warning generated.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.31.0:

Configured by dur-randir at Wed Feb 27 14:51:01 MSK 2019.

Summary of my perl5 (revision 5 version 31 subversion 0) configuration:
  Commit id: 58f4626762668e1c1948832073998af84b2c85d0
  Platform:
    osname=linux
    osvers=4.19.0-5-amd64
    archname=x86_64-linux
    uname='linux dorothy 4.19.0-5-amd64 #1 smp debian 4.19.37-3
(2019-05-15) x86_64 gnulinux '
    config_args='-de -Dusedevel -DDEBUGGING -Dcc=clang-9'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='clang-9'
    ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2 -g'
    cppflags='-DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='4.2.1 Compatible Clang 9.0.0 (trunk)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='clang-9'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/llvm-9/lib/clang/9.0.0/lib
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu
/lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.28.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.28'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl):
  Compile-time options:
    DEBUGGING
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_DEVEL
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at May 23 2019 12:26:06
  %ENV:
    PERLBREW_BASHRC_VERSION="0.78"
    PERLBREW_HOME="/home/afl/.perlbrew"
    PERLBREW_MANPATH="/home/afl/perlbrew/perls/perl-5.20.2/man"
    PERLBREW_PATH="/home/afl/perlbrew/bin:/home/afl/perlbrew/perls/perl-5.20.2/bin"
    PERLBREW_PERL="perl-5.20.2"
    PERLBREW_ROOT="/home/afl/perlbrew"
    PERLBREW_VERSION="0.78"
  @INC:
    lib
    /usr/local/lib/perl5/site_perl/5.31.0/x86_64-linux
    /usr/local/lib/perl5/site_perl/5.31.0
    /usr/local/lib/perl5/5.31.0/x86_64-linux
    /usr/local/lib/perl5/5.31.0

@p5pRT
Copy link
Author

p5pRT commented May 23, 2019

From @demerphq

Am I missing something here? This seems like pretty reasonable code and
perfectly normal pointer arithmetic.

Yves

On Thu, 23 May 2019, 11​:34 Sergey Aleynikov (via RT), <
perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Sergey Aleynikov
# Please include the string​: [perl #134131]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=134131 >

This is a bug report for perl from sergey.aleynikov@​gmail.com,
generated with the help of perlbug 1.41 running under perl 5.31.0.

-----------------------------------------------------------------
[Please describe your issue here]

I get the following warnings when building perl on Debian with clang 9.0.0

Wstring-plus-int​:

sv.c​:12490​:41​: warning​: adding 'int' to a string does not append to
the string [-Wstring-plus-int]
&& strnEQ(q + 1, UTF8f + 2, sizeof(UTF8f) - 3))
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
./handy.h​:508​:37​: note​: expanded from macro 'strnEQ'
#define strnEQ(s1,s2,l) (strncmp(s1,s2,l) == 0)
^~
sv.c​:12490​:41​: note​: use array indexing to silence this warning
&& strnEQ(q + 1, UTF8f + 2, sizeof(UTF8f) - 3))
^
& [
./handy.h​:508​:37​: note​: expanded from macro 'strnEQ'
#define strnEQ(s1,s2,l) (strncmp(s1,s2,l) == 0)
^
1 warning generated.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=core
severity=low
---
Site configuration information for perl 5.31.0​:

Configured by dur-randir at Wed Feb 27 14​:51​:01 MSK 2019.

Summary of my perl5 (revision 5 version 31 subversion 0) configuration​:
Commit id​: 58f4626
Platform​:
osname=linux
osvers=4.19.0-5-amd64
archname=x86_64-linux
uname='linux dorothy 4.19.0-5-amd64 #1 smp debian 4.19.37-3
(2019-05-15) x86_64 gnulinux '
config_args='-de -Dusedevel -DDEBUGGING -Dcc=clang-9'
hint=recommended
useposix=true
d_sigaction=define
useithreads=undef
usemultiplicity=undef
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
bincompat5005=undef
Compiler​:
cc='clang-9'
ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
optimize='-O2 -g'
cppflags='-DDEBUGGING -fno-strict-aliasing -pipe
-fstack-protector-strong -I/usr/local/include'
ccversion=''
gccversion='4.2.1 Compatible Clang 9.0.0 (trunk)'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries​:
ld='clang-9'
ldflags =' -fstack-protector-strong -L/usr/local/lib'
libpth=/usr/local/lib /usr/lib/llvm-9/lib/clang/9.0.0/lib
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu
/lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
libc=libc-2.28.so
so=so
useshrplib=false
libperl=libperl.a
gnulibc_version='2.28'
Dynamic Linking​:
dlsrc=dl_dlopen.xs
dlext=so
d_dlsymun=undef
ccdlflags='-Wl,-E'
cccdlflags='-fPIC'
lddlflags='-shared -O2 -g -L/usr/local/lib -fstack-protector-strong'

Characteristics of this binary (from libperl)​:
Compile-time options​:
DEBUGGING
HAS_TIMES
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_DEVEL
USE_64_BIT_ALL
USE_64_BIT_INT
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
Built under linux
Compiled at May 23 2019 12​:26​:06
%ENV​:
PERLBREW_BASHRC_VERSION="0.78"
PERLBREW_HOME="/home/afl/.perlbrew"
PERLBREW_MANPATH="/home/afl/perlbrew/perls/perl-5.20.2/man"

PERLBREW_PATH="/home/afl/perlbrew/bin​:/home/afl/perlbrew/perls/perl-5.20.2/bin"
PERLBREW_PERL="perl-5.20.2"
PERLBREW_ROOT="/home/afl/perlbrew"
PERLBREW_VERSION="0.78"
@​INC​:
lib
/usr/local/lib/perl5/site_perl/5.31.0/x86_64-linux
/usr/local/lib/perl5/site_perl/5.31.0
/usr/local/lib/perl5/5.31.0/x86_64-linux
/usr/local/lib/perl5/5.31.0

@p5pRT
Copy link
Author

p5pRT commented May 23, 2019

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 23, 2019

From @hvds

On Thu, 23 May 2019 08​:06​:30 -0700, demerphq wrote​:

Am I missing something here? This seems like pretty reasonable code
and perfectly normal pointer arithmetic.

I think it's warning you that this isn't C++. I don't think this is one we should care about.

Hugo

@p5pRT
Copy link
Author

p5pRT commented May 23, 2019

From @dur-randir

On Thu, 23 May 2019 08​:18​:28 -0700, hv wrote​:

I think it's warning you that this isn't C++. I don't think this is
one we should care about.

This is also in their's default warnings set, i'll check is it only for clang9 or has appeared earlier.

@p5pRT
Copy link
Author

p5pRT commented May 24, 2019

From @dur-randir

On Thu, 23 May 2019 08​:06​:30 -0700, demerphq wrote​:

Am I missing something here? This seems like pretty reasonable code
and perfectly normal pointer arithmetic.

This warning was added in clang 8.0.0, released in March 2019. They've already had some discussion about it's usefulness in https://reviews.llvm.org/D55382.

@jkeenan jkeenan added the build-time-warnings Replaces [META] Build-time warnings RT #133556 label Nov 4, 2019
@jkeenan
Copy link
Contributor

jkeenan commented Nov 13, 2020

I now have clang-10 available on Linux. Here is an update on the build-time warnings we're getting on unthreaded builds on Linux using that C-compiler.

$ clang --version
clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

non-DEBUGGING

$ ./perl -Ilib -V:config_args
config_args='-des -Dusedevel -Dcc=clang'

$ report-build-warnings blead.2ce8ebb919.linux.clang-10.maketp.output.txt.gz 
File:  blead.2ce8ebb919.linux.clang-10.maketp.output.txt.gz

  W#pragma-messages                          4
  Wimplicit-int-float-conversion             6
  Wstring-compare                            2
  Wstring-plus-int                           1

DEBUGGING (as originally reported with clang-9 in this ticket)

$ ./perl -Ilib -V:config_args
config_args='-des -Dusedevel -DDEBUGGING -Dcc=clang';

$ report-build-warnings blead.2ce8ebb919.linux.clang-10.debugging.maketp.output.txt.gz 
File:  blead.2ce8ebb919.linux.clang-10.debugging.maketp.output.txt.gz

  W#pragma-messages                          4
  Wimplicit-int-float-conversion             6
  Wstring-compare                           27
  Wstring-plus-int                           1

And, for good measure, Threaded, non-DEBUGGING

 report-build-warnings blead.2ce8ebb919.linux.clang-10.threaded.maketp.output.txt.gz 
File:  blead.2ce8ebb919.linux.clang-10.threaded.maketp.output.txt.gz

  W#pragma-messages                          4
  Wimplicit-int-float-conversion             6
  Wstring-compare                            2
  Wstring-plus-int                           1

I can supply further data upon request.

Thank you very much.
Jim Keenan

@demerphq
Copy link
Collaborator

demerphq commented Nov 14, 2020 via email

@jkeenan
Copy link
Contributor

jkeenan commented Mar 22, 2021

I now have clang-10 available on Linux. Here is an update on the build-time warnings we're getting on unthreaded builds on Linux using that C-compiler.

And, for good measure, Threaded, non-DEBUGGING

 report-build-warnings blead.2ce8ebb919.linux.clang-10.threaded.maketp.output.txt.gz 
File:  blead.2ce8ebb919.linux.clang-10.threaded.maketp.output.txt.gz

  W#pragma-messages                          4
  Wimplicit-int-float-conversion             6
  Wstring-compare                            2
  Wstring-plus-int                           1

We've improved. Compiling a threaded build on Linux using clang-10 as compiler, we're now down to:

$ report-build-warnings blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz 
File:  blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz

  Wstring-compare                            2
  Wstring-plus-int                           1

$ parse-build-warnings blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz 
File:  blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz

[
  {
    char   => 41,
    group  => "Wstring-plus-int",
    line   => 12517,
    source => "sv.c",
    text   => "adding 'int' to a string does not append to the string",
  },
  {
    char   => 37,
    group  => "Wstring-compare",
    line   => 8219,
    source => "re_comp.c",
    text   => "result of comparison against a string literal is unspecified (use an explicit string comparison function instead)",
  },
  {
    char   => 2,
    group  => "Wstring-compare",
    line   => 8267,
    source => "re_comp.c",
    text   => "result of comparison against a string literal is unspecified (use an explicit string comparison function instead)",
  },
]

This matches the build-time warnings output I'm getting with clang-10 on FreeBSD-12 as well.

Thank you very much.
Jim Keenan

@hvds
Copy link
Contributor

hvds commented Mar 22, 2021

We've improved. Compiling a threaded build on Linux using clang-10 as compiler, we're now down to:

$ report-build-warnings blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz 
File:  blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz

  Wstring-compare                            2
  Wstring-plus-int                           1

$ parse-build-warnings blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz 
File:  blead.3e25f6d2dc.linux.clang-10.threaded.maketp.output.txt.gz

[
  {
    char   => 41,
    group  => "Wstring-plus-int",
    line   => 12517,
    source => "sv.c",
    text   => "adding 'int' to a string does not append to the string",
  },

As before, this is perfectly normal pointer arithmetic - the warning is aimed at people who half-learned a bit of C++. We could satisfy it by replacing q + 1 with something like &q[1], but that makes the code worse so we shouldn't do it. We should ignore or shut up the warning instead, preferably globally.

As @jkeenan has worked out, the q + 1 was not what it was complaining about at all, but rather the following argument UTF8f + 2, where the UTF8f is a macro involving some string concatenation unprotected by brackets.

{
char => 37,
group => "Wstring-compare",
line => 8219,
source => "re_comp.c",
text => "result of comparison against a string literal is unspecified (use an explicit string comparison function instead)",
},

This one is perhaps a bit more defensible; it's coming from LEAVE_with_name("study_chunk"), defined in scope.c as a macro with argument "name" (and documented that the argument should be a string literal). It checks whether the scope we're leaving has the right name using:

            assert(((char*)PL_scopestack_name[PL_scopestack_ix-1]       \
                        == (char*)name)                                 \
                    || strEQ(PL_scopestack_name[PL_scopestack_ix-1], name));        \

It's clearly there as an optimization to avoid the cost of a strEQ() when it's the same pointer, but if that truly gives undefined behaviour for a string literal we could just use the strEQ() always.

However if the degree of undefinedness is only that there may be multiple copies of a string literal resulting in distinct pointers, then the check could still be perfectly safe and will likely still often be useful: scope entry and exit is a pretty hot path in perl, and it would be a shame to slow it down just because a compiler is being extra pedantic.

If it is "undefined" to the degree that "foo" == "bar" could be true, then our code is wrong and we should change it.

Hugo

@khwilliamson
Copy link
Contributor

khwilliamson commented Mar 22, 2021 via email

jkeenan added a commit that referenced this issue Mar 28, 2021
Observed in clang 9 and 10.

Partial solution for #17015
jkeenan added a commit that referenced this issue Apr 1, 2021
Observed in clang 9 and 10.

Partial solution for #17015
@jkeenan
Copy link
Contributor

jkeenan commented Apr 1, 2021

1 build-time warning quieted by #18671; more remain; ticket stays open.

Corion pushed a commit to Corion/perl5 that referenced this issue Jun 20, 2021
Observed in clang 9 and 10.

Partial solution for Perl#17015
@jkeenan
Copy link
Contributor

jkeenan commented Jul 5, 2021

1 build-time warning quieted by #18671; more remain; ticket stays open.

2 build-time warnings (-Wstring-compare) closed by f7b3322. There remain 2 -Wsign-compare warnings being generated by ListUtil.xs that were introduced after this ticket was first opened.

Thank you very much.
Jim Keenan

@jkeenan
Copy link
Contributor

jkeenan commented Oct 7, 2021

1 build-time warning quieted by #18671; more remain; ticket stays open.

2 build-time warnings (-Wstring-compare) closed by f7b3322. There remain 2 -Wsign-compare warnings being generated by ListUtil.xs that were introduced after this ticket was first opened.

Thank you very much. Jim Keenan

Today I updated https://rt.cpan.org/Ticket/Display.html?id=136985 to request that the upstream maintainer look at these warnings.

@xenu xenu removed the Severity Low label Dec 29, 2021
@jkeenan
Copy link
Contributor

jkeenan commented Feb 22, 2022

The remaining build-time warnings being emitted by Scalar-List-Utils have been cleared up as per https://rt.cpan.org/Ticket/Display.html?id=136985 and subsequent synch into blead. This ticket is now closable.

@jkeenan jkeenan closed this as completed Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build-time-warnings Replaces [META] Build-time warnings RT #133556 type-core
Projects
None yet
Development

No branches or pull requests

6 participants