Path: utzoo!attcan!uunet!lll-winken!lll-ncis!helios.ee.lbl.gov!nosc!ucsd!ucbvax!hoptoad!tim From: tim@hoptoad.uucp (Tim Maroney) Newsgroups: comp.sys.mac.programmer Subject: serious code generation bug in Lightspeed C Message-ID: <6275@hoptoad.uucp> Date: 12 Jan 89 15:02:44 GMT Organization: Eclectic Software, San Francisco Lines: 29 There is a serious bug in how Lightspeed C handles the assignment operation. The lvalue is evaluated before the value is computed. This means that assigments to relocatable structure members do not work correctly. For example, suppose you have a relocatable data structure and a handle to that structure in "h". Further suppose that one member of the structure referred to by "h" is of type Ptr, called "p". Then this straightforward statement gives an incorrect result: (*h)->p = NewPtr(size); The address of "(*h)->p", the lvalue, is computed before the right-hand side is evaluated. The address of "(*h)->p" may change as a result of the NewPtr trap, therefore it may be wrong on return from the trap and the result of NewPtr may be assigned into invalid memory. This is pretty amazing, even for a compiler like Think's that deliberately produces low-budget, non-optimized code. There is a work-around, assigning the result of NewPtr into an intermediate variable and then assigning it to the lvalue, but it is unwieldy, and it is difficult to spot all places where this compiler bug could bite. -- Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim "Gangsters would kidnap my math teacher, Miss Albertine, and I'd track them down and kill them one by one until she was free, and then she'd break off her engagement with my sarcastic English teacher, Mr. Richardson, because she'd fallen hopelessly in love with her grim-faced and silent fourteen-year-old savior." -- Nite Owl, in WATCHMEN by Alan Moore