Hit assert(I != ValueMap.end() && "Value not in slotcalculator!") in ValueEnumerator.cpp

Hi there,

I added a function to a module, but failed to write the bitcode to file because it hit the:
assert(I != ValueMap.end() && "Value not in slotcalculator!")

So I added some diagnosis information there,

unsigned ValueEnumerator::getValueID(const Value *V) const {
   if (isa<MDNode>(V) || isa<MDString>(V)) {
     ValueMapType::const_iterator I = MDValueMap.find(V);
     assert(I != MDValueMap.end() && "Value not in slotcalculator!");
     return I->second-1;
   }

   ValueMapType::const_iterator I = ValueMap.find(V);
   if (!(I != ValueMap.end() && "Value not in slotcalculator!")) {
     V->dump();
     for (ValueMapType::const_iterator IB = ValueMap.begin(), IE = ValueMap.end();
          IB != IE; IB++) {
       (*IB).first->dump(); errs() << (*IB).second << " " << V << " " << (*IB).first << "\n";
     }
     assert(I != ValueMap.end() && "Value not in slotcalculator!"); // this is where the assertion fails
   }
   return I->second-1;
}

The output show me that the V that it complains is not the ValueMap, but the content of *V is in the ValueMap.

This happened when I applied my pass to some modules from .cpp, and my pass worked on some modules from .c files.

Any hint on this?

Thanks,
Guoliang

Hi Guoliang,

I added a function to a module, but failed to write the bitcode to file
because it hit the:
assert(I != ValueMap.end()&& "Value not in slotcalculator!")

does the module pass the verifier after you add the function to it?

Ciao,

Duncan.

Thanks Duncan.

After adding the verifier, it gives me:

Broken module found, verification continues.
Referencing function in another module!

And I fixed my code based on this.

Thanks,
Guoliang