[PATCH] R600: Fix up for AsmPrinter's OutStreamer being a unique_ptr

David Blaikie dblaikie at gmail.com
Tue Apr 28 09:29:08 PDT 2015


On Tue, Apr 28, 2015 at 9:27 AM, David Blaikie <dblaikie at gmail.com> wrote:
> On Tue, Apr 28, 2015 at 6:53 AM, Tom Stellard <tom at stellard.net> wrote:
>> On Mon, Apr 27, 2015 at 09:34:53AM -0700, David Blaikie wrote:
>>> On Mon, Apr 27, 2015 at 2:59 AM, Michel Dänzer <michel at daenzer.net> wrote:
>>> > From: Michel Dänzer <michel.daenzer at amd.com>
>>> >
>>> > Fixes a crash with basically any OpenGL application using the radeonsi
>>> > driver.
>>> >
>>> > Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90176
>>> > Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
>>> > ---
>>> >  lib/Target/R600/AMDGPUMCInstLower.cpp | 4 ++--
>>> >  1 file changed, 2 insertions(+), 2 deletions(-)
>>> >
>>> > diff --git a/lib/Target/R600/AMDGPUMCInstLower.cpp b/lib/Target/R600/AMDGPUMCInstLower.cpp
>>> > index b00bd8d..708bb6f 100644
>>> > --- a/lib/Target/R600/AMDGPUMCInstLower.cpp
>>> > +++ b/lib/Target/R600/AMDGPUMCInstLower.cpp
>>> > @@ -132,8 +132,8 @@ void AMDGPUAsmPrinter::EmitInstruction(const MachineInstr *MI) {
>>> >        SmallVector<char, 16> CodeBytes;
>>> >        raw_svector_ostream CodeStream(CodeBytes);
>>> >
>>> > -      MCObjectStreamer &ObjStreamer = (MCObjectStreamer &)OutStreamer;
>>>
>>> Well that's lovely... - anyone have interest in banning c-style casts
>>> or a Clang warning for essentially reinterpret casts with c-style
>>> casts? (similar to -Wcast-qual - essentially trying to push for
>>> c-style casts to only be used for static_cast equivalent operations)
>>>
>>
>> These kinds of casts are used a lot in the target AsmParsers too.  What
>> kind of cast is correct here?
>
> static_cast would've done the right thing and avoided the chance of
> doing a bit-cast by accident (either at the original time it was
> written, or later on)
>
> The original code boiled down to something like this:
>
> MCFooStreamer &Original = ...
> MCStreamer &MCS = Original;
> MCFooStreamer &ExtractTheOriginalAgain =
> static_cast<MCFooStreamer&>(MCS); // this was where the unnecessarily
> powerful c-style cast was used

If we wanted to get fancy, we could have a wrapper that, when compiled
with RTTI, amounted to dynamic_cast+assert and without RTTI is just
the static_cast.

- David

>
>>
>> -Tom
>>
>>> > -      MCCodeEmitter &InstEmitter = ObjStreamer.getAssembler().getEmitter();
>>> > +      MCObjectStreamer *ObjStreamer = (MCObjectStreamer *)OutStreamer.get();
>>> > +      MCCodeEmitter &InstEmitter = ObjStreamer->getAssembler().getEmitter();
>>> >        InstEmitter.EncodeInstruction(TmpInst, CodeStream, Fixups,
>>> >                                      MF->getSubtarget<MCSubtargetInfo>());
>>> >        CodeStream.flush();
>>> > --
>>> > 2.1.4
>>> >
>>> >
>>> > _______________________________________________
>>> > llvm-commits mailing list
>>> > llvm-commits at cs.uiuc.edu
>>> > http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list