[LLVMdev] merging globals
Eli Friedman
eli.friedman at gmail.com
Thu Oct 16 18:37:19 PDT 2008
On Thu, Oct 16, 2008 at 3:26 PM, Mike Stump <mrs at apple.com> wrote:
> On Oct 16, 2008, at 1:57 PM, Eli Friedman wrote:
>> I strongly doubt we can get away with that.
>
> Yeah, we agree on that one. I was just thinking about the const case.
>
>> Here's a more concrete version of the solution I'm proposing: we add a
>> new optional marking to constant globals, say "mergeable". There are
>> two reasonable semantics: one is that the result of equality
>> comparisons of a pointer into this global with a pointer into any
>> other similarly marked global is undefined.
>
> undefined means the code is free to rm -rf /, is this what you meant?
> I'm against that.
>
> The usual wording is sufficient:
>
> It is unspeciļ¬ed whether such a variable has an address distinct
> from that of any other object in the program
Okay... works, but there are some strange edge cases; take the
following program:
static const int a = 0, b = &a == &b;
(a and b get used later, including their addresses)
In C mode, the front-end must evaluate &a == &b because complex
expressions in initializers generally can't be trusted to the backend.
However, once it evaluates this, it can't mark either a or b
mergeable; if it did, it would introduce a logical inconsistency with
other code that compared the addresses of a and b.
-Eli
More information about the llvm-dev
mailing list