This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug ipa/61159] New: __builtin_constant_p gives incorrect results with aliases
- From: "bugdal at aerifal dot cx" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 12 May 2014 18:07:37 +0000
- Subject: [Bug ipa/61159] New: __builtin_constant_p gives incorrect results with aliases
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=61159
Bug ID: 61159
Summary: __builtin_constant_p gives incorrect results with
aliases
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: ipa
Assignee: unassigned at gcc dot gnu.org
Reporter: bugdal at aerifal dot cx
This issue is closely related to #61144, but seems to have appeared earlier.
Consider the following test case:
static int dummy = 0;
extern int foo __attribute__((__weak__, __alias__("dummy")));
typedef char check[2*!__builtin_constant_p(dummy)-1];
typedef char check[2*!__builtin_constant_p(foo)-1];
While the static dummy could be considered constant if its address did not leak
outside the translation unit, its address DOES leak via the weak alias foo. As
long as there is no strong definition for foo in another translation unit,
dummy may be externally modified via the alias foo. As for foo, it is external
and thus may never be considered constant. Thus, __builtin_constant_p(dummy)
and __builtin_constant_p(foo) should both yield zero and the above translation
unit should compile successfully.
The results observed vary highly with gcc version. A number of versions were
observed giving __builtin_constant_p(dummy)==1, including 4.8.1, but
__builtin_constant_p(foo) was more rare, showing up only in 4.9.0 and some
really old versions like 4.4.7 (tested via gcc.godbolt.org since I don't have
that many gcc versions lying around to test locally).