This is an archive of the discontinued LLVM Phabricator instance.

[clang] Cached linkage assertion for static locals of static function
AcceptedPublic

Authored by cebowleratibm on Jun 20 2022, 1:31 PM.

Details

Summary

An assertion failure was encountered after https://reviews.llvm.org/D126340:

llvm/clang/lib/AST/Decl.cpp:1510: clang::LinkageInfo clang::LinkageComputer::getLVForDecl(const clang::NamedDecl *, clang::LVComputationKind): Assertion `D->getCachedLinkage() == LV.getLinkage()' failed.

Diff Detail

Event Timeline

cebowleratibm created this revision.Jun 20 2022, 1:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 1:31 PM
cebowleratibm requested review of this revision.Jun 20 2022, 1:31 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2022, 1:31 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cebowleratibm retitled this revision from [clang] Linkage of static locals may require inspecting visibility to [clang] Linkage computation of static locals may require forcing visibility computation.Jun 30 2022, 10:45 AM
cebowleratibm added reviewers: rnk, hans, thakis.
daltenty accepted this revision.Oct 28 2022, 4:48 PM

LGTM. Doing the inner computation while observing visibility seems like the right thing to do in this case.

clang/lib/AST/Decl.cpp
1377

Just adding my own note of explanation, since this stuff can be a little hard to follow.

This inner linkage query needs to observe visibility in order to get a consistent result, even if the calling query (i.e. getLinkageInternal in this case) has passed in a LVComputationKind indicating we don't need to for the LocalDecl. If we don't, we may get results inconsistent with the cached value for the enclosing FunctionDecl, hence the assert.

This revision is now accepted and ready to land.Oct 28 2022, 4:48 PM
cebowleratibm planned changes to this revision.Nov 7 2022, 12:21 PM
cebowleratibm retitled this revision from [clang] Linkage computation of static locals may require forcing visibility computation to [clang] Cached linkage assertion for static locals of static function.
cebowleratibm edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Nov 10 2022, 10:16 AM

I believe the fix for a52d151f9dde7 inadvertently exposed a code path where by the linkage of a static local of a static function, which would otherwise return LinkageInfo::none() may now return VisibleNoLinkage depending on the incoming computation argument.

I don't think a static local of a function with no linkage should ever return VisibleNoLinkage so I've added the appropriate guard such that the linkage evaluation with return no linkage regardless of the computation argument.

daltenty accepted this revision.Dec 7 2022, 7:22 AM

New revision LGTM, VisibleNoLinkage is typical reserved for types from inline functions so it doesn't seem sensible to return. Looking at the C++ standard, I'm not even convinced this is guaranteed to be the same object if the function doesn't have external linkage, so I think the guard is sensible.