On Oct 15, 2008, at 9:43 AM, Duncan Sands wrote:>> True, but note that it is the address of a variable that is used, not >> the value. > > Yes, but why do you think they should get a different address? I can > understand that it is surprising that they do, but determining whether > this is legal or not requires reading the language standard. > Hopefully > a language lawyer can chime in and say whether this transform is valid > or not.FWIW, I've been discussing this with some of my colleagues (who may well be the foremost experts on this topic), and so far we don't have a definite answer (we're looking at C99 and C++). We do think that a strict reading of the standard allows the optimization, but there is also some suspicion that that is unintended (at least in C++). Daveed
On Oct 15, 2008, at 12:00 PM, David Vandevoorde wrote:> > On Oct 15, 2008, at 9:43 AM, Duncan Sands wrote: > >>> True, but note that it is the address of a variable that is used, >>> not >>> the value. >> >> Yes, but why do you think they should get a different address? I can >> understand that it is surprising that they do, but determining >> whether >> this is legal or not requires reading the language standard. >> Hopefully >> a language lawyer can chime in and say whether this transform is >> valid >> or not. > > > FWIW, I've been discussing this with some of my colleagues (who may > well be the foremost experts on this topic), and so far we don't have > a definite answer (we're looking at C99 and C++). We do think that a > strict reading of the standard allows the optimization, but there is > also some suspicion that that is unintended (at least in C++).FWIW, a C++ CoreWG issue has been opened to clarify this. (My own position is that different objects should have guaranteed different addresses. To alias them, a code generator must prove that it wouldn't change observable behavior.) Daveed
Hello, David> > (My own position is that different objects should have guaranteed > different addresses. To alias them, a code generator must prove that > it wouldn't change observable behavior.)However, it's pretty common linker optimization to merge constant strings / small literal values. So, even if compiler itself won't merge them, they will be emitted into mergeable section and then linker will perform this optimization. --- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20081015/86ec5f4e/attachment.html>