This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/83504] New: incorrect attribute const interpretation on function overloads
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 20 Dec 2017 04:11:35 +0000
- Subject: [Bug c++/83504] New: incorrect attribute const interpretation on function overloads
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83504
Bug ID: 83504
Summary: incorrect attribute const interpretation on function
overloads
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: msebor at gcc dot gnu.org
Target Milestone: ---
When another overload of a function is subsequently declared const, all
versions of GCC treat calls to a prior overload of the same function as const
and eliminate multiple calls to it with the same argument, even if reads global
memory. As a result, GCC emits the wrong code for uses of such a function as
in the test case below.
$ cat u.C && gcc -O2 -S -Wall -Wextra -fdump-tree-optimized=/dev/stdout u.C
int i;
int f (int) { return i; }
int __attribute__ ((const)) f ();
void g (void)
{
i = 0;
int j = f (0);
i = 1;
if (j == f (0))
__builtin_abort ();
}
;; Function f (_Z1fi, funcdef_no=0, decl_uid=2326, cgraph_uid=0,
symbol_order=1)
f (int D.2325)
{
int _2;
<bb 2> [local count: 1073741825]:
_2 = i;
return _2;
}
;; Function g (_Z1gv, funcdef_no=1, decl_uid=2329, cgraph_uid=1,
symbol_order=2)
g ()
{
<bb 2> [local count: 1073741825]:
i = 1;
return;
}