Mailing List Archive

[perl #134375] When running Configure, clang and clang++ produce different results
# New Ticket Created by James E Keenan
# Please include the string: [perl #134375]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=134375 >


[The following is probably relevant to
https://rt.perl.org/Ticket/Display.html?id=134371, but I'm filing it
separately as it may be a more general problem.]

When I select '-Dcc=clang++', as distinct from '-Dcc=clang', ./Configure
produces different results. This difference appears to be independent
of both operating system and other configuration options.

Suppose first that I configure blead
(7654aaa1134e4908a6a6dc0b85d360816e79faa3, Aug 17 2019) on Linux as follows:

#####
sh ./Configure -de -Dusedevel -Dcc=clang
#####

... and then record the output of ./Configure in a file.

Next, suppose I clean the checkout then reconfigure and re-record the
output as follows:

#####
sh ./Configure -de -Dusedevel -Dcc=clang++
#####

Here are the compiler versions:

#####
$ clang --version; clang++ --version
clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin

clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
#####

If I diff the two output files, I get several differences, but the
following appears to be most significant:

#####
766c779,786
< I'll use gcvt to convert floats into a string.
---
> gcvt oddity: Expected 0.1, got 0.1
> ...But gcvt didn't work as I expected.
> Trying sprintf...
> sprintf() found.
> sprintf oddity: Expected 0.1, got 0.1
> ...But sprintf didn't work as I expected.
> *** WHOA THERE!!! ***
> None of ( gconvert gcvt sprintf) seemed to work properly. I'll use
sprintf.
#####

./Configure composes and runs a number of C programs on the fly as
probes. This file is typically named 'try.c'; the content of 'try.c' is
redefined several times during ./Configure. The relevant try.c starts
shortly after this comment at line 10370: ": Check how to convert floats
to strings." Within this C program we define a function called 'checkit()'.

#####
10429 int checkit(char *expect, char *got)
10430 {
10431 if (strcmp(expect, got)) {
10432 printf("%s oddity: Expected %s, got %s\n",
10433 myname, expect, got);
10434 exit(1);
10435 }
10436 }
#####

Line 10432 above is the source of the surprising output above that I got
while configuring with clang++.

To answer one question in advance: There is no leading or trailing
whitespace around '0.1'. I checked this by creating a branch in which I
put angle brackets around the last two instances of '%s' in the printf()
call above.

That implies that when running try.c, clang++ is calculating different
values for '*expect' and '*got' above line 10429. Moreover, clang++ is
getting different values both when calculating 'gcvt' and -- more
surprisingly -- when calculating 'sprintf'.

To answer another question in advance: I don't get this difference when
compiling gcc versus g++.

Is this a bug in clang++? Or is it a bug in ./Configure?

Thank you very much.
Jim Keenan
Re: [perl #134375] When running Configure, clang and clang++ produce different results [ In reply to ]
On Sun, Aug 18, 2019 at 08:04:43AM -0700, James E Keenan (via RT) wrote:
> # New Ticket Created by James E Keenan
> # Please include the string: [perl #134375]
> # in the subject line of all future correspondence about this issue.
> # <URL: https://rt.perl.org/Ticket/Display.html?id=134375 >
>
>
> [The following is probably relevant to
> https://rt.perl.org/Ticket/Display.html?id=134371, but I'm filing it
> separately as it may be a more general problem.]
>
> When I select '-Dcc=clang++', as distinct from '-Dcc=clang', ./Configure
> produces different results. This difference appears to be independent
> of both operating system and other configuration options.

> Is this a bug in clang++? Or is it a bug in ./Configure?

It is a bug in Configure. The 'checkit()' program is declared to return
an integer, but actually returns nothing. (The return value is never used.)
This is undefined behavior in C++, but apparently not in C. See
https://bugs.llvm.org/show_bug.cgi?id=43075
for a simple test case and explanation.

There are probably other such C vs. C++ bugs in Configure, including
possibly the detection of

d_futimes
d_lchown
d_strtoll
d_strtoul
d_strtoull
d_strtouq

I will leave this bug open as I work on those. Thank you for noticing
this issue in the first place!

--
Andy Dougherty doughera@lafayette.edu
Re: [perl #134375] When running Configure, clang and clang++ produce different results [ In reply to ]
On Thu, 22 Aug 2019 11:51:54 -0400, Andy Dougherty <doughera@lafayette.edu> wrote:

1346 days passed by (3 y, 8 m, 7 d)

Is this something that still needs attention?

If you have work in a usable state, can I get it to finish it?

> On Sun, Aug 18, 2019 at 08:04:43AM -0700, James E Keenan (via RT) wrote:
> > # New Ticket Created by James E Keenan
> > # Please include the string: [perl #134375]
> > # in the subject line of all future correspondence about this issue.
> > # <URL: https://rt.perl.org/Ticket/Display.html?id=134375 >
> >
> >
> > [The following is probably relevant to
> > https://rt.perl.org/Ticket/Display.html?id=134371, but I'm filing it
> > separately as it may be a more general problem.]
> >
> > When I select '-Dcc=clang++', as distinct from '-Dcc=clang', ./Configure
> > produces different results. This difference appears to be independent
> > of both operating system and other configuration options.
>
> > Is this a bug in clang++? Or is it a bug in ./Configure?
>
> It is a bug in Configure. The 'checkit()' program is declared to return
> an integer, but actually returns nothing. (The return value is never used.)
> This is undefined behavior in C++, but apparently not in C. See
> https://bugs.llvm.org/show_bug.cgi?id=43075
> for a simple test case and explanation.
>
> There are probably other such C vs. C++ bugs in Configure, including
> possibly the detection of
>
> d_futimes
> d_lchown
> d_strtoll
> d_strtoul
> d_strtoull
> d_strtouq
>
> I will leave this bug open as I work on those. Thank you for noticing
> this issue in the first place!
>


--
H.Merijn Brand https://tux.nl Perl Monger http://amsterdam.pm.org/
using perl5.00307 .. 5.37 porting perl5 on HP-UX, AIX, and Linux
https://tux.nl/email.html http://qa.perl.org https://www.test-smoke.org