[llvm-commits] [llvm] r71783 - /llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp

Eli Friedman eli.friedman at gmail.com
Thu May 14 15:51:50 PDT 2009


On Thu, May 14, 2009 at 1:44 PM, Dale Johannesen <dalej at apple.com> wrote:
>
> On May 14, 2009, at 11:59 AMPDT, Eli Friedman wrote:
>>>> On Thu, May 14, 2009 at 11:41 AM, Dale Johannesen <dalej at apple.com>
>>>> wrote:
>>>>> +        Value *V2 = I->getOperand(0)->getUnderlyingObject();
>>>>> +        if (V2) {
>>>>> +          GlobalVariable* GV = dyn_cast<GlobalVariable>(V2);
>>>>> +          if (GV && GV->hasExternalWeakLinkage())
>>>>> +            return false;
>>>>> +        }
>>>>
>>>> Ah, hmm, I'm not sure how I missed this when I looked at it
>>>> originally, but it's unsafe to continue if V2 or GV is null.  In
>>>> those
>>>> cases, you have no clue what the pointer points at.
>>>
>>> A variable base you mean?  That wouldn't be a Constant, would it?
>>> Can
>>> you give an example that would break?
>>
>> Somewhat silly example, but something like the following leads to an
>> unsafe constant:
>>
>> __attribute((weak)) extern int x;
>> int a() { return *(int*)(((unsigned long)&x)/2*2); }
>
> I see.  I'm certainly not inclined to disable a useful optimization to
> allow for things like this.  I suppose the answer is to have an
> expanded version of getUnderlyingObject that looks all the way down...

I think it's okay to disable the optimization when it can't find the
base; the cases where it can't find the base should be quite unusual
(basically, just cases involving ptrtoint).

-Eli




More information about the llvm-commits mailing list