This is an archive of the discontinued LLVM Phabricator instance.

Fix about a dozen compile warnings
ClosedPublic

Authored by ki.stfu on Sep 7 2016, 11:47 PM.

Details

Summary

It fixes the following compile warnings:

  1. '0' flag ignored with precision and ‘%d’ gnu_printf format
  2. enumeral and non-enumeral type in conditional expression
  3. format ‘%d’ expects argument of type ‘int’, but argument 4 has type ...
  4. enumeration value ‘...’ not handled in switch
  5. cast from type ‘const uint64_t* {aka ...}’ to type ‘int64_t* {aka ...}’ casts away qualifiers
  6. extra ‘;’
  7. comparison between signed and unsigned integer expressions
  8. variable ‘register_operand’ set but not used
  9. control reaches end of non-void function

Diff Detail

Event Timeline

ki.stfu updated this revision to Diff 70650.Sep 7 2016, 11:47 PM
ki.stfu retitled this revision from to Fix about a dozen compile warnings.
ki.stfu updated this object.
ki.stfu added reviewers: clayborg, jingham, zturner.
ki.stfu added a subscriber: lldb-commits.

BTW, the following warnings remain:

  1. unrecognized command line option ‘-Wno-vla-extension’
  2. unrecognized command line option ‘-Wno-deprecated-register’
  3. comparison of unsigned expression >= 0 is always true
[2782/3295] Building CXX object tools/lldb/source/Plugins/Instruction/ARM/CMakeFiles/lldbPluginInstructionARM.dir/EmulationStateARM.cpp.o
../tools/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp: In member function ‘bool EmulationStateARM::StorePseudoRegisterValue(uint32_t, uint64_t)’:
../tools/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp:69:17: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
   if ((dwarf_r0 <= reg_num) && (reg_num <= dwarf_cpsr))
                 ^
../tools/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp: In member function ‘uint64_t EmulationStateARM::ReadPseudoRegisterValue(uint32_t, bool&)’:
../tools/lldb/source/Plugins/Instruction/ARM/EmulationStateARM.cpp:92:17: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
   if ((dwarf_r0 <= reg_num) && (reg_num <= dwarf_cpsr))
                 ^
...
[3136/3295] Building CXX object tools/lldb/source/Utility/CMakeFiles/lldbUtility.dir/ARM64_DWARF_Registers.cpp.o
../tools/lldb/source/Utility/ARM64_DWARF_Registers.cpp: In function ‘bool arm64_dwarf::GetRegisterInfo(unsigned int, lldb_private::RegisterInfo&)’:
../tools/lldb/source/Utility/ARM64_DWARF_Registers.cpp:175:15: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
   if (reg_num >= x0 && reg_num <= pc) {
               ^
  1. format not a string literal and no format arguments
[3217/3295] Building CXX object tools/lldb/source/API/CMakeFiles/liblldb.dir/__/__/scripts/LLDBWrapPython.cpp.o
tools/lldb/scripts/LLDBWrapPython.cpp: In function ‘PyObject* _wrap_SBError_SetErrorStringWithFormat__SWIG_3(PyObject*, PyObject*)’:
tools/lldb/scripts/LLDBWrapPython.cpp:28426:70: warning: format not a string literal and no format arguments [-Wformat-security]
     result = (int)(arg1)->SetErrorStringWithFormat((char const *)arg2);
                                                                      ^
  1. comparison between signed and unsigned integer expressions
tools/lldb/scripts/LLDBWrapPython.cpp: In function ‘PyObject* _wrap_SBTarget_BreakpointCreateByNames__SWIG_0(PyObject*, PyObject*)’:
tools/lldb/scripts/LLDBWrapPython.cpp:55744:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (i = 0; i < arg3; i++) {
                     ^
tools/lldb/scripts/LLDBWrapPython.cpp: In function ‘PyObject* _wrap_SBTarget_BreakpointCreateByNames__SWIG_1(PyObject*, PyObject*)’:
tools/lldb/scripts/LLDBWrapPython.cpp:55836:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (i = 0; i < arg3; i++) {
                     ^
tools/lldb/scripts/LLDBWrapPython.cpp: In function ‘PyObject* _wrap_SBTarget_BreakpointCreateByNames__SWIG_2(PyObject*, PyObject*)’:
tools/lldb/scripts/LLDBWrapPython.cpp:55937:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for (i = 0; i < arg3; i++) {
                     ^
ki.stfu updated this revision to Diff 70653.Sep 8 2016, 12:04 AM

Remove obvious comment

ki.stfu updated this revision to Diff 70654.Sep 8 2016, 12:05 AM

Apply clang-format

zturner added inline comments.Sep 8 2016, 12:11 AM
source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp
1462–1467

I find this code pretty ugly because of how the line breaks. Can you change this to:

uint32_t segment_permissions = 0;
if (load_cmd.initprot & VM_PROT_READ)
  segment_permissions |= ePermissionsReadable;
if (load_cmd.initprot & VM_PROT_WRITE)
  segment_permissions |= ePermissionsWritable;
if (load_cmd.initprot & VM_PROT_EXECUTE)
  segment_permissions |= ePermissionsExecutable;

or, alternatively:

// global scope
static uint32_t translateSegmentPermissions(uint32_t initprot) {
  return ((initprot & VM_PROT_READ) ? ePermissionsReadable : 0u) |
              (initprot & VM_PROT_WRITE) ? ePermissionsWritable : 0u) |
              (initprot & VM_PROT_EXECUTE) ? ePermissionsExecutable : 0u);
}

// at this location
const uint32_t segment_permissions = translateSegmentPermissions(load_cmd.initprot);
source/Plugins/ScriptInterpreter/Python/PythonDataObjects.cpp
521

Am I missing something? Why isn't this just result = static_cast<int64_t>(uval);

source/Target/StackFrame.cpp
1425

Probably only of theoretical interest since I don't think pointee->GetByteSize() can ever return 0, but maybe this should be offset >= 0

1591

How about just delete this variable instead?

ki.stfu updated this revision to Diff 70656.Sep 8 2016, 1:04 AM
ki.stfu marked 3 inline comments as done.

Fixes per Zachary's comments

ki.stfu marked an inline comment as done.Sep 8 2016, 1:05 AM
ki.stfu added inline comments.
source/Target/StackFrame.cpp
1425

Good point. Thanks!

clayborg accepted this revision.Sep 8 2016, 8:55 AM
clayborg edited edge metadata.
This revision is now accepted and ready to land.Sep 8 2016, 8:55 AM
zturner accepted this revision.Sep 8 2016, 12:57 PM
zturner edited edge metadata.
ki.stfu updated this revision to Diff 70973.Sep 11 2016, 10:29 PM
ki.stfu edited edge metadata.

Rebase against ToT

ki.stfu updated this revision to Diff 70976.Sep 11 2016, 10:32 PM

Apply clang-format

ki.stfu closed this revision.Sep 11 2016, 10:34 PM