When two modules contain struct/union with the same name, check the
definitions are equivalent and diagnose if they are not. This is similar
to CXXRecordDecl where we already discover and diagnose mismatches.
rdar://problem/56764293
Paths
| Differential D71734
[ODRHash] Hash `RecordDecl` and diagnose discovered mismatches. ClosedPublic Authored by vsapsai on Dec 19 2019, 4:29 PM.
Details Summary When two modules contain struct/union with the same name, check the rdar://problem/56764293
Diff Detail
Event Timeline
Comment Actions
bruno added inline comments.
Comment Actions Updated the patch to refactor mode code.
Once the patch gets approved the idea is to upstream some of the refactoring
Comment Actions Think I'll need to make another review pass but here are my comments so far:
Comment Actions Heads up in case it affects you refactoring work: https://reviews.llvm.org/rGa60e8927297005898b10a46300d929ba5cf7833c Comment Actions
The reason is that in C++ ODR diagnostics for TagDecl are handled as part of CXXRecordDecl, I didn't want add a path in TagDecl for C/ObjC only.
They are at the top level but not nested ones, I fixed that and should upload a new patch with that next.
Done in upcoming patch.
Ditto.
Thanks for the heads up @rtrieu, I end up including that as part of rG90f58eaeff5f Comment Actions
Comment Actions Thanks for taking a look Richard, comments inline.
vsapsai marked an inline comment as done. Comment ActionsRebase on top of "main" and address review comments.
Comment Actions Found another case that doesn't emit an error #if defined(FIRST) struct Indirect { int x; }; struct Direct { struct Indirect i; }; #elif defined(SECOND) struct Indirect { double a; }; struct Direct { struct Indirect i; }; #else struct Direct d; #endif According to my debugging there is no error because Direct fields aren't deserialized in -fsyntax-only mode and therefore Indirect definitions aren't compared. But during IRGen there is diagnostic and that's because calculating record layout triggers full deserialization. Also there is diagnostic in C++ because we are dealing with default initialization and DeclareImplicitDefaultConstructor iterates through all the fields deserializing them. I believe the best user experience is consistent diagnostic, so we should emit the error even with -fsyntax-only. If anybody has any objections, please let me know, it would save time. vsapsai retitled this revision from [Modules] Handle tag types and complain about bad merges in C/Objective-C mode to [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches..Dec 14 2022, 2:07 PM Comment Actions If anybody is curious about anonymous structs/unions, the relevant change is D140055. Comment Actions Ping. Also checked the change on a bunch of internal Objective-C/C code using modules - no new errors.
Comment Actions LGTM generally. It'd better to mention this in the Potentially Breaking Changes section of ReleaseNotes.
This revision is now accepted and ready to land.Jan 17 2023, 10:48 PM Comment Actions
Thanks for all your efforts during the review! Mentioned the change in the release notes.
This revision was landed with ongoing or failed builds.Jan 19 2023, 1:59 PM Closed by commit rG160bc160b9b1: [ODRHash] Hash `RecordDecl` and diagnose discovered mismatches. (authored by vsapsai). · Explain Why This revision was automatically updated to reflect the committed changes. vsapsai marked an inline comment as done.
Revision Contents
Diff 237447 clang/include/clang/AST/Decl.h
clang/include/clang/AST/DeclBase.h
clang/include/clang/AST/ODRHash.h
clang/include/clang/Serialization/ASTReader.h
clang/lib/AST/Decl.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/AST/ODRHash.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTReaderDecl.cpp
clang/lib/Serialization/ASTWriterDecl.cpp
clang/test/Modules/odr_hash-record.c
|
We shouldn't store this here; this will make all CXXRecordDecls larger to store a field they will never look at.
We have 27 spare trailing bits in RecordDeclBitfields (28 if you don't add the HasODRHash bit and use 0 to mean "hash not computed"). Can we store this there instead of here?