From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 36250 invoked by alias); 19 May 2015 15:29:18 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 36168 invoked by uid 48); 19 May 2015 15:29:12 -0000 From: "gil.hur at sf dot snu.ac.kr" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/65752] Too strong optimizations int -> pointer casts Date: Tue, 19 May 2015 15:29:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 4.9.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gil.hur at sf dot snu.ac.kr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-05/txt/msg01528.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65752 --- Comment #24 from Chung-Kil Hur --- (In reply to schwab from comment #23) > "gil.hur at sf dot snu.ac.kr" writes: > > > Since "hello" is not printed, I think the if-statement is the same as no-op. > > Thus, removing the if-statement should not change the behavior of the program > > according to ISO C11. > > Unless you are invoking undefined behaviour. > > Andreas. ============================== #include int main() { int x = 0; uintptr_t xp = (uintptr_t) &x; uintptr_t i, j; for (i = 0; i < xp; i++) { } j = i; *(int*)((xp+i)-j) = 15; printf("%d\n", x); } ============================= This prints "15". And I do not think there is any UB. Please correct me if I am wrong. Then, I add the if-statement. ============================== #include int main() { int x = 0; uintptr_t xp = (uintptr_t) &x; uintptr_t i, j; for (i = 0; i < xp; i++) { } j = i; /****** begin *******/ if (j != xp) { printf("hello\n"); j = xp; } /****** end *********/ *(int*)((xp+i)-j) = 15; printf("%d\n", x); } ============================= This prints "0" without printing "hello". Thus, this raises no UB unless "j != xp" raises UB. If you think "j != xp" raises UB, please explain why and give some reference. Otherwise, I think it is a bug of GCC.