public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
@ 2023-04-12 22:09 redi at gcc dot gnu.org
  2023-04-12 22:13 ` [Bug fortran/109492] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-12 22:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

            Bug ID: 109492
           Summary: gcc/fortran/trans-expr.cc:3407:17: error: call of
                    overloaded ‘abs(long long int&)’ is ambiguous
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: build
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

Bootstrap fails using gcc-5.5 on Solaris 2.11 (specifically, on gcc211 in the
compile farm):

/export/home/jwakely/src/gcc/gcc/fortran/trans-expr.cc: In function ‘void
gfc_conv_power_op(gfc_se*, gfc_expr*)’:
/export/home/jwakely/src/gcc/gcc/fortran/trans-expr.cc:3407:17: error: call of
overloaded ‘abs(long long int&)’ is ambiguous
       w = abs (v);
                 ^
In file included from /usr/include/stdlib.h:11:0,
                 from /export/home/jwakely/src/gcc/gcc/system.h:266,
                 from
/export/home/jwakely/src/gcc/gcc/fortran/trans-expr.cc:25:
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/stdlib_iso.h:163:16:
note: candidate: long int std::abs(long int)
  inline long   abs(long _l) { return labs(_l); }
                ^
/opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/iso/stdlib_iso.h:117:12:
note: candidate: int std::abs(int)
 extern int abs(int);
            ^
gmake[1]: *** [Makefile:1157: fortran/trans-expr.o] Error 1


The problem is that the libc <stdlib.h> is not C++11-aware and so doesn't
provide the long long overload of abs. It is provided by the libstdc++
<cstdlib> header, but only in namespace std.

The solution is to either use std::abs (v) or to do:

--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -3399,6 +3399,7 @@ gfc_conv_power_op (gfc_se * se, gfc_expr * expr)
   if (INTEGER_CST_P (lse.expr)
       && TREE_CODE (TREE_TYPE (rse.expr)) == INTEGER_TYPE)
     {
+      using std::abs;
       wi::tree_to_wide_ref wlhs = wi::to_wide (lse.expr);
       HOST_WIDE_INT v, w;
       int kind, ikind, bit_size;


The bootstrap compiler is:

Reading specs from /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/specs
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/csw/libexec/gcc/sparc-sun-solaris2.10/5.5.0/lto-wrapper
Target: sparc-sun-solaris2.10
Configured with:
/home/dam/mgar/pkg/gcc5/trunk/work/solaris10-sparc/build-isa-sparcv8plus/gcc-5.5.0/configure
--prefix=/opt/csw --exec_prefix=/opt/csw --bindir=/opt/csw/bin
--sbindir=/opt/csw/sbin --libexecdir=/opt/csw/libexec --datadir=/opt/csw/share
--sysconfdir=/etc/opt/csw --sharedstatedir=/opt/csw/share
--localstatedir=/var/opt/csw --libdir=/opt/csw/lib
--infodir=/opt/csw/share/info --includedir=/opt/csw/include
--mandir=/opt/csw/share/man --enable-cloog-backend=isl --enable-java-awt=xlib
--enable-languages=ada,c,c++,fortran,go,java,objc --enable-libada
--enable-libssp --enable-nls --enable-objc-gc --enable-threads=posix
--program-suffix=-5.5 --with-cloog=/opt/csw --with-gmp=/opt/csw
--with-included-gettext --with-ld=/usr/ccs/bin/ld --without-gnu-ld
--with-libiconv-prefix=/opt/csw --with-mpfr=/opt/csw --with-ppl=/opt/csw
--with-system-zlib=/opt/csw --with-as=/usr/ccs/bin/as --without-gnu-as
Thread model: posix
gcc version 5.5.0 (GCC) 

This was built on solaris 2.10 so maybe the solution is just to update
/opt/csw/bin/gcc. I'll ask the cfarm admins about that.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/109492] gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
  2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
@ 2023-04-12 22:13 ` redi at gcc dot gnu.org
  2023-04-13 11:37 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-12 22:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #0)
> This was built on solaris 2.10 so maybe the solution is just to update
> /opt/csw/bin/gcc. I'll ask the cfarm admins about that.

That wouldn't help, Solaris 2.11 still doesn't provide abs(long long) in
<stdlib.h> so it has to be provided by libstdc++, and GCC 5.5 didn't do that
correctly.

So I think the Fortran front end should use std::abs for portability to older
GCC systems (we claim to be able to bootstrap with anything newer than GCC
4.8).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/109492] gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
  2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
  2023-04-12 22:13 ` [Bug fortran/109492] " redi at gcc dot gnu.org
@ 2023-04-13 11:37 ` rguenth at gcc dot gnu.org
  2023-04-13 19:03 ` anlauf at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-04-13 11:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-04-13

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
It should use abs_hwi () instead (or maybe absu_hwi for safety).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/109492] gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
  2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
  2023-04-12 22:13 ` [Bug fortran/109492] " redi at gcc dot gnu.org
  2023-04-13 11:37 ` rguenth at gcc dot gnu.org
@ 2023-04-13 19:03 ` anlauf at gcc dot gnu.org
  2023-04-13 19:34 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-04-13 19:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #3 from anlauf at gcc dot gnu.org ---
There is no unsigned integer type in Fortran, so anything that is done to
solve this should be fine.

Does the following patch work?

diff --git a/gcc/fortran/trans-expr.cc b/gcc/fortran/trans-expr.cc
index 79367fa2ae0..09cdd9263c4 100644
--- a/gcc/fortran/trans-expr.cc
+++ b/gcc/fortran/trans-expr.cc
@@ -3400,11 +3400,12 @@ gfc_conv_power_op (gfc_se * se, gfc_expr * expr)
       && TREE_CODE (TREE_TYPE (rse.expr)) == INTEGER_TYPE)
     {
       wi::tree_to_wide_ref wlhs = wi::to_wide (lse.expr);
-      HOST_WIDE_INT v, w;
+      HOST_WIDE_INT v;
+      unsigned HOST_WIDE_INT w;
       int kind, ikind, bit_size;

       v = wlhs.to_shwi ();
-      w = abs (v);
+      w = absu_hwi (v);

       kind = expr->value.op.op1->ts.kind;
       ikind = gfc_validate_kind (BT_INTEGER, kind, false);

It works here on x86_64-pc-linux-gnu.
If this fixes the reported issue on Solaris, it is approved.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/109492] gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
  2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2023-04-13 19:03 ` anlauf at gcc dot gnu.org
@ 2023-04-13 19:34 ` redi at gcc dot gnu.org
  2023-04-13 20:47 ` cvs-commit at gcc dot gnu.org
  2023-04-14 19:25 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2023-04-13 19:34 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to anlauf from comment #3)
> Does the following patch work?

It compiles OK on Solaris with gcc-5.5

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/109492] gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
  2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2023-04-13 19:34 ` redi at gcc dot gnu.org
@ 2023-04-13 20:47 ` cvs-commit at gcc dot gnu.org
  2023-04-14 19:25 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-04-13 20:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:

https://gcc.gnu.org/g:43816633afd275a9057232a6ebfdc19e441f09ec

commit r13-7174-g43816633afd275a9057232a6ebfdc19e441f09ec
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Thu Apr 13 22:42:23 2023 +0200

    Fortran: call of overloaded âabs(long long int&)â is ambiguous
[PR109492]

    gcc/fortran/ChangeLog:

            PR fortran/109492
            * trans-expr.cc (gfc_conv_power_op): Use absu_hwi and
            unsigned HOST_WIDE_INT for portability.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Bug fortran/109492] gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous
  2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2023-04-13 20:47 ` cvs-commit at gcc dot gnu.org
@ 2023-04-14 19:25 ` anlauf at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-04-14 19:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109492

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #6 from anlauf at gcc dot gnu.org ---
I assume that it fixed now.  Otherwise please reopen.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-04-14 19:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-12 22:09 [Bug fortran/109492] New: gcc/fortran/trans-expr.cc:3407:17: error: call of overloaded ‘abs(long long int&)’ is ambiguous redi at gcc dot gnu.org
2023-04-12 22:13 ` [Bug fortran/109492] " redi at gcc dot gnu.org
2023-04-13 11:37 ` rguenth at gcc dot gnu.org
2023-04-13 19:03 ` anlauf at gcc dot gnu.org
2023-04-13 19:34 ` redi at gcc dot gnu.org
2023-04-13 20:47 ` cvs-commit at gcc dot gnu.org
2023-04-14 19:25 ` anlauf at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).