[llvm] r290618 - DebugInfo: add explicit casts for -Wqual-cast

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 2 12:11:22 PST 2017


Any chance of fixing the constness in 'P' instead of const casting away?
(ie: if this really needs to be mutable, P should be non-const void*) Or if
it doesn't need to be non-const, perhaps DIEInteger needs a fix?

Also, it looks like you have extra () around the const_cast - remove them?

On Tue, Dec 27, 2016 at 10:46 AM Saleem Abdulrasool via llvm-commits <
llvm-commits at lists.llvm.org> wrote:

> Author: compnerd
> Date: Tue Dec 27 12:35:24 2016
> New Revision: 290618
>
> URL: http://llvm.org/viewvc/llvm-project?rev=290618&view=rev
> Log:
> DebugInfo: add explicit casts for -Wqual-cast
>
> Fix a warning detected by gcc 6:
>   warning: cast from type 'const void*' to type 'uint8_t* {aka unsigned
> char*}' casts away qualifiers [-Wcast-qual]
>
> Modified:
>     llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
>
> Modified: llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp?rev=290618&r1=290617&r2=290618&view=diff
>
> ==============================================================================
> --- llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp (original)
> +++ llvm/trunk/unittests/DebugInfo/DWARF/DwarfGenerator.cpp Tue Dec 27
> 12:35:24 2016
> @@ -81,8 +81,10 @@ void dwarfgen::DIE::addAttribute(uint16_
>    auto &DG = CU->getGenerator();
>    DIEBlock *Block = new (DG.getAllocator()) DIEBlock;
>    for (size_t I = 0; I < S; ++I)
> -    Block->addValue(DG.getAllocator(), (dwarf::Attribute)0,
> -                    dwarf::DW_FORM_data1, DIEInteger(((uint8_t *)P)[I]));
> +    Block->addValue(
> +        DG.getAllocator(), (dwarf::Attribute)0, dwarf::DW_FORM_data1,
> +        DIEInteger(
> +            (const_cast<uint8_t *>(static_cast<const uint8_t *>(P)))[I]));
>
>    Block->ComputeSize(DG.getAsmPrinter());
>    Die->addValue(DG.getAllocator(), static_cast<dwarf::Attribute>(A), Form,
>
>
> _______________________________________________
> 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/20170102/14fcb4c9/attachment.html>


More information about the llvm-commits mailing list