<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - [ThinLTO] assert(GS != DefinedGlobals.end()) failed"
   href="https://llvm.org/bugs/show_bug.cgi?id=28760">28760</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[ThinLTO] assert(GS != DefinedGlobals.end()) failed
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lld
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>twoh@fb.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Encountered assert(GS != DefinedGlobals.end()) failure while running ThinLTO.
The assertion statement is in MustPreserveGV lambda function in
llvm::thinLTOInternalizeModule (lib/Transforms/IPO/FunctionImport.cpp).

It seems that the assertion fails because it fails to recover the "original
name" of the global value. ModuleSummaryIndex::getOriginalNameBeforePromote
attempts to get the original name by stripping .llvm.{MODHASH}, but what I
observe is that ".1" is still appended to the expected original name. 

Then where this extra ".1" comes from? It is appended when the global value is
materialized. IRLinker::materialize function calls
IRLinker::linkGlobalValueProto function, and inside that function if DGV is
nullptr or ShouldLink is true then IRLinker::copyGlobalValueProto function is
called to create a global variable in the destination module that corresponds
to SGV. I found that newly created global variable has the extra ".1" added to
the name of the SGV. 

When this thing happens? I don't have a complete understanding about it but I
observed that the same global value is materialized twice during the single
invocation of IRLinker::run function, once with GlobalValueMaterializer and
once with LocalValueMaterializer. First, the global value 

; Materializable
; Function Attrs: nounwind uwtable
define weak_odr void @foo(%1*) unnamed_addr #7 comdat($comdat1) align 2
personality i32 (...)* @__gxx_personality_v0 {}
(I renamed the function and comdat)

it materialized with GlobalValueMaterializer, (so the IRLinker::materialize
function is called with ForAlias == false), and the materialized value is

; Function Attrs: nounwind uwtable
declare void @foo(%"type1"*) unnamed_addr #2 align 2

Then, later, the same value is materialized again with LocalValueMaterializer
(so ForAlias == true for IRLinker::materialize), and the materialized value is

; Function Attrs: nounwind uwtable
define internal void @foo.1(%"type 0x7efb6ee89d80"*) unnamed_addr #2
comdat($comdat1) align 2 personality i32 (...)* @__gxx_personality_v0 !dbg
!12345 {
  // function definition
}</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>