clang - segmentation fault in virtual method invokation -


clang uses following scheme define concrete type in llvm ir:

%"mytype" = type {virtual_method_types, field_types, super_types} 

and in order call virtual method (e.g. virtual int f(){}) following scheme used:

%0 = load %"mytype"** %this %1 = bitcast %"mytype"* %0 i32 (%"mytype"*)*** %vtable = load i32 (%"mytype"*)*** %1 %method = getelementptr inbounds i32 (%"mytype"*)** %vtable, i64 0 (index of f() in vt) %ld = load i32 (%"mytype"*)** %method  %call = call i32 (%"mytype"*)* %ld (%"mytype"* %0)  

however, if following scheme used instead, should changed in above code prevent seg fault?

 %"mytype" = type {field_types, super_types, virtual_method_types} 

this line gets pointer @ start of object, vptr (pointer virtual table):

%1 = bitcast %"mytype"* %0 i32 (%"mytype"*)*** 

if place vptr @ end of object instead, code need change use extractvalue on %0 pointer correct location of vptr (or alternatively getelementptr on %this, anyway need load %this, doesn't help). instance, if vptr 12th field in %"mytype", you'll need like:

%1 = extractvalue %"mytype" %0, 12 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -