[llvm-dev] DSA - CallTargets output

Syed Rafiul Hussain via llvm-dev llvm-dev at lists.llvm.org
Sat May 7 05:54:53 PDT 2016


I was trying to use DSA to find the targets for indirect calls. I get
the correct targets for the example mentioned if the paper
(http://www.rw.cdl.uni-saarland.de/teaching/spa10/papers/dsa.pdf). I
tweaked that example a little bit and get the incorrect targets.

#include <stdio.h>
#include <stdlib.h>

typedef struct list{
struct list *Next;
int Data;
}list;

int Global = 10;

void do_all(list *L, void (*FP)(int *)){
do{
FP(&L->Data);
L= L->Next;
}while(L);
}

void addG(int *X){
(*X) += Global;
}

void subtractG(int *X){
(*X) -= Global;
}

void subtractGToList(list *L){
do_all (L, subtractG);
}
void addGToList(list *L){
do_all (L, addG);
}

list *makeList (int Num){
list *New = malloc(sizeof(list));
New->Next = Num? makeList(Num - 1) : 0;
New->Data = Num;
return New;
}

int main(){
list *X = makeList(10);
list *Y = makeList (100);
int a;
void (*fp3)(list*);
scanf("%d", &a);
if (a%2 == 0)
fp3 = &addGToList;
else
fp3 = &subtractGToList;
(*fp3)(X);
}

===================

Output of calltarget-eqtd pass:
----------------------------------------
[* = incomplete] CS: func list
*   call void %0(i32* %Data)
do_all    call void %0(i32* %Data): addG addGToList subtractG subtractGToList
  call void %1(%struct.list* %2): addG addGToList subtractG subtractGToList


However, the correct output should be:
[* = incomplete] CS: func list
*   call void %0(i32* %Data)
do_all    call void %0(i32* %Data): addG subtractG
  call void %1(%struct.list* %2): addGToList subtractGToList


Could anyone please verify the result/ give a hint what I am missing?

Thanks.
-- 
Syed


More information about the llvm-dev mailing list