This is an archive of the discontinued LLVM Phabricator instance.

[LLD] [MachO] Fix GCC build warnings
ClosedPublic

Authored by mstorsjo on Aug 2 2022, 1:05 AM.

Details

Reviewers
thakis
int3
Group Reviewers
Restricted Project
Commits
rG59c6f418fa3c: [LLD] [MachO] Fix GCC build warnings
Summary

This fixes the following warnings produced by GCC 9:

../tools/lld/MachO/Arch/ARM64.cpp: In member function ‘void {anonymous}::OptimizationHintContext::applyAdrpLdr(const lld::macho::OptimizationHint&)’:
../tools/lld/MachO/Arch/ARM64.cpp:448:18: warning: comparison of integer expressions of different signedness: ‘int64_t’ {aka ‘long int’} and ‘uint64_t’ {aka ‘long unsigned int’} [-Wsign-compare]
  448 |   if (ldr.offset != (rel1->referentVA & 0xfff))
      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../tools/lld/MachO/UnwindInfoSection.cpp: In function ‘bool canFoldEncoding(compact_unwind_encoding_t)’:
../tools/lld/MachO/UnwindInfoSection.cpp:404:44: warning: comparison between ‘enum<unnamed>’ and ‘enum<unnamed>’ [-Wenum-compare]
  404 |   static_assert(UNWIND_X86_64_MODE_MASK == UNWIND_X86_MODE_MASK, "");
      |                                            ^~~~~~~~~~~~~~~~~~~~
../tools/lld/MachO/UnwindInfoSection.cpp:405:49: warning: comparison between ‘enum<unnamed>’ and ‘enum<unnamed>’ [-Wenum-compare]
  405 |   static_assert(UNWIND_X86_64_MODE_STACK_IND == UNWIND_X86_MODE_STACK_IND, "");
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~

Diff Detail

Event Timeline

mstorsjo created this revision.Aug 2 2022, 1:05 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptAug 2 2022, 1:05 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
mstorsjo requested review of this revision.Aug 2 2022, 1:05 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 1:05 AM
int3 added inline comments.Aug 2 2022, 5:28 AM
lld/MachO/UnwindInfoSection.cpp
404–410

Could we declare the enum to have size uint32_t instead? Or does GCC still warn in that case?

mstorsjo added inline comments.Aug 2 2022, 5:32 AM
lld/MachO/UnwindInfoSection.cpp
404–410

GCC still warns about that - it's not so much about whether the enums have a defined size or not, but simply that they're values from two different enums - comparing them in most cases would be a bug, while we strictly care only about their numerical value here.

int3 accepted this revision.Aug 2 2022, 5:35 AM
int3 added inline comments.
lld/MachO/UnwindInfoSection.cpp
404–410

Gotcha. Thanks!

This revision is now accepted and ready to land.Aug 2 2022, 5:35 AM
This revision was automatically updated to reflect the committed changes.