This is an archive of the discontinued LLVM Phabricator instance.

[NFC] Make headers self-contained.
ClosedPublic

Authored by rupprecht on Nov 18 2022, 8:59 AM.

Details

Summary

Some headers in LLDB work only when considered as textual inclusion, but not if one attempts to use them on their own or with a different context.

  • python-typemaps.h: uses Python definitions without using "Python.h".
  • RISCVCInstructions.h uses RISC-V register enums without including the enums header.
  • RISCVInstructions.h includes EmulateInstructionRISCV.h, but is unnecessary since we forward-declare EmulateInstructionRISCV anyway. Including the header is problematic because EmulateInstructionRISCV.h uses DecodeResult which isn't defined until later in RISCVInstructions.h.

This makes LLDB build cleanly with the "parse_headers" feature [1]. I'm not sure what the analagous CMake option is.

[1] I didn't find public documentation but @MaskRay wrote this up: https://maskray.me/blog/2022-09-25-layering-check-with-clang#parse_headers

Diff Detail

Event Timeline

rupprecht created this revision.Nov 18 2022, 8:59 AM
rupprecht requested review of this revision.Nov 18 2022, 8:59 AM
MaskRay accepted this revision.Nov 28 2022, 7:18 PM
MaskRay added inline comments.
lldb/source/Plugins/Instruction/RISCV/RISCVInstructions.h
15–16

I assume that this is correct, even after considering IWYU. Perhaps worth a double check.

This revision is now accepted and ready to land.Nov 28 2022, 7:18 PM
labath accepted this revision.Nov 29 2022, 2:06 AM
rupprecht marked an inline comment as done.Nov 29 2022, 4:00 AM
rupprecht added inline comments.
lldb/source/Plugins/Instruction/RISCV/RISCVInstructions.h
15–16

Thanks, I double checked: the only top-level type exported by EmulateInstructionRISCV.h is class EmulateInstructionRISCV. That's forward-declared in this file (line 20 on the base side), and only ever referred to by reference, so a forward declare is fully sufficient for that.

This revision was automatically updated to reflect the committed changes.
rupprecht marked an inline comment as done.