This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/17719] New: regparm __attribute__ not set in function casts


Direct cast from void pointer to function pointer forgets about regparm
attributes (resulting a segfault). The bug does not appear if a temporal union
is used to do the cast (like in FUNCCAST0).
--

#include <stdio.h>

#define ATTR __attribute__((regparm(1)))
//#define ATTR

ATTR void f(char *s);
typedef ATTR void (*f_t)(char *s);

#define FUNCCAST0(T, X) ((union { T t; } *)&(X))->t
#define FUNCCAST1(T, X) ((T)(X))

int main() {
  void *fp;
  fp = f;
  FUNCCAST0(f_t, fp)("ok0");
  FUNCCAST1(f_t, fp)("ok1");
  return 0;
}

ATTR void f(char *s) {
  printf("%s\n", s);
}

-- 
           Summary: regparm __attribute__ not set in function casts
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jfran at clip dot dia dot fi dot upm dot es
                CC: gcc-bugs at gcc dot gnu dot org


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]