Debian Codegraph @

js/src/devtools/rootAnalysis/t/virtual/test.py

raw
1 # 'test' is provided by the calling script.
2 # flake8: noqa: F821
3
4 test.compile("source.cpp")
5 test.run_analysis_script("gcTypes")
6
7 info = test.load_typeInfo()
8
9 assert "Sub1" in info["OtherCSUTags"]
10 assert ["CSU1", "CSU2"] == sorted(info["OtherCSUTags"]["Sub1"])
11 assert "Base" in info["OtherFieldTags"]
12 assert "someGC" in info["OtherFieldTags"]["Base"]
13 assert "Sub1" in info["OtherFieldTags"]
14 assert "someGC" in info["OtherFieldTags"]["Sub1"]
15
16 # For now, fields with the same name (eg overloaded virtual methods) just
17 # accumulate attributes.
18 assert ["Sub1 override", "Sub1 override for int overload", "second attr"] == sorted(
19 info["OtherFieldTags"]["Sub1"]["someGC"]
20 )
21
22 gcFunctions = test.load_gcFunctions()
23
24 assert "void Sub1::noneGC()" not in gcFunctions
25 assert "void Sub1::someGC()" not in gcFunctions
26 assert "void Sub1::someGC(int32)" not in gcFunctions
27 assert "void Sub1::allGC()" in gcFunctions
28 assert "void Sub2::noneGC()" not in gcFunctions
29 assert "void Sub2::someGC()" in gcFunctions
30 assert "void Sub2::someGC(int32)" in gcFunctions
31 assert "void Sub2::allGC()" in gcFunctions
32
33 callgraph = test.load_callgraph()
34
35 assert callgraph.calleeGraph["void f()"]["Super.noneGC:0"]
36 assert callgraph.calleeGraph["Super.noneGC:0"]["Sub1.noneGC:0"]
37 assert callgraph.calleeGraph["Super.noneGC:0"]["Sub2.noneGC:0"]
38 assert callgraph.calleeGraph["Sub1.noneGC:0"]["void Sub1::noneGC()"]
39 assert callgraph.calleeGraph["Sub2.noneGC:0"]["void Sub2::noneGC()"]
40 assert "void Sibling::noneGC()" not in callgraph.calleeGraph["Super.noneGC:0"]
41 assert callgraph.calleeGraph["Super.onBase:0"]["Sub1.onBase:0"]
42 assert callgraph.calleeGraph["Sub1.onBase:0"]["void Sub1::onBase()"]
43 assert callgraph.calleeGraph["Super.onBase:0"]["void Base::onBase()"]
44 assert "void Sibling::onBase()" not in callgraph.calleeGraph["Super.onBase:0"]
45
46 hazards = test.load_hazards()
47 hazmap = {haz.variable: haz for haz in hazards}
48
49 assert "c1" not in hazmap
50 assert "c2" in hazmap
51 assert "c3" in hazmap
52 assert "c4" not in hazmap
53 assert "c5" in hazmap
54 assert "c6" in hazmap
55 assert "c7" not in hazmap
56 assert "c8" in hazmap
57 assert "c9" in hazmap
58 assert "c10" in hazmap
59 assert "c11" in hazmap
60
61 # Virtual resolution should take the static type into account: the only method
62 # implementations considered should be those of descendants, even if the
63 # virtual method is inherited and not overridden in the static class. (Base
64 # defines sibGC() as pure virtual, Super inherits it without overriding,
65 # Sibling and Sub2 both implement it.)
66
67 # Call Base.sibGC on a Super pointer: can only call Sub2.sibGC(), which does not GC.
68 # In particular, PEdgeCallInstance.Exp.Field.FieldCSU.Type = {Kind: "CSU", Name="Super"}
69 assert "c12" not in hazmap
70 # Call Base.sibGC on a Base pointer; can call Sibling.sibGC(), which GCs.
71 assert "c13" in hazmap
72
73 # Call nsISupports.danger() which is annotated to be overridable and hence can GC.
74 assert "c14" in hazmap
75
76 # someGC(int) overload
77 assert "c16" in hazmap
78 assert "c17" in hazmap
79
80 # Super.onBase() could call the GC'ing Base::onBase().
81 assert "c15" in hazmap
82
83 # virtual ~nsJSPrincipals calls ~JSPrincipals calls GC.
84 assert "c18" in hazmap
85 assert "c19" in hazmap
86
87 # ~SafePrincipals does not GC.
88 assert "c20" not in hazmap
89
90 # ...but when cast to a nsISupports*, the compiler can't tell that it won't.
91 assert "c21" in hazmap
92
93 # Function pointers! References to function pointers! Created by reference-capturing lambdas!
94 assert "c22" in hazmap
95 assert "c23" in hazmap
96 assert "c24" in hazmap
97 assert "c25" not in hazmap
98 assert "c26" not in hazmap
99 assert "c27" not in hazmap