From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7061 invoked by alias); 21 Nov 2013 12:05:34 -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 7020 invoked by uid 48); 21 Nov 2013 12:05:31 -0000 From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/54954] malloc optimizations not disabled by -fno-builtin Date: Thu, 21 Nov 2013 12:05:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.7.2 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: RESOLVED 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: resolution 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: 2013-11/txt/msg02137.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54954 Richard Biener changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|INVALID |WORKSFORME --- Comment #9 from Richard Biener --- I said it works for me because it works with -fno-builtin-malloc. Andrew, you are wrong - the malloc attribute itself does not tell us that the malloc call may not clobber global memory. I've massaged the testcase to build w/o warnings: m.c: #include #include void *__libc_malloc(size_t size); void *malloc(size_t size) { increment_count(); return (void*)__libc_malloc(size); } t.c: #include #include #include static int count = 0; void increment_count(void) { count++; } int main (void) { char *ptr; count = 0; ptr = malloc(1); assert(ptr); assert(count); printf("%p\n", ptr); free(ptr); return 0; } rguenther@murzim:/tmp> /space/rguenther/install/gcc-4.7.0/bin/gcc -o t t.c m.c -O2 -fno-builtin-malloc rguenther@murzim:/tmp> ./t 0x1127010 rguenther@murzim:/tmp> /space/rguenther/install/gcc-4.7.0/bin/gcc -o t t.c m.c -O2 rguenther@murzim:/tmp> ./t t: t.c:18: main: Assertion `count' failed. Aborted Works with all GCC versions I tried. I tried on x86_64-linux (just in case RTL optimizers break this in which case the target architecture may be important).