This is an archive of the discontinued LLVM Phabricator instance.

Verifier: Disallow uses of intrinsic global variables
ClosedPublic

Authored by arsenm on Nov 28 2022, 11:28 AM.

Details

Summary

appendToGlobalCtors implicitly assumes this is the case, since it
deletes and recreates without trying to update any uses.

This ran into an interesting problem in a few linker tests. During the
link, ConstantExpr casts were speculatively created to replace any
uses that might need them for replacement. These unused ConstantExprs
would hang around and still appear on the use list. It seems like a
bug that those stick around, but I'm not sure where those are supposed
to be cleaned up. Avoid this by not creating the casts for appending
linkage.

Delete one of the casts entirely as it breaks no tests. The verifier
has enforced a specific type for these since 2011, so I don't see why
we would need to handle linking modules with a wrong types. One test
does fail without the second cast (Linker/appending-global-proto.ll,
added by D95126). This test looks contrived; it's using appending
linkage with a regular variable. The LangRef suggests this is illegal
(and suggests another missing verifier check).

Diff Detail

Event Timeline

arsenm created this revision.Nov 28 2022, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 11:28 AM
arsenm requested review of this revision.Nov 28 2022, 11:28 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 28 2022, 11:28 AM
Herald added a subscriber: wdng. · View Herald Transcript
tra added a comment.Nov 28 2022, 2:52 PM

Verifier: Disallow uses of intrinsic global variables

Is this the correct description for this patch? The modified test itself does not seem to use any global variables. Perhaps I'm missing something.

llvm/test/CodeGen/AMDGPU/cgp-addressing-modes-flat.ll
31 ↗(On Diff #478294)

I'm just curious whether it's expected that some address calculations were not sunk into a conditional branch as it's done on GFX9/10?
I would assume that such a generic optimization would be GPU-agnostic.

arsenm updated this revision to Diff 478390.Nov 28 2022, 3:05 PM

Correct patch

arsenm added inline comments.Nov 28 2022, 3:05 PM
llvm/test/CodeGen/AMDGPU/cgp-addressing-modes-flat.ll
31 ↗(On Diff #478294)

gfx7 and 8 didn't have flat offsets or any useful flat addressing modes

nikic added a subscriber: nikic.Dec 6 2022, 7:03 AM

lld.ELF/lto::linkage.ll fails in pre-merge checks: LLVM ERROR: unknown special variable

arsenm updated this revision to Diff 484611.Dec 21 2022, 10:12 AM
arsenm added a reviewer: nikic.

Opaque pointers fixes the lld test failure. If other pointer cast mismatches for appending variables is banned (D140485) we don't need to worry about the dangling constant expressions anymore

nikic accepted this revision.Jan 5 2023, 10:58 AM

LGTM

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