This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13397] New: Optimizer doesn't take into account protection flags
- From: "yuri at tsoft dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Dec 2003 05:17:46 -0000
- Subject: [Bug c++/13397] New: Optimizer doesn't take into account protection flags
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following piece of code could have been optimized better
if optimizer had taken into account that certain
field is "private".
If some field is private in the class and all function
members are explicitely defined in the class it's no
way private field legitimately changes in other than
by these methods way (assuming no friend classes).
Example:
----cut---------------------------------------------------
#include <stdio.h>
class C {
public: C() : c('a'), pc(&c) { }
private: char *pc;
public: char *get_pc() { return (pc); }
private: char c;
};
extern void f(C *);
int main(int argc, const char *argv) {
C c;
f(&c);
if (c.get_pc() != NULL) {
printf("YES\n");
} else {
printf("NO\n");
}
}
----------cut(end code)--------------------------
In the above code it's clear that field pc is never
not NULL so it's no need to compare the
value returned by get_pc() function. And
"NO" should never appear in the assembly.
But it appears though.
Same would also apply for any other type
if class methods only change the value
in particular way and no it's pointers
leaked and no friend classes declared.
Yuri.
--
Summary: Optimizer doesn't take into account protection flags
Product: gcc
Version: 3.4
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: yuri at tsoft dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: Any Linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13397