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

Dale Johannesen dalej at apple.com
Thu May 14 13:44:22 PDT 2009


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...




More information about the llvm-commits mailing list