This is an archive of the discontinued LLVM Phabricator instance.

[NFC] [Serialization] Add static assert for the size of the decls to mention developers to remember to touch the serializer after them modified the field of decls
ClosedPublic

Authored by ChuanqiXu on Jan 17 2023, 11:58 PM.

Details

Summary

It is easy for the developers to forget to touch the serializer after them add new field to decls. Then if the existing tests fail to catch such cases, it may be a bug report from users some day. And it is time-consuming to solve such bugs.

To mitigate the problem, I add the static_asserts in the serializer. So that the developers can understand they need to modify the serializer after they saw the static assertion failure. Although this can't solve all the problems, I feel the current status can be much better.

Diff Detail

Event Timeline

ChuanqiXu created this revision.Jan 17 2023, 11:58 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 17 2023, 11:58 PM
ChuanqiXu requested review of this revision.Jan 17 2023, 11:58 PM
erichkeane accepted this revision.Jan 18 2023, 5:58 AM

This is great! This is definitely a mistake I've made a few times :) The solution itself is only so-so, but I don't have an idea for a better one, so I think this can do for now.

This revision is now accepted and ready to land.Jan 18 2023, 5:58 AM

Ah, Windows build failures are obviously relevant :) One gotcha here is going to be to chase down all the sizes of the records on different platforms.

Ah, Windows build failures are obviously relevant :) One gotcha here is going to be to chase down all the sizes of the records on different platforms.

The failure shouldn't be related the patch since the patch itself should only cause static assert failures. I saw you guys have already found the solutions in D141954. So I am going to land this.

This revision was landed with ongoing or failed builds.Jan 18 2023, 6:20 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 18 2023, 6:20 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
thakis added a subscriber: thakis.Jan 18 2023, 6:32 PM
thakis added inline comments.
clang/lib/Serialization/ASTWriterDecl.cpp
2313

How can this work? This includes an ArrayRef (http://llvm-cs.pcc.me.uk/tools/clang/include/clang/AST/DeclOpenMP.h#221) which contains a pointer and a size_t. That alone will be 16 bytes on 64-bit builds and 8 bytes on 32-bit builds.

ChuanqiXu added inline comments.Jan 18 2023, 6:41 PM
clang/lib/Serialization/ASTWriterDecl.cpp
2313

You're right that I forgot the case for 32-bit machine. I've reverted the patch. And I need to look for better solutions.

Thanks for the fast revert!

It passes on the previous windows CI. It looks like the assertion for sizeof(...) is indeed not a good idea.

Ah, Windows build failures are obviously relevant :) One gotcha here is going to be to chase down all the sizes of the records on different platforms.

The failure shouldn't be related the patch since the patch itself should only cause static assert failures. I saw you guys have already found the solutions in D141954. So I am going to land this.

No, that patch was talking about the libcxx issue. The windows issues I saw in pre-commit CI on this patch were it hitting your assert all over the place.

ChuanqiXu updated this revision to Diff 494511.Feb 2 2023, 10:34 PM

This is only part of the original revision, which contains platform independent assertion only.

This revision was landed with ongoing or failed builds.Feb 2 2023, 10:43 PM