[poolalloc] r238057 - Add callgraph tests for behavior when main is addr-taken or not.

Will Dietz wdietz2 at illinois.edu
Fri May 22 14:54:42 PDT 2015


Author: wdietz2
Date: Fri May 22 16:54:42 2015
New Revision: 238057

URL: http://llvm.org/viewvc/llvm-project?rev=238057&view=rev
Log:
Add callgraph tests for behavior when main is addr-taken or not.

The two tests have almost identical IR, except DSA correctly
reports callgraph for one but not the other.

The issue is related to DSA behavior when main is addr-taken
(addrtaken_main); the correct callgraph is reported when
'main' is renamed to 'main2' and invoked from a new simple
wrapper 'main' (addrtaken_caller).

Tests derived from example submitted by Victor van der Veen.
(Thanks!)


Added:
    poolalloc/trunk/test/dsa/callgraph/addrtaken_caller.ll
    poolalloc/trunk/test/dsa/callgraph/addrtaken_main.ll

Added: poolalloc/trunk/test/dsa/callgraph/addrtaken_caller.ll
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/test/dsa/callgraph/addrtaken_caller.ll?rev=238057&view=auto
==============================================================================
--- poolalloc/trunk/test/dsa/callgraph/addrtaken_caller.ll (added)
+++ poolalloc/trunk/test/dsa/callgraph/addrtaken_caller.ll Fri May 22 16:54:42 2015
@@ -0,0 +1,49 @@
+;RUN: dsaopt %s -dsa-td -analyze -check-callees=run_func,f1
+;RUN: dsaopt %s -dsa-td -analyze -check-not-callees=run_func,main
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .str = private unnamed_addr constant [10 x i8] c"Main: %p\0A\00", align 1
+ at .str1 = private unnamed_addr constant [10 x i8] c"Sum:  %d\0A\00", align 1
+
+; Function Attrs: nounwind uwtable
+define internal i32 @main(i32 %argc, i8** %argv) #0 {
+entry:
+	%call = call i32 @main2(i32 %argc, i8** %argv)
+	ret i32 %call
+}
+
+define internal i32 @main2(i32 %argc, i8** %argv) #0 {
+entry:
+  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i32 (i32, i8**)* @main2)
+  %call1 = call i32 @foo()
+  %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str1, i32 0, i32 0), i32 %call1)
+  ret i32 0
+}
+
+declare i32 @printf(i8*, ...)
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @foo() #1 {
+entry:
+  %call = call i32 @run_func(i32 (i32, i32)* @f1, i32 1, i32 2)
+  ret i32 %call
+}
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @run_func(i32 (i32, i32)* %fptr, i32 %arg1, i32 %arg2) #1 {
+entry:
+  %call = call i32 %fptr(i32 %arg1, i32 %arg2)
+  ret i32 %call
+}
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @f1(i32 %arg1, i32 %arg2) #1 {
+entry:
+  %add = add nsw i32 %arg1, %arg2
+  ret i32 %add
+}
+
+attributes #0 = { nounwind uwtable }
+attributes #1 = { noinline nounwind uwtable }

Added: poolalloc/trunk/test/dsa/callgraph/addrtaken_main.ll
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/test/dsa/callgraph/addrtaken_main.ll?rev=238057&view=auto
==============================================================================
--- poolalloc/trunk/test/dsa/callgraph/addrtaken_main.ll (added)
+++ poolalloc/trunk/test/dsa/callgraph/addrtaken_main.ll Fri May 22 16:54:42 2015
@@ -0,0 +1,45 @@
+;RUN: dsaopt %s -dsa-td -analyze -check-callees=run_func,f1
+;RUN: dsaopt %s -dsa-td -analyze -check-not-callees=run_func,main
+; Bad things happen when main is externally reachable.
+;XFAIL: *
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at .str = private unnamed_addr constant [10 x i8] c"Main: %p\0A\00", align 1
+ at .str1 = private unnamed_addr constant [10 x i8] c"Sum:  %d\0A\00", align 1
+
+; Function Attrs: nounwind uwtable
+define internal i32 @main(i32 %argc, i8** %argv) #0 {
+entry:
+  %call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i32 0, i32 0), i32 (i32, i8**)* @main)
+  %call1 = call i32 @foo()
+  %call2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str1, i32 0, i32 0), i32 %call1)
+  ret i32 0
+}
+
+declare i32 @printf(i8*, ...)
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @foo() #1 {
+entry:
+  %call = call i32 @run_func(i32 (i32, i32)* @f1, i32 1, i32 2)
+  ret i32 %call
+}
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @run_func(i32 (i32, i32)* %fptr, i32 %arg1, i32 %arg2) #1 {
+entry:
+  %call = call i32 %fptr(i32 %arg1, i32 %arg2)
+  ret i32 %call
+}
+
+; Function Attrs: noinline nounwind uwtable
+define internal i32 @f1(i32 %arg1, i32 %arg2) #1 {
+entry:
+  %add = add nsw i32 %arg1, %arg2
+  ret i32 %add
+}
+
+attributes #0 = { nounwind uwtable }
+attributes #1 = { noinline nounwind uwtable }





More information about the llvm-commits mailing list