From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Martin v. Loewis" To: torvalds@transmeta.com Cc: egcs@egcs.cygnus.com Subject: Re: Linux and aliasing? Date: Sun, 06 Jun 1999 01:18:00 -0000 Message-id: <199906060817.KAA00715@mira.isdn.cs.tu-berlin.de> References: X-SW-Source: 1999-06/msg00219.html > It seems that other people use more casts for "normal" things, and are > actually afraid of my proposal for performance reasons. I'm surprised: > people that do things like that are usually not the people who complain > about others coding standards ;) Well, no. The 'normal' kind of cast is very common, and frequently used in the Linux kernel. For example, if a tty driver routine is called (e.g. drivers/char/rocket.c :-), it fetches driver_data and casts it to the device-specific type (i.e. (struct r_port *)). In these cases, people typically save the cast result in a variable instead of derefencing it, so they would not suffer from your anti-aliasing mechanism. These uses of casts are conforming C code: The driver put an r_port pointer into driver_data earlier on. > Anyway, I grepped the kernel for "likely" places where my change would > make a difference by using the following heuristic grep: > > grep '\*(.*\* *)' */*.c > > and in basically all cases the compiler would have done the right thing if > it had followed my proposal. It is actually the other casts that the Linux contributors need to worry about. Alias problems are very hard to find (as you pointed out), and somebody will have to go over the complete kernel source and investigate every single cast - if you ever plan to turn-on -fstrict-aliasing. I did the inverse grep grep '(.*\* *)' */*.c | grep -v '\*(.*\* *)' */*.c and found only one place (fs/binfmt_aout.c:create_aout_tables) where pointers are aliased in different types, and dereferenced later. The hidden treasures are probably in the header files (as earlier examples indicate). Regards, Martin From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Martin v. Loewis" To: torvalds@transmeta.com Cc: egcs@egcs.cygnus.com Subject: Re: Linux and aliasing? Date: Wed, 30 Jun 1999 15:43:00 -0000 Message-ID: <199906060817.KAA00715@mira.isdn.cs.tu-berlin.de> References: X-SW-Source: 1999-06n/msg00219.html Message-ID: <19990630154300.B0Kh2xKPdG-k-cBo6eCk9dVjEcduGTFnN68xW6dKUII@z> > It seems that other people use more casts for "normal" things, and are > actually afraid of my proposal for performance reasons. I'm surprised: > people that do things like that are usually not the people who complain > about others coding standards ;) Well, no. The 'normal' kind of cast is very common, and frequently used in the Linux kernel. For example, if a tty driver routine is called (e.g. drivers/char/rocket.c :-), it fetches driver_data and casts it to the device-specific type (i.e. (struct r_port *)). In these cases, people typically save the cast result in a variable instead of derefencing it, so they would not suffer from your anti-aliasing mechanism. These uses of casts are conforming C code: The driver put an r_port pointer into driver_data earlier on. > Anyway, I grepped the kernel for "likely" places where my change would > make a difference by using the following heuristic grep: > > grep '\*(.*\* *)' */*.c > > and in basically all cases the compiler would have done the right thing if > it had followed my proposal. It is actually the other casts that the Linux contributors need to worry about. Alias problems are very hard to find (as you pointed out), and somebody will have to go over the complete kernel source and investigate every single cast - if you ever plan to turn-on -fstrict-aliasing. I did the inverse grep grep '(.*\* *)' */*.c | grep -v '\*(.*\* *)' */*.c and found only one place (fs/binfmt_aout.c:create_aout_tables) where pointers are aliased in different types, and dereferenced later. The hidden treasures are probably in the header files (as earlier examples indicate). Regards, Martin