Skip to content

Commit 042dfc1

Browse files
author
bjjwwang
committed
update ass3
1 parent 15fd6a7 commit 042dfc1

File tree

3 files changed

+106
-90
lines changed

3 files changed

+106
-90
lines changed

.github/workflows/svf-teaching.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
matrix:
1111
os: [ubuntu-latest, macos-latest]
1212
env:
13-
XCODE_VERSION: '15.3.0'
13+
XCODE_VERSION: '16.0.0'
1414
steps:
1515
# checkout the repo
1616
- uses: actions/checkout@v2
Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
1-
extern void MAYALIAS(void* p, void* q);
2-
extern void NOALIAS(void* p, void* q);
3-
4-
typedef struct {
5-
int *ptr1;
6-
int value;
7-
int *ptr2;
8-
} MyStruct;
1+
/*
2+
* Cycle
3+
* Author: Sen Ye
4+
* Date: 11/10/2013
5+
*/
6+
extern void MAYALIAS(void*,void*);
97

108
int main() {
11-
int a = 10;
12-
int b = 20;
13-
MyStruct s1, s2;
14-
15-
s1.ptr1 = &a;
16-
s1.ptr2 = &a;
17-
s2.ptr1 = &b;
18-
s2.ptr2 = &a;
19-
20-
MAYALIAS(s1.ptr1, s1.ptr2);
21-
22-
MAYALIAS(s1.ptr2, s2.ptr2);
23-
24-
return 0;
25-
}
9+
int **x1, **y1, **z1;
10+
int *x2, *y2, *z2, *y2_;
11+
int x3, y3, z3, y3_;
12+
x2 = &x3, y2 = &y3, z2 = &z3;
13+
x1 = &x2, y1 = &y2, z1 = &z2;
14+
// if the following branch is commented out,
15+
// the first alias check will fail while
16+
// the second one is OK.
17+
if (y3_) {
18+
y1 = &y2_;
19+
y2_ = &y3_;
20+
}
21+
*x1 = *y1;
22+
*y1 = *z1;
23+
*z1 = *x1;
24+
// there should be a cycle from
25+
// y2 -> x2 -> z2 -> y2
26+
MAYALIAS(x2, y2);
27+
MAYALIAS(z2, x2);
28+
return 0;
29+
}
Lines changed: 78 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,58 @@
1-
; ModuleID = './test4.ll'
2-
source_filename = "./test4.c"
1+
; ModuleID = './test5.ll'
2+
source_filename = "./test5.c"
33
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
44
target triple = "arm64-apple-macosx14.0.0"
55

6-
%struct.MyStruct = type { ptr, i32, ptr }
7-
86
; Function Attrs: noinline nounwind ssp uwtable(sync)
97
define i32 @main() #0 !dbg !9 {
108
entry:
11-
%a = alloca i32, align 4
12-
%b = alloca i32, align 4
13-
%s1 = alloca %struct.MyStruct, align 8
14-
%s2 = alloca %struct.MyStruct, align 8
15-
call void @llvm.dbg.declare(metadata ptr %a, metadata !15, metadata !DIExpression()), !dbg !16
16-
store i32 10, ptr %a, align 4, !dbg !16
17-
call void @llvm.dbg.declare(metadata ptr %b, metadata !17, metadata !DIExpression()), !dbg !18
18-
store i32 20, ptr %b, align 4, !dbg !18
19-
call void @llvm.dbg.declare(metadata ptr %s1, metadata !19, metadata !DIExpression()), !dbg !27
20-
call void @llvm.dbg.declare(metadata ptr %s2, metadata !28, metadata !DIExpression()), !dbg !29
21-
%ptr1 = getelementptr inbounds %struct.MyStruct, ptr %s1, i32 0, i32 0, !dbg !30
22-
store ptr %a, ptr %ptr1, align 8, !dbg !31
23-
%ptr2 = getelementptr inbounds %struct.MyStruct, ptr %s1, i32 0, i32 2, !dbg !32
24-
store ptr %a, ptr %ptr2, align 8, !dbg !33
25-
%ptr11 = getelementptr inbounds %struct.MyStruct, ptr %s2, i32 0, i32 0, !dbg !34
26-
store ptr %b, ptr %ptr11, align 8, !dbg !35
27-
%ptr22 = getelementptr inbounds %struct.MyStruct, ptr %s2, i32 0, i32 2, !dbg !36
28-
store ptr %a, ptr %ptr22, align 8, !dbg !37
29-
%ptr13 = getelementptr inbounds %struct.MyStruct, ptr %s1, i32 0, i32 0, !dbg !38
30-
%0 = load ptr, ptr %ptr13, align 8, !dbg !38
31-
%ptr24 = getelementptr inbounds %struct.MyStruct, ptr %s1, i32 0, i32 2, !dbg !39
32-
%1 = load ptr, ptr %ptr24, align 8, !dbg !39
33-
call void @MAYALIAS(ptr noundef %0, ptr noundef %1), !dbg !40
34-
%ptr25 = getelementptr inbounds %struct.MyStruct, ptr %s1, i32 0, i32 2, !dbg !41
35-
%2 = load ptr, ptr %ptr25, align 8, !dbg !41
36-
%ptr26 = getelementptr inbounds %struct.MyStruct, ptr %s2, i32 0, i32 2, !dbg !42
37-
%3 = load ptr, ptr %ptr26, align 8, !dbg !42
38-
call void @MAYALIAS(ptr noundef %2, ptr noundef %3), !dbg !43
39-
ret i32 0, !dbg !44
9+
%y2 = alloca ptr, align 8
10+
%y2_ = alloca ptr, align 8
11+
%y3 = alloca i32, align 4
12+
%z3 = alloca i32, align 4
13+
%y3_ = alloca i32, align 4
14+
call void @llvm.dbg.declare(metadata ptr %y2, metadata !15, metadata !DIExpression()), !dbg !17
15+
call void @llvm.dbg.declare(metadata ptr %y2_, metadata !18, metadata !DIExpression()), !dbg !19
16+
call void @llvm.dbg.declare(metadata ptr undef, metadata !20, metadata !DIExpression()), !dbg !21
17+
call void @llvm.dbg.declare(metadata ptr %y3, metadata !22, metadata !DIExpression()), !dbg !23
18+
call void @llvm.dbg.declare(metadata ptr %z3, metadata !24, metadata !DIExpression()), !dbg !25
19+
call void @llvm.dbg.declare(metadata ptr %y3_, metadata !26, metadata !DIExpression()), !dbg !27
20+
call void @llvm.dbg.value(metadata ptr undef, metadata !28, metadata !DIExpression()), !dbg !29
21+
store ptr %y3, ptr %y2, align 8, !dbg !30
22+
call void @llvm.dbg.value(metadata ptr %z3, metadata !31, metadata !DIExpression()), !dbg !29
23+
call void @llvm.dbg.value(metadata ptr undef, metadata !32, metadata !DIExpression()), !dbg !29
24+
call void @llvm.dbg.value(metadata ptr %y2, metadata !34, metadata !DIExpression()), !dbg !29
25+
call void @llvm.dbg.value(metadata ptr undef, metadata !35, metadata !DIExpression()), !dbg !29
26+
%0 = load i32, ptr %y3_, align 4, !dbg !36
27+
%tobool = icmp ne i32 %0, 0, !dbg !36
28+
br i1 %tobool, label %if.then, label %if.end, !dbg !38
29+
30+
if.then: ; preds = %entry
31+
call void @llvm.dbg.value(metadata ptr %y2_, metadata !34, metadata !DIExpression()), !dbg !29
32+
store ptr %y3_, ptr %y2_, align 8, !dbg !39
33+
br label %if.end, !dbg !41
34+
35+
if.end: ; preds = %if.then, %entry
36+
%y1.0 = phi ptr [ %y2_, %if.then ], [ %y2, %entry ], !dbg !29
37+
call void @llvm.dbg.value(metadata ptr %y1.0, metadata !34, metadata !DIExpression()), !dbg !29
38+
%1 = load ptr, ptr %y1.0, align 8, !dbg !42
39+
call void @llvm.dbg.value(metadata ptr %1, metadata !28, metadata !DIExpression()), !dbg !29
40+
store ptr %z3, ptr %y1.0, align 8, !dbg !43
41+
call void @llvm.dbg.value(metadata ptr %1, metadata !31, metadata !DIExpression()), !dbg !29
42+
%2 = load ptr, ptr %y2, align 8, !dbg !44
43+
call void @MAYALIAS(ptr noundef %1, ptr noundef %2), !dbg !45
44+
call void @MAYALIAS(ptr noundef %1, ptr noundef %1), !dbg !46
45+
ret i32 0, !dbg !47
4046
}
4147

4248
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
4349
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
4450

4551
declare void @MAYALIAS(ptr noundef, ptr noundef) #2
4652

53+
; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
54+
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
55+
4756
attributes #0 = { noinline nounwind ssp uwtable(sync) "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+crc,+crypto,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+zcm,+zcz" }
4857
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
4958
attributes #2 = { "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="apple-m1" "target-features"="+aes,+crc,+crypto,+dotprod,+fp-armv8,+fp16fml,+fullfp16,+lse,+neon,+ras,+rcpc,+rdm,+sha2,+sha3,+sm4,+v8.1a,+v8.2a,+v8.3a,+v8.4a,+v8.5a,+v8a,+zcm,+zcz" }
@@ -53,47 +62,50 @@ attributes #2 = { "frame-pointer"="non-leaf" "no-trapping-math"="true" "stack-pr
5362
!llvm.ident = !{!8}
5463

5564
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "Homebrew clang version 16.0.6", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None, sysroot: "/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk", sdk: "MacOSX14.sdk")
56-
!1 = !DIFile(filename: "test4.c", directory: "/Users/z5489735/2023/0522/Software-Security-Analysis/Assignment-1/Tests/testcases/pta")
65+
!1 = !DIFile(filename: "test5.c", directory: "/Users/z5489735/2023/0522/Software-Security-Analysis/Assignment-1/Tests/testcases/pta")
5766
!2 = !{i32 7, !"Dwarf Version", i32 4}
5867
!3 = !{i32 2, !"Debug Info Version", i32 3}
5968
!4 = !{i32 1, !"wchar_size", i32 4}
6069
!5 = !{i32 8, !"PIC Level", i32 2}
6170
!6 = !{i32 7, !"uwtable", i32 1}
6271
!7 = !{i32 7, !"frame-pointer", i32 1}
6372
!8 = !{!"Homebrew clang version 16.0.6"}
64-
!9 = distinct !DISubprogram(name: "main", scope: !10, file: !10, line: 10, type: !11, scopeLine: 10, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
65-
!10 = !DIFile(filename: "./test4.c", directory: "/Users/z5489735/2023/0522/Software-Security-Analysis/Assignment-1/Tests/testcases/pta")
73+
!9 = distinct !DISubprogram(name: "main", scope: !10, file: !10, line: 8, type: !11, scopeLine: 8, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !14)
74+
!10 = !DIFile(filename: "./test5.c", directory: "/Users/z5489735/2023/0522/Software-Security-Analysis/Assignment-1/Tests/testcases/pta")
6675
!11 = !DISubroutineType(types: !12)
6776
!12 = !{!13}
6877
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
6978
!14 = !{}
70-
!15 = !DILocalVariable(name: "a", scope: !9, file: !10, line: 11, type: !13)
71-
!16 = !DILocation(line: 11, column: 9, scope: !9)
72-
!17 = !DILocalVariable(name: "b", scope: !9, file: !10, line: 12, type: !13)
73-
!18 = !DILocation(line: 12, column: 9, scope: !9)
74-
!19 = !DILocalVariable(name: "s1", scope: !9, file: !10, line: 13, type: !20)
75-
!20 = !DIDerivedType(tag: DW_TAG_typedef, name: "MyStruct", file: !10, line: 8, baseType: !21)
76-
!21 = distinct !DICompositeType(tag: DW_TAG_structure_type, file: !10, line: 4, size: 192, elements: !22)
77-
!22 = !{!23, !25, !26}
78-
!23 = !DIDerivedType(tag: DW_TAG_member, name: "ptr1", scope: !21, file: !10, line: 5, baseType: !24, size: 64)
79-
!24 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
80-
!25 = !DIDerivedType(tag: DW_TAG_member, name: "value", scope: !21, file: !10, line: 6, baseType: !13, size: 32, offset: 64)
81-
!26 = !DIDerivedType(tag: DW_TAG_member, name: "ptr2", scope: !21, file: !10, line: 7, baseType: !24, size: 64, offset: 128)
82-
!27 = !DILocation(line: 13, column: 14, scope: !9)
83-
!28 = !DILocalVariable(name: "s2", scope: !9, file: !10, line: 13, type: !20)
84-
!29 = !DILocation(line: 13, column: 18, scope: !9)
85-
!30 = !DILocation(line: 15, column: 8, scope: !9)
86-
!31 = !DILocation(line: 15, column: 13, scope: !9)
87-
!32 = !DILocation(line: 16, column: 8, scope: !9)
88-
!33 = !DILocation(line: 16, column: 13, scope: !9)
89-
!34 = !DILocation(line: 17, column: 8, scope: !9)
90-
!35 = !DILocation(line: 17, column: 13, scope: !9)
91-
!36 = !DILocation(line: 18, column: 8, scope: !9)
92-
!37 = !DILocation(line: 18, column: 13, scope: !9)
93-
!38 = !DILocation(line: 20, column: 17, scope: !9)
94-
!39 = !DILocation(line: 20, column: 26, scope: !9)
95-
!40 = !DILocation(line: 20, column: 5, scope: !9)
96-
!41 = !DILocation(line: 22, column: 17, scope: !9)
97-
!42 = !DILocation(line: 22, column: 26, scope: !9)
98-
!43 = !DILocation(line: 22, column: 5, scope: !9)
99-
!44 = !DILocation(line: 24, column: 5, scope: !9)
79+
!15 = !DILocalVariable(name: "y2", scope: !9, file: !10, line: 10, type: !16)
80+
!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
81+
!17 = !DILocation(line: 10, column: 12, scope: !9)
82+
!18 = !DILocalVariable(name: "y2_", scope: !9, file: !10, line: 10, type: !16)
83+
!19 = !DILocation(line: 10, column: 22, scope: !9)
84+
!20 = !DILocalVariable(name: "x3", scope: !9, file: !10, line: 11, type: !13)
85+
!21 = !DILocation(line: 11, column: 6, scope: !9)
86+
!22 = !DILocalVariable(name: "y3", scope: !9, file: !10, line: 11, type: !13)
87+
!23 = !DILocation(line: 11, column: 10, scope: !9)
88+
!24 = !DILocalVariable(name: "z3", scope: !9, file: !10, line: 11, type: !13)
89+
!25 = !DILocation(line: 11, column: 14, scope: !9)
90+
!26 = !DILocalVariable(name: "y3_", scope: !9, file: !10, line: 11, type: !13)
91+
!27 = !DILocation(line: 11, column: 18, scope: !9)
92+
!28 = !DILocalVariable(name: "x2", scope: !9, file: !10, line: 10, type: !16)
93+
!29 = !DILocation(line: 0, scope: !9)
94+
!30 = !DILocation(line: 12, column: 15, scope: !9)
95+
!31 = !DILocalVariable(name: "z2", scope: !9, file: !10, line: 10, type: !16)
96+
!32 = !DILocalVariable(name: "x1", scope: !9, file: !10, line: 9, type: !33)
97+
!33 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !16, size: 64)
98+
!34 = !DILocalVariable(name: "y1", scope: !9, file: !10, line: 9, type: !33)
99+
!35 = !DILocalVariable(name: "z1", scope: !9, file: !10, line: 9, type: !33)
100+
!36 = !DILocation(line: 17, column: 6, scope: !37)
101+
!37 = distinct !DILexicalBlock(scope: !9, file: !10, line: 17, column: 6)
102+
!38 = !DILocation(line: 17, column: 6, scope: !9)
103+
!39 = !DILocation(line: 19, column: 7, scope: !40)
104+
!40 = distinct !DILexicalBlock(scope: !37, file: !10, line: 17, column: 11)
105+
!41 = !DILocation(line: 20, column: 2, scope: !40)
106+
!42 = !DILocation(line: 21, column: 8, scope: !9)
107+
!43 = !DILocation(line: 22, column: 6, scope: !9)
108+
!44 = !DILocation(line: 26, column: 15, scope: !9)
109+
!45 = !DILocation(line: 26, column: 2, scope: !9)
110+
!46 = !DILocation(line: 27, column: 2, scope: !9)
111+
!47 = !DILocation(line: 28, column: 2, scope: !9)

0 commit comments

Comments
 (0)