<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 --- - c++ programs type name changed in llvm ir after linking"
href="https://llvm.org/bugs/show_bug.cgi?id=27922">27922</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>c++ programs type name changed in llvm ir after linking
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>fanx@cse.unsw.edu.au
</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>Created <span class=""><a href="attachment.cgi?id=16431" name="attach_16431" title="the two source files: main.cpp and b.cpp. and the generated ir file: whole.mem2reg.ll">attachment 16431</a> <a href="attachment.cgi?id=16431&action=edit" title="the two source files: main.cpp and b.cpp. and the generated ir file: whole.mem2reg.ll">[details]</a></span>
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</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>