[llvm] r311948 - Remove an unnecessary const_cast.

Adam Nemet via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 19:35:07 PDT 2017


It's been a while but I think it has to do with using the same function to parse and emit the class. So naturally it takes a reference.

In addition we stream opt remarks as pointers so that at parse time we can construct the right object from the class hierarchy.  (I know we only emit these currently and never parse but I did not want to do something that outright  prevented that.)

> On Aug 28, 2017, at 6:32 PM, David Blaikie <dblaikie at gmail.com> wrote:
> 
> Ah, why does it do that?
> 
>> On Mon, Aug 28, 2017 at 6:31 PM Adam Nemet <anemet at apple.com> wrote:
>> 
>> 
>>> On Aug 28, 2017, at 5:16 PM, David Blaikie <dblaikie at gmail.com> wrote:
>>> 
>>> Does this even need the variable then?
>> 
>> Yes. As the new comment says << takes a reference to a pointer -- we need an lvalue. 
>> 
>>> Maybe easier to read as:
>>> 
>>>   *Out << &OptDiagBase;
>>> 
>>> (& even drop the {} around the if (& while you're there, maybe roll the 'Out' into the if condition, if it's not used after the 'if'))
>>> 
>>>> On Mon, Aug 28, 2017 at 4:01 PM Adam Nemet via llvm-commits <llvm-commits at lists.llvm.org> wrote:
>>>> Author: anemet
>>>> Date: Mon Aug 28 16:00:13 2017
>>>> New Revision: 311948
>>>> 
>>>> URL: http://llvm.org/viewvc/llvm-project?rev=311948&view=rev
>>>> Log:
>>>> Remove an unnecessary const_cast.
>>>> 
>>>> I think that this is dating back to when emit used to take a const reference.
>>>> 
>>>> Modified:
>>>>     llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
>>>> 
>>>> Modified: llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp
>>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp?rev=311948&r1=311947&r2=311948&view=diff
>>>> ==============================================================================
>>>> --- llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp (original)
>>>> +++ llvm/trunk/lib/Analysis/OptimizationDiagnosticInfo.cpp Mon Aug 28 16:00:13 2017
>>>> @@ -165,7 +165,8 @@ void OptimizationRemarkEmitter::emit(
>>>> 
>>>>    yaml::Output *Out = F->getContext().getDiagnosticsOutputFile();
>>>>    if (Out) {
>>>> -    auto *P = const_cast<DiagnosticInfoOptimizationBase *>(&OptDiagBase);
>>>> +    // For remarks the << operator takes a reference to a pointer.
>>>> +    auto *P = &OptDiagBase;
>>>>      *Out << P;
>>>>    }
>>>>    // FIXME: now that IsVerbose is part of DI, filtering for this will be moved
>>>> 
>>>> 
>>>> _______________________________________________
>>>> llvm-commits mailing list
>>>> llvm-commits at lists.llvm.org
>>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170828/d484690b/attachment.html>


More information about the llvm-commits mailing list