[LLVMdev] alias analysis and functions
dan mihai
dnmh68 at hotmail.com
Thu Oct 1 18:58:23 PDT 2009
Hi,
I am trying to use alias analysis (Anderson) and noticed that for pointers to functions
I don't get the expected result: a pointer that clearly may point to a function is
reported as NoAlias.
I use -anders-aa -aa-eval -print-no-aliases -print-may-aliases -print-must-aliases
Here is a test case:
///////////////try_calls_aliases.c
#include <stdio.h>
typedef int (*PF)();
PF pf01=0;
PF pf2=0;
int pointed_to_function0() {
printf("pointed_to_function0\n");
return 1;
}
int pointed_to_function1() {
pf01 = pointed_to_function1;
printf("pointed_to_function1\n");
return 1;
}
void ptr_function_caller(PF pf) {
printf("ptr_function_caller\n");
pf();
PF lpf0 = pointed_to_function0;
PF lpf1 = pointed_to_function1;
}
int main(int argc, char* argv[]) {
ptr_function_caller(pointed_to_function0);
return 0;
}
-------------
After
llvmgcc -emit-llvm try_calls_aliases.c -c -o try_calls_aliases.bc
opt 2>&1 -anders-aa -aa-eval -print-no-aliases -print-may-aliases -print-must-aliases try_calls_aliases.bc | egrep -e 'Alias|Function' > c
I get:
...........
Function: ptr_function_caller: 8 pointers, 2 call sites
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*), i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*)
NoAlias: i32 (...)* %pf, i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*) ???????????????????????????????????????????????????????????????????????????????
NoAlias: i32 (...)* %pf, i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*)
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*), i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*), i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)* %pf, i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*), i32 (...)** %pf_addr
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*), i32 (...)** %pf_addr
NoAlias: i32 (...)* %pf, i32 (...)** %pf_addr
NoAlias: i32 (...)** %pf_addr, i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*), i32 (...)** %lpf1
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*), i32 (...)** %lpf1
NoAlias: i32 (...)* %pf, i32 (...)** %lpf1
NoAlias: i32 (...)** %lpf1, i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)** %lpf1, i32 (...)** %pf_addr
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*), i32 (...)** %lpf0
NoAlias: i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*), i32 (...)** %lpf0
NoAlias: i32 (...)* %pf, i32 (...)** %lpf0
NoAlias: i32 (...)** %lpf0, i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)** %lpf0, i32 (...)** %pf_addr
NoAlias: i32 (...)** %lpf0, i32 (...)** %lpf1
NoAlias: i32 (...)* %1, i32 (...)* bitcast (i32 ()* @pointed_to_function0 to i32 (...)*)
NoAlias: i32 (...)* %1, i32 (...)* bitcast (i32 ()* @pointed_to_function1 to i32 (...)*)
MayAlias: i32 (...)* %1, i32 (...)* %pf
NoAlias: i32 (...)* %1, i8* getelementptr ([20 x i8]* @.str2, i32 0, i64 0)
NoAlias: i32 (...)* %1, i32 (...)** %pf_addr
NoAlias: i32 (...)* %1, i32 (...)** %lpf1
NoAlias: i32 (...)* %1, i32 (...)** %lpf0
...............
Any advice on how to get this work as expected? (that is pf MayAlias pointed_to_function0 inside ptr_function_caller, etc)?
Thank you,
Dan
_________________________________________________________________
Insert movie times and more without leaving HotmailĀ®.
http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGLM_WL_HM_Tutorial_QuickAdd_062009
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20091002/8b25c086/attachment.html>
More information about the llvm-dev
mailing list