struct type parament

Hi All,

I generated the following code with "clang -flto" command.

void test(struct StruTyName *a) {
     ...
}

Then the type of test function is "void (%struct.StruTyName.100*)" by calling function::getFunctionType API.

What's the meaning of number 100?

Best,
Haopeng

Hi,

I think this is when a collision is found on the name.
I would be interesting to have the full test, it might be that the API is used in a way such that type is constantly re-created even if it already exists, which might be inefficient.

See in lib/IR/Type.cpp, StructType::setName(StringRef Name):

...
  // While we have a name collision, try a random rename.
  if (Entry->getValue()) {
    SmallString<64> TempStr(Name);
    TempStr.push_back('.');
    raw_svector_ostream TmpStream(TempStr);
    unsigned NameSize = Name.size();
   
    do {
      TempStr.resize(NameSize + 1);
      TmpStream.resync();
      TmpStream << getContext().pImpl->NamedStructTypesUniqueID++;
      
      Entry = &getContext().pImpl->
                 NamedStructTypes.GetOrCreateValue(TmpStream.str());
    } while (Entry->getValue());
  }

Hi Mehdi,

Thanks for your reply.

It seems caused by random rename because I saw %struct.StructTyName.692.475*, which might be twice renaming.

Does this collision occur because this type is declared more than once?

I encountered this problem when used clang to compile transmission 1.42 (http://download.transmissionbt.com/files/) with configuration: "./configure --disable-gtk". Then in ./third-party/libevent/event.o.ll, you can see the function "event_base_get_method" is an example.

Best,
Haopeng

Hi Haopeng,

One more element, I just noticed you are using LTO, I am not sure how it is implemented but my guess is that there is a shared LLVMContext. If multiple files include this structure declaration, I wouldn’t be surprised if it trigger creating the type over and over in the IR.

Why is it a problem for you by the way? Does the compilation fails in some way?

I tried to compare two types. Because of renaming, the comparison result is not as expected. How to deal with renaming while comparing types?

Best,
Haopeng

Do you really want to map the “source code level” type or does a comparison based on the structural equivalence would be OK?

See:

  /// isLayoutIdentical - Return true if this is layout identical to the
  /// specified struct.
  bool isLayoutIdentical(StructType *Other) const;

It works. Thank you.

Best,
Haopeng