1 //! extra-files = ['dwarf_generic_satellite.cc']
2 
3 // clang-format off
4 // clang -o generic.wasm -target wasm32-unknown-wasip1 -g generic.cpp generic-satellite.cpp
5 // clang-format on
6 //
7 #include "dwarf_generic.h"
8 
9 int SomeClass::MainDefinedFunction() {
10   int x = HIDE_FROM_CHECKER(1);
11   debug_break();
12   int y = SatelliteFunction(x);
13   return x + y;
14 }
15 
16 int TestClassDefinitionSpreadAcrossCompileUnits() {
17   int result = SomeClass::MainDefinedFunction();
18   return result != 3 ? 1 : 0;
19 }
20 
21 struct BaseType {
22   int BaseValue = 1;
23 };
24 struct DerivedType : BaseType {
25   long long DerivedValue = 2;
26 
27   int InstanceMethod() {
28     debug_break();
29     return BaseValue + DerivedValue;
30   }
31 
32   int ConstInstanceMethod() const {
33     debug_break();
34     return BaseValue + DerivedValue;
35   }
36 };
37 
38 int TestInheritance() {
39   DerivedType inst;
40   debug_break();
41   return inst.BaseValue + inst.DerivedValue != 3 ? 1 : 0;
42 }
43 
44 int TestInstanceMethod() {
45   debug_break();
46 
47   DerivedType inst;
48   inst.BaseValue = 2;
49   inst.DerivedValue = 4;
50   if (inst.InstanceMethod() != 6)
51     return 1;
52 
53   inst.BaseValue++;
54   volatile DerivedType volatileInst = inst;
55   if (inst.InstanceMethod() != 7)
56     return 2;
57 
58   inst.DerivedValue++;
59   const DerivedType constInst = inst;
60   if (inst.ConstInstanceMethod() != 8)
61     return 3;
62 
63   return 0;
64 }
65 
66 __asm("FunctionWithoutWasmDWARF:\n"
67       ".global	FunctionWithoutWasmDWARF\n"
68       ".functype	FunctionWithoutWasmDWARF (i32, i32) -> (i32)\n"
69       "local.get	0\n"
70       "local.get	1\n"
71       "i32.div_u\n"
72       "end_function\n");
73 extern "C" int FunctionWithoutWasmDWARF(int a, int b);
74 
75 int TestFunctionWithoutWasmDWARF() {
76   debug_break();
77   int x = FunctionWithoutWasmDWARF(9, 10);
78   return x == 0 ? 0 : 4;
79 }
80 
81 int main() {
82   int exitCode = 0;
83   exitCode += TestClassDefinitionSpreadAcrossCompileUnits();
84   exitCode += TestInheritance();
85   exitCode += TestInstanceMethod();
86   exitCode += TestFunctionWithoutWasmDWARF();
87   return exitCode;
88 }
89