public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tmsriram at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/55742] __attribute__ in class function declaration cause "prototype does not match" errors.
Date: Wed, 19 Dec 2012 23:30:00 -0000	[thread overview]
Message-ID: <bug-55742-4-WO3sAxEe3y@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-55742-4@http.gcc.gnu.org/bugzilla/>


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55742

Sriraman Tallam <tmsriram at google dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |davidxl at google dot com

--- Comment #1 from Sriraman Tallam <tmsriram at google dot com> 2012-12-19 23:29:51 UTC ---
(In reply to comment #0)
> The following code used to compile with GCC 4.7.  It fails on trunk with:
> 
> $ bld/xgcc -Bbld/ -c a.cc
> a.cc:10:6: error: prototype for 'void A::E(uint64*, uint64*, const void*,
> int64) const' does not match any in class 'A'
>  void A::E(uint64 *l, uint64 *h, const void *b, int64 g) const
>       ^
> a.cc:6:18: error: candidate is: virtual void A::E(uint64*, uint64*, const
> void*, int64) const
>      virtual void E(uint64 *l, uint64 *h, const void *b, int64 g) const
> 
> 
> typedef unsigned long long uint64;
> typedef long long int64;
> 
> class A {
>   public:
>     virtual void E(uint64 *l, uint64 *h, const void *b, int64 g) const
>         __attribute__ ((__target__ ("sse4")));
> };
> 
> void A::E(uint64 *l, uint64 *h, const void *b, int64 g) const
> {
>     *l = *h + g;
>     if (b) return;
> }
> 
> This seems to be a bug in the multiversioning logic.  We fail to match the
> function to its declaration in decl2.c:check_classfn because
> ix86_function_versions returns true.
> 
> 676
> 677               /* While finding a match, same types and params are not
> enough
> 678                  if the function is versioned.  Also check version
> ("target")
> 679                  attributes.  */
> 680               if (same_type_p (TREE_TYPE (TREE_TYPE (function)),
> 681                                TREE_TYPE (TREE_TYPE (fndecl)))
> 682                   && compparms (p1, p2)
> 683                   && !targetm.target_option.function_versions (function,
> fndecl)
> 684                   && (!is_template
> 685                       || comp_template_parms (template_parms,
> 686                                               DECL_TEMPLATE_PARMS
> (fndecl)))
> 687                   && (DECL_TEMPLATE_SPECIALIZATION (function)
> 688                       == DECL_TEMPLATE_SPECIALIZATION (fndecl))
> 689                   && (!DECL_TEMPLATE_SPECIALIZATION (function)
> 690                       || (DECL_TI_TEMPLATE (function)
> 691                           == DECL_TI_TEMPLATE (fndecl))))
> 692                 break;
> 
> While this agrees with the logic of the multiversion test, it is not the
> appropriate context to be checking for multiversions, I think.
> 
> Here we are comparing a function *declaration* with a function *definition*. 
> The function definition can never have attributes (only declarations do).

AFAIU, this is not true. Definitions can have target attributes too.

So, your example can be fixed by adding __attribute__ ((__target__ ("sse4")))
to the front of the definition:

__attribute__ ((__target__ ("sse4")))
void A::E(uint64 *l, uint64 *h, const void *b, int64 g) const
{
    *l = *h + g;
    if (b) return;
}

will now make that code compile.


Infact, I think this is necessary. It is *not correct* to add the target
attribute only to the declaration.

Example:


test.cc
=======

char a[17];
char c[16];

int bar () __attribute__ ((target ("sse4.2")));

int bar ()
{
  char *b = a+1;
  fprintf (stderr, "Foo\n");

  for (int i = 0; i< 16; i++)
    c[i] = b[i];

  return 255;
}

Here, only the declaration has sse4.2, not the definition.

$ g++ test.cc -ftree-vectorize  -c -O2 -mno-sse

Now, test.o does not contain any sse4.2 instructions.

Add "__attribute__ ((target ("sse4.2")))" to the definition, and recompile with
same command. test.o will have movdqa and movdqu instructions. So, the target
attributes should also be on the definition for functionality to be correct.

With Multiversioning, this problem is exposed. I think the source change is the
correct way to go here.








  So I
> *think* the right fix here is to not call the multiversion hook.
> 
> Sri, could you take a look?  This bug is causing build failures with our
> internal code base.
> 
> 
> Thanks.


  reply	other threads:[~2012-12-19 23:30 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-19 16:46 [Bug c++/55742] New: " dnovillo at gcc dot gnu.org
2012-12-19 23:30 ` tmsriram at google dot com [this message]
2012-12-20 18:00 ` [Bug c++/55742] " dnovillo at gcc dot gnu.org
2012-12-20 18:21 ` tmsriram at google dot com
2012-12-20 18:24 ` dnovillo at google dot com
2012-12-20 19:37 ` tmsriram at google dot com
2012-12-20 19:52 ` xinliangli at gmail dot com
2013-01-10 22:10 ` tmsriram at google dot com
2013-01-14 14:33 ` [Bug c++/55742] [4.8 regression] " jason at gcc dot gnu.org
2013-01-14 14:35 ` rguenth at gcc dot gnu.org
2013-01-14 14:38 ` rguenth at gcc dot gnu.org
2013-01-14 15:14 ` jakub at gcc dot gnu.org
2013-01-14 17:17 ` xinliangli at gmail dot com
2013-01-14 17:21 ` xinliangli at gmail dot com
2013-01-14 17:46 ` tmsriram at google dot com
2013-01-14 17:50 ` xinliangli at gmail dot com
2013-01-14 18:07 ` tmsriram at google dot com
2013-01-14 18:26 ` jakub at gcc dot gnu.org
2013-01-14 18:33 ` jakub at gcc dot gnu.org
2013-01-14 20:18 ` xinliangli at gmail dot com
2013-01-14 20:24 ` jakub at gcc dot gnu.org
2013-01-14 20:30 ` xinliangli at gmail dot com
2013-01-15 18:45 ` jason at gcc dot gnu.org
2013-01-15 19:03 ` xinliangli at gmail dot com
2013-01-16  8:12 ` jakub at gcc dot gnu.org
2013-01-16 15:54 ` jason at gcc dot gnu.org
2013-01-16 16:03 ` jakub at gcc dot gnu.org
2013-01-16 16:06 ` richard.guenther at gmail dot com
2013-01-16 17:21 ` tmsriram at google dot com
2013-01-16 17:26 ` tmsriram at google dot com
2013-01-16 20:04 ` jason at gcc dot gnu.org
2013-01-17 22:45 ` xinliangli at gmail dot com
2013-01-18  9:49 ` richard.guenther at gmail dot com
2013-01-18 14:19 ` jakub at gcc dot gnu.org
2013-01-18 16:59 ` jason at gcc dot gnu.org
2013-01-18 17:28 ` xinliangli at gmail dot com
2013-01-18 17:52 ` jakub at gcc dot gnu.org
2013-01-18 18:03 ` tmsriram at google dot com
2013-01-18 18:08 ` tmsriram at google dot com
2013-01-18 19:53 ` tmsriram at google dot com
2013-01-19 10:14 ` jakub at gcc dot gnu.org
2013-01-19 10:28 ` jakub at gcc dot gnu.org
2013-01-19 17:18 ` tmsriram at google dot com
2013-01-21 11:41 ` jakub at gcc dot gnu.org
2013-01-23 16:39 ` jakub at gcc dot gnu.org
2013-01-30 18:05 ` jakub at gcc dot gnu.org
2013-01-30 18:18 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-55742-4-WO3sAxEe3y@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).