[llvm-commits] [llvm] r163247 - in /llvm/trunk/lib/Target/X86/Disassembler: X86Disassembler.cpp X86DisassemblerDecoder.c X86DisassemblerDecoder.h

Jim Grosbach grosbach at apple.com
Wed Sep 5 14:46:55 PDT 2012


On Sep 5, 2012, at 2:42 PM, Roman Divacky <rdivacky at freebsd.org> wrote:

> Basically this:
> 
> int main() {
>  const int *cp;
>  int *p = (int *)cp;
> }
> pes ~/openacc$ g++48 -Wcast-qual gcc48-warning.cpp
> gcc48-warning.cpp: In function 'int main()':
> gcc48-warning.cpp:3:19: warning: cast from type 'const int*' to type 'int*' casts away qualifiers [-Wcast-qual]
>   int *p = (int *)cp;
>                   ^
> pes ~/openacc$ clang++ -Wcast-qual gcc48-warning.cpp
> pes ~/openacc$ 
> 
> In some places we cast away the const qualifier needlessly.

Do I assume correctly that warning only fires in C++ code and is basically telling you to use const_cast instead if that's really what you mean to do?

> 
> On Wed, Sep 05, 2012 at 05:22:34PM -0400, Chandler Carruth wrote:
>> My question here is similar to the question on other commits here:
>> 
>> What is the warning or error that detects this? Is it correct?
>> 
>> If so, could you file bugs to add this to Clang? We shouldn't have this
>> type of divergent syntaxes between GCC and Clang...
>> 
>> 
>> On Wed, Sep 5, 2012 at 5:17 PM, Roman Divacky <rdivacky at freebsd.org> wrote:
>> 
>>> Author: rdivacky
>>> Date: Wed Sep  5 16:17:34 2012
>>> New Revision: 163247
>>> 
>>> URL: http://llvm.org/viewvc/llvm-project?rev=163247&view=rev
>>> Log:
>>> Use const properly so that we dont remove const qualifier from region and
>>> MII
>>> by casting. Found with gcc48.
>>> 
>>> Modified:
>>>    llvm/trunk/lib/Target/X86/Disassembler/X86Disassembler.cpp
>>>    llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.c
>>>    llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
>>> 
>>> Modified: llvm/trunk/lib/Target/X86/Disassembler/X86Disassembler.cpp
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/Disassembler/X86Disassembler.cpp?rev=163247&r1=163246&r2=163247&view=diff
>>> 
>>> ==============================================================================
>>> --- llvm/trunk/lib/Target/X86/Disassembler/X86Disassembler.cpp (original)
>>> +++ llvm/trunk/lib/Target/X86/Disassembler/X86Disassembler.cpp Wed Sep  5
>>> 16:17:34 2012
>>> @@ -44,7 +44,7 @@
>>>   dbgs() << file << ":" << line << ": " << s;
>>> }
>>> 
>>> -const char *x86DisassemblerGetInstrName(unsigned Opcode, void *mii) {
>>> +const char *x86DisassemblerGetInstrName(unsigned Opcode, const void *mii)
>>> {
>>>   const MCInstrInfo *MII = static_cast<const MCInstrInfo *>(mii);
>>>   return MII->getName(Opcode);
>>> }
>>> @@ -95,8 +95,8 @@
>>> ///                   be a pointer to a MemoryObject.
>>> /// @param byte     - A pointer to the byte to be read.
>>> /// @param address  - The address to be read.
>>> -static int regionReader(void* arg, uint8_t* byte, uint64_t address) {
>>> -  MemoryObject* region = static_cast<MemoryObject*>(arg);
>>> +static int regionReader(const void* arg, uint8_t* byte, uint64_t address)
>>> {
>>> +  const MemoryObject* region = static_cast<const MemoryObject*>(arg);
>>>   return region->readByte(address, byte);
>>> }
>>> 
>>> @@ -135,10 +135,10 @@
>>> 
>>>   int ret = decodeInstruction(&internalInstr,
>>>                               regionReader,
>>> -                              (void*)&region,
>>> +                              (const void*)&region,
>>>                               loggerFn,
>>>                               (void*)&vStream,
>>> -                              (void*)MII,
>>> +                              (const void*)MII,
>>>                               address,
>>>                               fMode);
>>> 
>>> 
>>> Modified: llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.c
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.c?rev=163247&r1=163246&r2=163247&view=diff
>>> 
>>> ==============================================================================
>>> --- llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.c
>>> (original)
>>> +++ llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.c Wed
>>> Sep  5 16:17:34 2012
>>> @@ -719,7 +719,7 @@
>>>  * @return      - 0 if the ModR/M could be read when needed or was not
>>> needed;
>>>  *                nonzero otherwise.
>>>  */
>>> -static int getID(struct InternalInstruction* insn, void *miiArg) {
>>> +static int getID(struct InternalInstruction* insn, const void *miiArg) {
>>>   uint8_t attrMask;
>>>   uint16_t instructionID;
>>> 
>>> @@ -1621,10 +1621,10 @@
>>>  */
>>> int decodeInstruction(struct InternalInstruction* insn,
>>>                       byteReader_t reader,
>>> -                      void* readerArg,
>>> +                      const void* readerArg,
>>>                       dlog_t logger,
>>>                       void* loggerArg,
>>> -                      void* miiArg,
>>> +                      const void* miiArg,
>>>                       uint64_t startLoc,
>>>                       DisassemblerMode mode) {
>>>   memset(insn, 0, sizeof(struct InternalInstruction));
>>> 
>>> Modified: llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h?rev=163247&r1=163246&r2=163247&view=diff
>>> 
>>> ==============================================================================
>>> --- llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h
>>> (original)
>>> +++ llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.h Wed
>>> Sep  5 16:17:34 2012
>>> @@ -403,7 +403,7 @@
>>>  *                  be read from.
>>>  * @return        - -1 if the byte cannot be read for any reason; 0
>>> otherwise.
>>>  */
>>> -typedef int (*byteReader_t)(void* arg, uint8_t* byte, uint64_t address);
>>> +typedef int (*byteReader_t)(const void* arg, uint8_t* byte, uint64_t
>>> address);
>>> 
>>> /*
>>>  * dlog_t - Type for the logging function that the consumer can provide to
>>> @@ -422,7 +422,7 @@
>>>   /* Reader interface (C) */
>>>   byteReader_t reader;
>>>   /* Opaque value passed to the reader */
>>> -  void* readerArg;
>>> +  const void* readerArg;
>>>   /* The address of the next byte to read via the reader */
>>>   uint64_t readerCursor;
>>> 
>>> @@ -561,10 +561,10 @@
>>>  */
>>> int decodeInstruction(struct InternalInstruction* insn,
>>>                       byteReader_t reader,
>>> -                      void* readerArg,
>>> +                      const void* readerArg,
>>>                       dlog_t logger,
>>>                       void* loggerArg,
>>> -                      void* miiArg,
>>> +                      const void* miiArg,
>>>                       uint64_t startLoc,
>>>                       DisassemblerMode mode);
>>> 
>>> @@ -579,7 +579,7 @@
>>>                           unsigned line,
>>>                           const char *s);
>>> 
>>> -const char *x86DisassemblerGetInstrName(unsigned Opcode, void *mii);
>>> +const char *x86DisassemblerGetInstrName(unsigned Opcode, const void *mii);
>>> 
>>> #ifdef __cplusplus
>>> }
>>> 
>>> 
>>> _______________________________________________
>>> 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