This is an archive of the discontinued LLVM Phabricator instance.

[MC] Avoid calling vector<FieldInfo> members before FieldInfo is defined
ClosedPublic

Authored by ilya-biryukov on Aug 10 2022, 10:09 AM.

Details

Summary

The C++ Standard requires a complete type T when using any members of
vector<T>, see
https://eel.is/c++draft/vector#overview-4.

This only breaks with latest libc++ in C++20 mode and does not show up
in the common configurations.
We have an internal experimental configuration that discovered this.

Diff Detail

Event Timeline

ilya-biryukov created this revision.Aug 10 2022, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 10:09 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
ilya-biryukov requested review of this revision.Aug 10 2022, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 10 2022, 10:09 AM
alexfh accepted this revision.Aug 10 2022, 10:15 AM

Looks good! Thanks for the fix!

This revision is now accepted and ready to land.Aug 10 2022, 10:15 AM
This revision was landed with ongoing or failed builds.Aug 10 2022, 10:22 AM
This revision was automatically updated to reflect the committed changes.

After this commit, GCC 9 produces warnings on this file:

../lib/MC/MCParser/MasmParser.cpp:227:1: warning: ‘{anonymous}::StructFieldInfo::StructFieldInfo(std::vector<{anonymous}::StructInitializer>&&, {anonymous}::StructInfo)’ defined but not used [-Wunused-function]
  227 | StructFieldInfo::StructFieldInfo(std::vector<StructInitializer> &&V,
      | ^~~~~~~~~~~~~~~

This change did not really change anything in that regard, I'm not sure why this warning was suppressed before.
It's possible that moving the constructor out of the class body had an effect of making it non-inline, which had an effect on the warning, but I'm not sure.

Sent a small refactoring rG7c80c4d67716308dc0f382be88bbe73dd293892c that should fix it.