This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/67418] New: resolution to constant fails between pointer on stack and pointer within argument structure
- From: "Emmanuel.Thome at inria dot fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 01 Sep 2015 09:14:18 +0000
- Subject: [Bug c/67418] New: resolution to constant fails between pointer on stack and pointer within argument structure
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67418
Bug ID: 67418
Summary: resolution to constant fails between pointer on stack
and pointer within argument structure
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: Emmanuel.Thome at inria dot fr
Target Milestone: ---
Hi,
In the code below, gcc version 4.8.4, 4.9.3, and 5.2.0 fail to resolve the
expression temp != a->x as being a constant, while all succeed in resolving
temp != b.
It seems to me however that no valid code can reach either temp==b or
temp==a->x. Shouldn't gcc decide then that temp != a->x is constant and equal
to true in this case ? Please correct me if I am wrong.
[I've run into this as being the cause of an unexpected uninitialized warning,
whose root cause is this constant problem]
E.
struct container {
unsigned long * x;
};
int bang() __attribute__((error("should never be called")));
#define MUST_BE_CONSTANT(c) do { \
int n __attribute__((unused)) = __builtin_constant_p((c)) ? 0 : bang(); \
} while (0)
void test(struct container * a, unsigned long * b)
{
unsigned long temp[1];
MUST_BE_CONSTANT(temp != b); // passes ok.
MUST_BE_CONSTANT(temp != a->x); // fails to decide it holds
}
/*
$ ./gcc-5.2.0/bin/gcc -O2 -Wextra /tmp/a.c -c
/tmp/a.c: In function âtestâ:
/tmp/a.c:7:67: error: call to âbangâ declared with attribute error: should
never be called
int n __attribute__((unused)) = __builtin_constant_p((c)) ? 0 : bang(); \
^
/tmp/a.c:14:5: note: in expansion of macro âMUST_BE_CONSTANTâ
MUST_BE_CONSTANT(temp != a->x); // fails to decide it holds
^
$ uname -a
Linux localhost 4.1.0-1-amd64 #1 SMP Debian 4.1.3-1 (2015-08-03) x86_64
GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux testing (stretch)
Release: testing
Codename: stretch
$ ./gcc-5.2.0/bin/gcc -v
Using built-in specs.
COLLECT_GCC=/opt/gcc-5.2.0/bin/gcc
COLLECT_LTO_WRAPPER=/opt/gcc-5.2.0/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-5.2.0/configure --prefix=/opt/gcc-5.2.0
--enable-languages=c,c++
Thread model: posix
gcc version 5.2.0 (GCC)
*/