I've wanted to fix the alias analysis problems in our code base for a
few years now. Today, while waiting for a Linux kernel compile to
finish, I took at look at one of them. It is caused by this
definition in console-impl.h:
#ifdef ERROR_CHECK_TYPES
DECLARE_INLINE_HEADER (
struct console *
error_check_console_type (struct console *con, Lisp_Object sym)
)
{
assert (EQ (CONSOLE_TYPE (con), sym));
return con;
}
# define CONSOLE_TYPE_DATA(con, type) \
(*(struct type##_console **) \
&(error_check_console_type (con, Q##type))->console_data)
#else
# define CONSOLE_TYPE_DATA(con, type) \
(*(struct type##_console **) &((con)->console_data))
#endif
That way, CONSOLE_TYPE_DATA(foo, bar) is an lvalue. However, it
breaks compilations with alias analysis turned on. The way to fix
this is to give up on having a single polymorphic macro that is both
an rvalue and an lvalue. I'll admit it's cute, but with today's
compilers, it is also dangerous. The rvalue version should look like
this:
#ifdef ERROR_CHECK_TYPES
DECLARE_INLINE_HEADER (
struct console *
error_check_console_type (struct console *con, Lisp_Object sym)
)
{
assert (EQ (CONSOLE_TYPE (con), sym));
return con;
}
# define CONSOLE_TYPE_DATA(con, type) \
((struct type##_console *) \
(error_check_console_type (con, Q##type))->console_data)
#else
# define CONSOLE_TYPE_DATA(con, type) \
((struct type##_console *) ((con)->console_data))
#endif
The lvalue version is easy, since console_data is a void *, so
anything can be assigned to it. I'd probably write the
non-error-checking version like this:
#define CONSOLE_TYPE_DATA_LVALUE(con) ((con)->console_data)
or, more likely, just dispense with the stupid macro and assign to
con->console_data directly. What do you other developers think?
--
Jerry James
http://www.jamezone.org/
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://calypso.tux.org/cgi-bin/mailman/listinfo/xemacs-beta