[llvm] r311948 - Remove an unnecessary const_cast.

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 11:53:51 PDT 2017


On Mon, Aug 28, 2017 at 7:35 PM Adam Nemet <anemet at apple.com> wrote:

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

Yeah, leaky abstraction. op<< is clearly output only, but the
implementation detail of using the same function for input as output leaks
into this interface.

That's really awkward. :/ Hope someone fixes it.


>
> 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/20170829/bb15db3c/attachment.html>


More information about the llvm-commits mailing list