chopper icon indicating copy to clipboard operation
chopper copied to clipboard

ReturnToVoidFunction pass does not properly handle functions that return structs

Open andreamattavelli opened this issue 8 years ago • 0 comments

The issue is mainly due to how LLVM handles the returned struct:

define i32 @main(i32 %argc, i8** %argv, i8** %envp) #0 {                                                                                              
entry:                                                                                                                                                
  %retval = alloca i32, align 4                                                                                                                       
  %argc.addr = alloca i32, align 4                                                                                                                    
  %argv.addr = alloca i8**, align 8                                                                                                                   
  %envp.addr = alloca i8**, align 8                                                                                                                   
  %k = alloca i32, align 4                                                                                                                            
  %o = alloca %struct.point, align 4                                                                                                                  
  store i32 0, i32* %retval                                                                                                                           
  store i32 %argc, i32* %argc.addr, align 4                                                                                                           
  store i8** %argv, i8*** %argv.addr, align 8                                                                                                         
  store i8** %envp, i8*** %envp.addr, align 8                                                                                                         
  %0 = bitcast i32* %k to i8*                                                                                                                         
  call void @klee_make_symbolic(i8* %0, i64 4, i8* getelementptr inbounds ([2 x i8]* @.str, i32 0, i32 0))                                            
  %call = call { i64, i64 } @f()                                                                                                                      
  %1 = bitcast %struct.point* %o to { i64, i64 }*                                                                                                     
  %2 = getelementptr { i64, i64 }* %1, i32 0, i32 0                                                                                                   
  %3 = extractvalue { i64, i64 } %call, 0                                                                                                             
  store i64 %3, i64* %2, align 1                                                                                                                      
  %4 = getelementptr { i64, i64 }* %1, i32 0, i32 1                                                                                                   
  %5 = extractvalue { i64, i64 } %call, 1                                                                                                             
  store i64 %5, i64* %4, align 1                                                                                                                      
  %x = getelementptr inbounds %struct.point* %o, i32 0, i32 0                                                                                         
  store i32 876, i32* %x, align 4                                                                                                                     
  %6 = load i32* %k, align 4                                                                                                                          
  %cmp = icmp sgt i32 %6, 0

My guess is that we should remove all the code related to the copy of values from struct to struct.

andreamattavelli avatar Jul 21 '17 15:07 andreamattavelli