From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21389 invoked by alias); 18 Jan 2013 19:53:46 -0000 Received: (qmail 21286 invoked by uid 48); 18 Jan 2013 19:53:22 -0000 From: "tmsriram at google dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/55742] [4.8 regression] __attribute__ in class function declaration cause "prototype does not match" errors. Date: Fri, 18 Jan 2013 19:53: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-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: tmsriram at google dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 4.8.0 X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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: 2013-01/txt/msg01788.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D55742 --- Comment #38 from Sriraman Tallam 2013-01-1= 8 19:53:16 UTC --- (In reply to comment #32) > Created attachment 29207 [details] > gcc48-pr55742.patch >=20 > This bug is open for way too long given its severity, so let's start talk= ing > over patches. >=20 > This patch attempts to implement what I understand from Jason's comments,= just > with "default" instead of "any", because it is indeed the default target > attribute (whatever you specify on the command line). >=20 > Say on: > void foo (); > void foo () __attribute__((target ("avx"))); > void foo () __attribute__((target ("default"))); > __attribute__((target ("default"))) void foo () > { > } > __attribute__((target ("avx"))) void foo () > { > } > void (*fn) () =3D foo; >=20 > first we merge the first two decls, because only if target attribute is p= resent > on both, we consider it for multi-versioning, for compatibility with 4.7 = and > older. On e.g. > void foo (); > void foo () __attribute__((target ("sse4"))); > void foo () __attribute__((target ("default"))); > void foo () > { > } > we reject the last fn definition, because at that point foo is already kn= own to > be multi-versioned, thus it is required that target attribute is specifie= d for > foo (either "default", or some other). Unfortunately, for this case the = error > is reported twice for some reason. >=20 > The #c0 testcase now compiles. >=20 > Now, the issues I discovered with multiversioning, still unfixed by the p= atch: > 1) the mv*.C testcases should be moved, probably to g++.dg/ext/mv*.C > 2) can you please explain the mess in handle_target_attribute? > /* Do not strip invalid target attributes for targets which support fun= ction > multiversioning as the target string is used to determine versioned > functions. */ > else if (! targetm.target_option.valid_attribute_p (*node, name, args, > flags) > && ! targetm.target_option.supports_function_versions ()) > *no_add_attrs =3D true; > Why do you need that? Consider complete garbage in target attribute argu= ments, > which is errored about, but the above for i386/x86_64 keeps the target > attribute around anyway, leading to lots of ICEs everywhere: Without bringing in your patch, I removed this line with patch: --- gcc/c-family/c-common.c (revision 195302) +++ gcc/c-family/c-common.c (working copy) @@ -8763,8 +8763,7 @@ multiversioning as the target string is used to determine versioned functions. */ else if (! targetm.target_option.valid_attribute_p (*node, name, args, - flags) - && ! targetm.target_option.supports_function_versions ()) + flags)) *no_add_attrs =3D true; return NULL_TREE; and then tried the new compiler on the following example: int foo (); int foo () __attribute__ ((target("mmx"))); int main () { return foo (); } int foo () { return 0; } int __attribute__ ((target("mmx"))) foo () { return 0; } and with -mno-mmx added to the compile options, everything is fine. However, with -mmmx in the compile options, I get: fe_example.cc: In function =E2=80=98int foo()=E2=80=99: fe_example.cc:16:1: error: redefinition of =E2=80=98int foo()=E2=80=99 foo () ^ fe_example.cc:10:1: error: =E2=80=98int foo()=E2=80=99 previously defined h= ere foo () Reason is the stripping of target attributes that do not make sense. But, f= or MV that creates duplicate functions.=20 I can change this to only keep the attribute tagged it is recognized by the target. That way I will strip out erroneous values for target attribute. > Consider e.g.: > __attribute__((target ("default"))) void foo (void) > { > } > __attribute__((target (128))) void foo (void) > { > } > 3) the multiversioning code assumes that target has a single argument, bu= t it > can have more than one. Say for: > __attribute__((target ("avx,popcnt"))) void foo (void) > { > } > __attribute__((target ("popcnt","avx"))) void bar (void) > { > } > the compiler handles those two as equivalent, but with -Dbar=3Dfoo > multi-versioning only considers the first string out of that.