This is an archive of the discontinued LLVM Phabricator instance.

Call MarkVirtualMembersReferenced on an actual class definition
ClosedPublic

Authored by sberg on Mar 1 2023, 2:46 PM.

Details

Summary

...rather than on potentially just a declaration.
Without the fix, the newly added clang/test/SemaCXX/warn-undefined-internal.cpp failed with

error: 'warning' diagnostics expected but not seen:
  File /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp Line 12 (directive at /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:13): function 'test2()::S::f' has internal linkage but is not defined
error: 'note' diagnostics expected but not seen:
  File /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp Line 14 (directive at /home/sbergman/github.com/llvm/llvm-project/clang/test/SemaCXX/warn-undefined-internal.cpp:15): used here

(I ran into this when two LibreOffice Clang plugins produced false positive warnings, as they relied on Decl::isReferenced() returning true for such virtual member functions of local classes.)

Diff Detail

Event Timeline

sberg created this revision.Mar 1 2023, 2:46 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 1 2023, 2:46 PM
sberg requested review of this revision.Mar 1 2023, 2:46 PM
sberg added inline comments.Mar 1 2023, 2:51 PM
clang/lib/Sema/SemaDeclCXX.cpp
17940

That call of getCanonicalDecl originated with https://github.com/llvm/llvm-project/commit/88d292ccb86c10857298c252bb93331f7ef2258a "Rework when and how vtables are emitted, by tracking where vtables are", and I wonder if more of the uses of the modified Class below suffer from the same issue, that they expect Class to represent a definition when it might potentially reference just a declaration.

aaron.ballman accepted this revision.Mar 2 2023, 6:30 AM

Thanks! LGTM, though please add a release note about the fix.

clang/lib/Sema/SemaDeclCXX.cpp
17940

The only other place the class is being used is in VTableUses and Sema::DefineUsedVTables() does CXXRecordDecl *Class = VTableUses[I].first->getDefinition(); so I think that's safe (if it a bit convoluted). So I think this is okay as-is.

This revision is now accepted and ready to land.Mar 2 2023, 6:30 AM