[Lldb-commits] [lldb] r250662 - Silence -Wqual-cast warnings from GCC 5.2

Saleem Abdulrasool via lldb-commits lldb-commits at lists.llvm.org
Sun Oct 18 12:34:39 PDT 2015


Author: compnerd
Date: Sun Oct 18 14:34:38 2015
New Revision: 250662

URL: http://llvm.org/viewvc/llvm-project?rev=250662&view=rev
Log:
Silence -Wqual-cast warnings from GCC 5.2

There were a number of const qualifiers being cast away which caused warnings.
This cluttered the output hiding real errors.  Silence them by explicit casting.
NFC.

Modified:
    lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
    lldb/trunk/source/Commands/CommandObjectMemory.cpp
    lldb/trunk/source/Core/DataExtractor.cpp
    lldb/trunk/source/Core/Scalar.cpp
    lldb/trunk/source/Core/StreamString.cpp
    lldb/trunk/source/DataFormatters/StringPrinter.cpp
    lldb/trunk/source/Host/common/Host.cpp
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
    lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
    lldb/trunk/source/Symbol/CompilerType.cpp
    lldb/trunk/source/Symbol/Type.cpp

Modified: lldb/trunk/include/lldb/DataFormatters/StringPrinter.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/DataFormatters/StringPrinter.h?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/include/lldb/DataFormatters/StringPrinter.h (original)
+++ lldb/trunk/include/lldb/DataFormatters/StringPrinter.h Sun Oct 18 14:34:38 2015
@@ -432,13 +432,13 @@ namespace lldb_private {
                 m_size(size),
                 m_deleter(deleter)
                 {}
-                
+
                 StringPrinterBufferPointer(const U* bytes, S size, Deleter deleter = nullptr) :
-                m_data((T*)bytes),
+                m_data(reinterpret_cast<const T*>(bytes)),
                 m_size(size),
                 m_deleter(deleter)
                 {}
-                
+
                 StringPrinterBufferPointer(StringPrinterBufferPointer&& rhs) :
                 m_data(rhs.m_data),
                 m_size(rhs.m_size),

Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Sun Oct 18 14:34:38 2015
@@ -527,20 +527,21 @@ protected:
                                                1, 
                                                type_list);
             }
-            
+
             if (type_list.GetSize() == 0 && lookup_type_name.GetCString() && *lookup_type_name.GetCString() == '$')
             {
                 if (ClangPersistentVariables *persistent_vars = llvm::dyn_cast_or_null<ClangPersistentVariables>(target->GetPersistentExpressionStateForLanguage(lldb::eLanguageTypeC)))
                 {
                     clang::TypeDecl *tdecl = persistent_vars->GetPersistentType(ConstString(lookup_type_name));
-                    
+
                     if (tdecl)
                     {
-                        clang_ast_type.SetCompilerType(ClangASTContext::GetASTContext(&tdecl->getASTContext()),(const lldb::opaque_compiler_type_t)tdecl->getTypeForDecl());
+                        clang_ast_type.SetCompilerType(ClangASTContext::GetASTContext(&tdecl->getASTContext()),
+                                                       reinterpret_cast<lldb::opaque_compiler_type_t>(const_cast<clang::Type*>(tdecl->getTypeForDecl())));
                     }
                 }
             }
-            
+
             if (clang_ast_type.IsValid() == false)
             {
                 if (type_list.GetSize() == 0)

Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Sun Oct 18 14:34:38 2015
@@ -142,8 +142,8 @@ DataExtractor::DataExtractor () :
 // The data must stay around as long as this object is valid.
 //----------------------------------------------------------------------
 DataExtractor::DataExtractor (const void* data, offset_t length, ByteOrder endian, uint32_t addr_size, uint32_t target_byte_size/*=1*/) :
-    m_start     ((uint8_t*)data),
-    m_end       ((uint8_t*)data + length),
+    m_start     (const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(data))),
+    m_end       (const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(data)) + length),
     m_byte_order(endian),
     m_addr_size (addr_size),
     m_data_sp   (),
@@ -287,7 +287,7 @@ DataExtractor::SetData (const void *byte
     }
     else
     {
-        m_start = (uint8_t *)bytes;
+        m_start = const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(bytes));
         m_end = m_start + length;
     }
     return GetByteSize();

Modified: lldb/trunk/source/Core/Scalar.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/Scalar.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Core/Scalar.cpp (original)
+++ lldb/trunk/source/Core/Scalar.cpp Sun Oct 18 14:34:38 2015
@@ -264,7 +264,7 @@ Scalar::GetBytes() const
     case e_ulonglong:
     case e_sint128:
     case e_uint128:
-        return (void *)m_integer.getRawData();
+        return const_cast<void *>(reinterpret_cast<const void *>(m_integer.getRawData()));
     case e_float:
         flt_val = m_float.convertToFloat();
         return (void *)&flt_val;
@@ -273,7 +273,7 @@ Scalar::GetBytes() const
         return (void *)&dbl_val;
     case e_long_double:
         llvm::APInt ldbl_val = m_float.bitcastToAPInt();
-        return (void *)ldbl_val.getRawData();
+        return const_cast<void *>(reinterpret_cast<const void *>(ldbl_val.getRawData()));
     }
     return NULL;
 }

Modified: lldb/trunk/source/Core/StreamString.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/StreamString.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Core/StreamString.cpp (original)
+++ lldb/trunk/source/Core/StreamString.cpp Sun Oct 18 14:34:38 2015
@@ -37,7 +37,7 @@ StreamString::Flush ()
 size_t
 StreamString::Write (const void *s, size_t length)
 {
-    m_packet.append ((char *)s, length);
+    m_packet.append (reinterpret_cast<const char *>(s), length);
     return length;
 }
 

Modified: lldb/trunk/source/DataFormatters/StringPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/StringPrinter.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/StringPrinter.cpp (original)
+++ lldb/trunk/source/DataFormatters/StringPrinter.cpp Sun Oct 18 14:34:38 2015
@@ -324,8 +324,8 @@ DumpUTFBufferToStream (ConversionResult
         {
             // just copy the pointers - the cast is necessary to make the compiler happy
             // but this should only happen if we are reading UTF8 data
-            utf8_data_ptr = (UTF8*)data_ptr;
-            utf8_data_end_ptr = (UTF8*)data_end_ptr;
+            utf8_data_ptr = const_cast<UTF8 *>(reinterpret_cast<const UTF8*>(data_ptr));
+            utf8_data_end_ptr = const_cast<UTF8 *>(reinterpret_cast<const UTF8*>(data_end_ptr));
         }
         
         const bool escape_non_printables = dump_options.GetEscapeNonPrintables();

Modified: lldb/trunk/source/Host/common/Host.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Host/common/Host.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Host/common/Host.cpp (original)
+++ lldb/trunk/source/Host/common/Host.cpp Sun Oct 18 14:34:38 2015
@@ -820,8 +820,8 @@ Host::LaunchProcessPosixSpawn(const char
 #endif
 
     const char *tmp_argv[2];
-    char * const *argv = (char * const*)launch_info.GetArguments().GetConstArgumentVector();
-    char * const *envp = (char * const*)launch_info.GetEnvironmentEntries().GetConstArgumentVector();
+    char * const *argv = const_cast<char * const*>(launch_info.GetArguments().GetConstArgumentVector());
+    char * const *envp = const_cast<char * const*>(launch_info.GetEnvironmentEntries().GetConstArgumentVector());
     if (argv == NULL)
     {
         // posix_spawn gets very unhappy if it doesn't have at least the program
@@ -829,7 +829,7 @@ Host::LaunchProcessPosixSpawn(const char
         // variables don't make it into the child process if "argv == NULL"!!!
         tmp_argv[0] = exe_path;
         tmp_argv[1] = NULL;
-        argv = (char * const*)tmp_argv;
+        argv = const_cast<char * const*>(tmp_argv);
     }
 
 #if !defined (__APPLE__)

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Sun Oct 18 14:34:38 2015
@@ -371,7 +371,7 @@ char **
 Args::GetArgumentVector()
 {
     if (!m_argv.empty())
-        return (char **)&m_argv[0];
+        return const_cast<char **>(&m_argv[0]);
     return nullptr;
 }
 
@@ -379,7 +379,7 @@ const char **
 Args::GetConstArgumentVector() const
 {
     if (!m_argv.empty())
-        return (const char **)&m_argv[0];
+        return const_cast<const char **>(&m_argv[0]);
     return nullptr;
 }
 
@@ -1387,7 +1387,7 @@ Args::ParseArgsForCompletion
         int long_options_index = -1;
         
         val = OptionParser::Parse (dummy_vec.size() - 1,
-                                  (char *const *) &dummy_vec.front(),
+                                  const_cast<char *const *>(&dummy_vec.front()),
                                   sstr.GetData(),
                                   long_options,
                                   &long_options_index);

Modified: lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp (original)
+++ lldb/trunk/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp Sun Oct 18 14:34:38 2015
@@ -673,9 +673,12 @@ PlatformPOSIX::ConnectRemote (Args& args
         if (m_options.get())
         {
             OptionGroupOptions* options = m_options.get();
-            const OptionGroupPlatformRSync* m_rsync_options = (OptionGroupPlatformRSync*)options->GetGroupWithOption('r');
-            const OptionGroupPlatformSSH* m_ssh_options = (OptionGroupPlatformSSH*)options->GetGroupWithOption('s');
-            const OptionGroupPlatformCaching* m_cache_options = (OptionGroupPlatformCaching*)options->GetGroupWithOption('c');
+            const OptionGroupPlatformRSync *m_rsync_options =
+                static_cast<const OptionGroupPlatformRSync *>(options->GetGroupWithOption('r'));
+            const OptionGroupPlatformSSH *m_ssh_options =
+                static_cast<const OptionGroupPlatformSSH *>(options->GetGroupWithOption('s'));
+            const OptionGroupPlatformCaching *m_cache_options =
+                static_cast<const OptionGroupPlatformCaching *>(options->GetGroupWithOption('c'));
 
             if (m_rsync_options->m_rsync)
             {

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteRegisterContext.cpp Sun Oct 18 14:34:38 2015
@@ -183,7 +183,8 @@ GDBRemoteRegisterContext::ReadRegisterBy
             if (!gdb_comm.ReadAllRegisters(m_thread.GetProtocolID(), response))
                 return false;
             if (response.IsNormalResponse())
-                if (response.GetHexBytes ((void *)m_reg_data.GetDataStart(), m_reg_data.GetByteSize(), '\xcc') == m_reg_data.GetByteSize())
+                if (response.GetHexBytes(const_cast<void *>(reinterpret_cast<const void *>(m_reg_data.GetDataStart())),
+                                         m_reg_data.GetByteSize(), '\xcc') == m_reg_data.GetByteSize())
                     SetAllRegisterValid (true);
         }
         else if (reg_info->value_regs)

Modified: lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp (original)
+++ lldb/trunk/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp Sun Oct 18 14:34:38 2015
@@ -227,7 +227,7 @@ DWARFDebugInfoEntry::Extract
 
                 bool isCompileUnitTag = m_tag == DW_TAG_compile_unit;
                 if (cu && isCompileUnitTag)
-                    ((DWARFCompileUnit*)cu)->SetBaseAddress(0);
+                    const_cast<DWARFCompileUnit *>(cu)->SetBaseAddress(0);
 
                 // Skip all data in the .debug_info for the attributes
                 const uint32_t numAttributes = abbrevDecl->NumAttributes();

Modified: lldb/trunk/source/Symbol/CompilerType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/CompilerType.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/CompilerType.cpp (original)
+++ lldb/trunk/source/Symbol/CompilerType.cpp Sun Oct 18 14:34:38 2015
@@ -1201,7 +1201,7 @@ CompilerType::ReadFromMemory (lldb_priva
         data.SetData(data_sp);
     }
     
-    uint8_t* dst = (uint8_t*)data.PeekData(0, byte_size);
+    uint8_t* dst = const_cast<uint8_t*>(data.PeekData(0, byte_size));
     if (dst != nullptr)
     {
         if (address_type == eAddressTypeHost)

Modified: lldb/trunk/source/Symbol/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/Type.cpp?rev=250662&r1=250661&r2=250662&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/Type.cpp (original)
+++ lldb/trunk/source/Symbol/Type.cpp Sun Oct 18 14:34:38 2015
@@ -445,7 +445,7 @@ Type::ReadFromMemory (ExecutionContext *
         data.SetData(data_sp);
     }
 
-    uint8_t* dst = (uint8_t*)data.PeekData(0, byte_size);
+    uint8_t* dst = const_cast<uint8_t*>(data.PeekData(0, byte_size));
     if (dst != nullptr)
     {
         if (address_type == eAddressTypeHost)




More information about the lldb-commits mailing list