This is an archive of the discontinued LLVM Phabricator instance.

LowerTypeTests: Drop function type metadata only if we're going to replace it.
ClosedPublic

Authored by pcc on Jul 18 2017, 7:34 PM.

Details

Summary

Previously we were (mis)handling jump table members with a prevailing
definition in a full LTO module and a non-prevailing definition in a
ThinLTO module by dropping type metadata on those functions entirely,
which would cause type tests involving such functions to fail.

This patch causes us to drop metadata only if we are about to replace
it with metadata from cfi.functions.

We also want to replace metadata for available_externally functions,
which can arise in the opposite scenario (prevailing ThinLTO
definition, non-prevailing full LTO definition). The simplest way
to handle that is to remove the definition; there's little value in
keeping it around at this point (i.e. after most optimization passes
have already run) and later code will try to use the function's linkage
to create an alias, which would result in invalid IR if the function
is available_externally.

Fixes PR33832.

Event Timeline

pcc created this revision.Jul 18 2017, 7:34 PM
tejohnson added inline comments.Jul 19 2017, 1:54 PM
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
1485

ExportSummary is the full LTO case? Can you note that somewhere? I forget where that is documented (it isn't where ExportSummary and ImportSummary are declared in LowerTypeTestsModule and LowerTypeTests).

1515

I'm assuming this change is to handle your first case:
"jump table members with a prevailing
definition in a full LTO module and a non-prevailing definition in a
ThinLTO module...This patch causes us to drop metadata only if we are about to replace
it with metadata from cfi.functions."

I'm a bit confused on where here indicates that the LTO version is prevailing and there is a non-prevailing def in ThinLTO? Also, is M the full LTO module or the ThinLTO Module? I was assuming the latter but since F is a declaration below, it wouldn't be the case where F was prevailing in this module.

1515

Needs comment.

llvm/test/Transforms/LowerTypeTests/export-icall.ll
1

Are the changes in this test case testing for both parts of the fix in this patch?

41

Without the fix in this patch I guess this would try to create an alias with available_externally linkage?

pcc added inline comments.Jul 19 2017, 2:32 PM
llvm/lib/Transforms/IPO/LowerTypeTests.cpp
1485

Yes, ExportSummary is for full LTO. It's documented here: http://llvm-cs.pcc.me.uk/include/llvm/Transforms/IPO/PassManagerBuilder.h#138

In a separate change I'll add a reference to that where those fields are defined.

1515

I'm assuming this change is to handle your first case:

Yes.

Also, is M the full LTO module or the ThinLTO Module?

It is the full LTO module.

I'm a bit confused on where here indicates that the LTO version is prevailing and there is a non-prevailing def in ThinLTO?

If the LTO def is prevailing and the ThinLTO def is non-prevailing, we will see a function definition here (because it will have been copied into the combined module by the IRMover) as well as a definition entry in cfi.functions for that function (because we will have added it to the full LTO module in the ThinLTO bitcode writer -- we know it is non-prevailing because we can expect to see max 1 prevailing definition per symbol).

It looks like the original code assumed that if cfi.functions contained a definition entry for a function, there must not be a definition in the full LTO module (and therefore we can go ahead and drop the metadata and expect to enter the if statement below to re-add it). But that wasn't accounting for the ThinLTO def potentially being non-prevailing.

1515

Will do.

llvm/test/Transforms/LowerTypeTests/export-icall.ll
1

Hmm, not quite. There ought to also be a test with a linker definition here. I'll add it.

41

Right.

pcc updated this revision to Diff 107422.Jul 19 2017, 5:11 PM
pcc marked 2 inline comments as done.
  • Address review comments
This revision is now accepted and ready to land.Jul 19 2017, 9:50 PM
This revision was automatically updated to reflect the committed changes.