[llvm-bugs] [Bug 27922] New: c++ programs type name changed in llvm ir after linking

via llvm-bugs llvm-bugs at lists.llvm.org
Fri May 27 22:09:58 PDT 2016


https://llvm.org/bugs/show_bug.cgi?id=27922

            Bug ID: 27922
           Summary: c++ programs type name changed in llvm ir after
                    linking
           Product: new-bugs
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: fanx at cse.unsw.edu.au
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Created attachment 16431
  --> https://llvm.org/bugs/attachment.cgi?id=16431&action=edit
the two source files: main.cpp and b.cpp. and the generated ir file:
whole.mem2reg.ll

Recently I am using clang++ (3.8.0) to compile some c++ programs and find that
some type names will be changed after linking different modules. Here is a
simple example:

I have two files: main.cpp and b.cpp

main.cpp
#include <iostream>
using namespace std;

class A {
  public:
    virtual void f() {
      cout << "A:\tf\n";
    }
};

int main ()
{
  A *p = new A;
  p->f();
  return 0;
}

b.cpp
#include <iostream>
using namespace std;

class X {
  public:
    virtual int g();
};

int X::g()
{
  cout << "X:\tg\n";
  return 0;
}

I use the following commands to compile these two files separately and then
link them tegother:
clang++ -c -emit-llvm -o b.bc b.cpp
clang++ -c -emit-llvm -o main.bc main.cpp
llvm-link -o whole.bc b.bc main.bc
opt -mem2reg -o whole.mem2reg.bc whole.bc
llvm-dis -o whole.mem2reg.ll whole.mem2reg.bc

In the file whole.mem2reg.ll, type "class.A" has been replaced by "class.X" in
function main, the constructor of class A and the virtual member function f of
class A:

; Function Attrs: norecurse uwtable
define i32 @main() #3 {
  %1 = call noalias i8* @_Znwm(i64 8) #6
  %2 = bitcast i8* %1 to %class.X*
  call void @_ZN1AC2Ev(%class.X* %2) #2
  %3 = bitcast %class.X* %2 to void (%class.X*)***
  %4 = load void (%class.X*)**, void (%class.X*)*** %3, align 8
  %5 = getelementptr inbounds void (%class.X*)*, void (%class.X*)** %4, i64 0
  %6 = load void (%class.X*)*, void (%class.X*)** %5, align 8
  call void %6(%class.X* %2)
  ret i32 0
}

; Function Attrs: inlinehint nounwind uwtable
define linkonce_odr void @_ZN1AC2Ev(%class.X* %this) unnamed_addr #5 comdat
align 2 {
  %1 = bitcast %class.X* %this to i32 (...)***
  store i32 (...)** bitcast (i8** getelementptr inbounds ([3 x i8*], [3 x i8*]*
@_ZTV1A, i64 0, i64 2) to i32 (...)**), i32 (...)*** %1, align 8
  ret void
}

; Function Attrs: uwtable
define linkonce_odr void @_ZN1A1fEv(%class.X* %this) unnamed_addr #0 comdat
align 2 {
  %1 = call dereferenceable(272) %"class.std::basic_ostream"*
@_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(%"class.std::basic_ostream"*
dereferenceable(272) @_ZSt4cout, i8* getelementptr inbounds ([6 x i8], [6 x
i8]* @.str.4, i32 0, i32 0))
  ret void
}

Does anyone know why llvm replace the type name?

Thanks

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20160528/b043ce61/attachment.html>


More information about the llvm-bugs mailing list