From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 2423 invoked by alias); 17 Oct 2010 16:19:54 -0000 Received: (qmail 2415 invoked by uid 22791); 17 Oct 2010 16:19:53 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,MISSING_MID X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 17 Oct 2010 16:19:48 +0000 From: "mbuilov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/46045] incorrect code generated if redecalring local variable in do-while(0) X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mbuilov at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sun, 17 Oct 2010 16:19:00 -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 X-SW-Source: 2010-10/txt/msg01406.txt.bz2 Message-ID: <20101017161900.Qoth4PQgcaEVFvwaQfHVqZzQeg_FKPaoZVildw0oEiU@z> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46045 --- Comment #4 from Michael Builov 2010-10-17 16:19:37 UTC --- Just a warning with -Wextra, but no warnings with -Wall -pedantic. I found a bug with this code: struct A { int k; int m; }; #define dump(_a_) \ do { \ struct A *a = _a_; \ printk("%d, %d\n", a->k, a->m); \ } while (0) void foo(struct A *b, struct A *a) { dump(b); /* fine */ dump(a); /* crash */ } This code compiles and runs fine with Sun cc, but crashes with gcc. I think it is definitely a bug in gcc, this code compiled only with extra warnings (not enabled by default in linux kernel) should not crash. The best way to fix this issue - generate an error message, like when redeclaring variable in function: void bar(struct A *a) { struct A *a = a; /* error: 'a' redeclared as different kind of symbol */ } strange, but no errors/non-extra warnings with: void bar(struct A *a) { { struct A *a = a; } }