GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 92.7% 166 / 0 / 179
Functions: 93.1% 27 / 0 / 29
Branches: 47.2% 168 / 0 / 356

src/irgenerator/StdFunctionManager.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "StdFunctionManager.h"
4
5 #include <SourceFile.h>
6 #include <driver/Driver.h>
7 #include <global/GlobalResourceManager.h>
8 #include <irgenerator/IRGenerator.h>
9 #include <irgenerator/NameMangling.h>
10 #include <model/Function.h>
11
12 #include <llvm/IR/Module.h>
13
14 namespace spice::compiler {
15
16 5016 StdFunctionManager::StdFunctionManager(SourceFile *sourceFile, GlobalResourceManager &resourceManager, llvm::Module *module,
17 const IRGenerator *irGenerator)
18
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 4 taken 5012 times.
5016 : context(resourceManager.cliOptions.useLTO ? resourceManager.ltoContext : sourceFile->context), builder(sourceFile->builder),
19 5016 module(module), irGenerator(irGenerator) {}
20
21 2975 llvm::Function *StdFunctionManager::getPrintfFct() const {
22
3/6
✓ Branch 2 → 3 taken 2975 times.
✗ Branch 2 → 17 not taken.
✓ Branch 4 → 5 taken 2975 times.
✗ Branch 4 → 17 not taken.
✓ Branch 5 → 6 taken 2975 times.
✗ Branch 5 → 17 not taken.
2975 llvm::Function *printfFct = getFunction("printf", builder.getInt32Ty(), builder.getPtrTy(), true);
23 // Set attributes
24 2975 printfFct->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Local);
25 2975 printfFct->addFnAttr(llvm::Attribute::NoFree);
26 2975 printfFct->addFnAttr(llvm::Attribute::NoUnwind);
27 2975 printfFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
28 2975 printfFct->addParamAttr(0, llvm::Attribute::NoUndef);
29 2975 printfFct->addParamAttr(0, llvm::Attribute::ReadOnly);
30 2975 printfFct->addRetAttr(llvm::Attribute::NoUndef);
31 2975 return printfFct;
32 }
33
34 12059 llvm::Function *StdFunctionManager::getFPrintfFct() const {
35
4/8
✓ Branch 2 → 3 taken 12060 times.
✗ Branch 2 → 21 not taken.
✓ Branch 3 → 4 taken 12059 times.
✗ Branch 3 → 21 not taken.
✓ Branch 5 → 6 taken 12059 times.
✗ Branch 5 → 21 not taken.
✓ Branch 6 → 7 taken 12060 times.
✗ Branch 6 → 21 not taken.
12059 llvm::Function *fprintfFct = getFunction("fprintf", builder.getInt32Ty(), {builder.getPtrTy(), builder.getPtrTy()}, true);
36 // Set attributes
37 12060 fprintfFct->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Local);
38 12060 fprintfFct->addFnAttr(llvm::Attribute::NoFree);
39 12060 fprintfFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
40 12060 fprintfFct->addParamAttr(0, llvm::Attribute::NoUndef);
41 12060 fprintfFct->addParamAttr(1, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
42 12060 fprintfFct->addParamAttr(1, llvm::Attribute::NoUndef);
43 12060 fprintfFct->addParamAttr(1, llvm::Attribute::ReadOnly);
44 12060 fprintfFct->addRetAttr(llvm::Attribute::NoUndef);
45 12059 return fprintfFct;
46 }
47
48 12060 llvm::Function *StdFunctionManager::getExitFct() const {
49
2/4
✓ Branch 2 → 3 taken 12060 times.
✗ Branch 2 → 10 not taken.
✓ Branch 4 → 5 taken 12060 times.
✗ Branch 4 → 10 not taken.
12060 llvm::Function *exitFct = getProcedure("exit", builder.getInt32Ty());
50 // Set attributes
51 12060 exitFct->addFnAttr(llvm::Attribute::Cold);
52 12060 exitFct->addFnAttr(llvm::Attribute::NoReturn);
53 12060 exitFct->addFnAttr(llvm::Attribute::NoUnwind);
54 12060 return exitFct;
55 }
56
57 ✗ llvm::Function *StdFunctionManager::getFreeFct() const {
58 ✗ llvm::Function *freeFct = getProcedure("free", builder.getPtrTy());
59 // Set attributes
60 ✗ freeFct->addFnAttr(llvm::Attribute::NoUnwind);
61 ✗ freeFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
62 ✗ freeFct->addParamAttr(0, llvm::Attribute::NoUndef);
63 ✗ freeFct->addParamAttr(0, llvm::Attribute::ReadOnly);
64 ✗ return freeFct;
65 }
66
67 112 llvm::Function *StdFunctionManager::getMemcmpFct() const {
68 112 llvm::Type *ptrTy = builder.getPtrTy();
69
3/6
✓ Branch 3 → 4 taken 112 times.
✗ Branch 3 → 22 not taken.
✓ Branch 5 → 6 taken 112 times.
✗ Branch 5 → 22 not taken.
✓ Branch 6 → 7 taken 112 times.
✗ Branch 6 → 22 not taken.
112 llvm::Function *memcmpFct = getFunction("memcmp", builder.getInt32Ty(), {ptrTy, ptrTy, builder.getInt64Ty()});
70 // Set attributes
71 112 memcmpFct->addFnAttr(llvm::Attribute::NoUnwind);
72 112 memcmpFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
73 112 memcmpFct->addParamAttr(0, llvm::Attribute::NoUndef);
74 112 memcmpFct->addParamAttr(0, llvm::Attribute::ReadOnly);
75 112 memcmpFct->addParamAttr(1, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
76 112 memcmpFct->addParamAttr(1, llvm::Attribute::NoUndef);
77 112 memcmpFct->addParamAttr(1, llvm::Attribute::ReadOnly);
78 112 memcmpFct->addParamAttr(2, llvm::Attribute::NoUndef);
79 112 memcmpFct->addRetAttr(llvm::Attribute::NoUndef);
80 112 return memcmpFct;
81 }
82
83 3205 llvm::Function *StdFunctionManager::getMemcpyIntrinsic() const {
84 3205 llvm::Type *ptrTy = builder.getPtrTy();
85
3/6
✓ Branch 3 → 4 taken 3205 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 3205 times.
✗ Branch 4 → 13 not taken.
✓ Branch 6 → 7 taken 3205 times.
✗ Branch 6 → 13 not taken.
3205 llvm::Function *memcpyFct = getProcedure("llvm.memcpy.p0.p0.i64", {ptrTy, ptrTy, builder.getInt64Ty(), builder.getInt1Ty()});
86 // Set attributes
87 3205 memcpyFct->addFnAttr(llvm::Attribute::NoCallback);
88 3205 memcpyFct->addFnAttr(llvm::Attribute::NoFree);
89 3205 memcpyFct->addFnAttr(llvm::Attribute::NoUnwind);
90 3205 memcpyFct->addFnAttr(llvm::Attribute::WillReturn);
91 3205 return memcpyFct;
92 }
93
94 144 llvm::Function *StdFunctionManager::getStringGetRawLengthStringFct() const {
95
2/4
✓ Branch 2 → 3 taken 144 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 144 times.
✗ Branch 5 → 31 not taken.
288 const ParamList paramLst = {{QualType(TY_STRING), false}};
96
5/10
✓ Branch 8 → 9 taken 144 times.
✗ Branch 8 → 45 not taken.
✓ Branch 9 → 10 taken 144 times.
✗ Branch 9 → 42 not taken.
✓ Branch 10 → 11 taken 144 times.
✗ Branch 10 → 41 not taken.
✓ Branch 13 → 14 taken 144 times.
✗ Branch 13 → 37 not taken.
✓ Branch 14 → 15 taken 144 times.
✗ Branch 14 → 35 not taken.
432 const Function function("getRawLength", nullptr, QualType(TY_DYN), QualType(TY_LONG), paramLst, {}, nullptr);
97
1/2
✓ Branch 19 → 20 taken 144 times.
✗ Branch 19 → 53 not taken.
144 const std::string mangledName = NameMangling::mangleFunction(function);
98
3/6
✓ Branch 20 → 21 taken 144 times.
✗ Branch 20 → 49 not taken.
✓ Branch 22 → 23 taken 144 times.
✗ Branch 22 → 49 not taken.
✓ Branch 24 → 25 taken 144 times.
✗ Branch 24 → 49 not taken.
288 return getFunction(mangledName.c_str(), builder.getInt64Ty(), {builder.getPtrTy()});
99 144 }
100
101 834 llvm::Function *StdFunctionManager::getStringIsRawEqualStringStringFct() const {
102
3/6
✓ Branch 2 → 3 taken 834 times.
✗ Branch 2 → 36 not taken.
✓ Branch 3 → 4 taken 834 times.
✗ Branch 3 → 36 not taken.
✓ Branch 6 → 7 taken 834 times.
✗ Branch 6 → 33 not taken.
1668 const ParamList paramLst = {{QualType(TY_STRING), false}, {QualType(TY_STRING), false}};
103
5/10
✓ Branch 9 → 10 taken 834 times.
✗ Branch 9 → 47 not taken.
✓ Branch 10 → 11 taken 834 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 834 times.
✗ Branch 11 → 43 not taken.
✓ Branch 14 → 15 taken 834 times.
✗ Branch 14 → 39 not taken.
✓ Branch 15 → 16 taken 834 times.
✗ Branch 15 → 37 not taken.
2502 const Function function("isRawEqual", nullptr, QualType(TY_DYN), QualType(TY_BOOL), paramLst, {}, nullptr);
104
1/2
✓ Branch 20 → 21 taken 834 times.
✗ Branch 20 → 55 not taken.
834 const std::string mangledName = NameMangling::mangleFunction(function);
105
4/8
✓ Branch 21 → 22 taken 834 times.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 834 times.
✗ Branch 22 → 51 not taken.
✓ Branch 24 → 25 taken 834 times.
✗ Branch 24 → 51 not taken.
✓ Branch 26 → 27 taken 834 times.
✗ Branch 26 → 51 not taken.
1668 return getFunction(mangledName.c_str(), builder.getInt1Ty(), {builder.getPtrTy(), builder.getPtrTy()});
106 834 }
107
108 497 llvm::Function *StdFunctionManager::getAllocUnsafeLongFct() const {
109
1/2
✓ Branch 2 → 3 taken 497 times.
✗ Branch 2 → 60 not taken.
497 QualType unsignedLong(TY_LONG);
110
1/2
✓ Branch 3 → 4 taken 497 times.
✗ Branch 3 → 60 not taken.
497 unsignedLong.makeUnsigned();
111
1/2
✓ Branch 6 → 7 taken 497 times.
✗ Branch 6 → 33 not taken.
994 const ParamList paramLst = {{unsignedLong, false}};
112
6/12
✓ Branch 9 → 10 taken 497 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 497 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 497 times.
✗ Branch 11 → 44 not taken.
✓ Branch 12 → 13 taken 497 times.
✗ Branch 12 → 43 not taken.
✓ Branch 15 → 16 taken 497 times.
✗ Branch 15 → 39 not taken.
✓ Branch 16 → 17 taken 497 times.
✗ Branch 16 → 37 not taken.
1491 const Function function("sAllocUnsafe", nullptr, QualType(TY_DYN), QualType(TY_BYTE).toPtr(nullptr), paramLst, {}, nullptr);
113
1/2
✓ Branch 21 → 22 taken 497 times.
✗ Branch 21 → 56 not taken.
497 const std::string mangledName = NameMangling::mangleFunction(function);
114
3/6
✓ Branch 22 → 23 taken 497 times.
✗ Branch 22 → 52 not taken.
✓ Branch 24 → 25 taken 497 times.
✗ Branch 24 → 52 not taken.
✓ Branch 26 → 27 taken 497 times.
✗ Branch 26 → 52 not taken.
994 return getFunction(mangledName.c_str(), builder.getPtrTy(), {builder.getInt64Ty()});
115 497 }
116
117 516 llvm::Function *StdFunctionManager::getDeallocBytePtrRefFct() const {
118
2/4
✓ Branch 2 → 3 taken 516 times.
✗ Branch 2 → 33 not taken.
✓ Branch 3 → 4 taken 516 times.
✗ Branch 3 → 33 not taken.
516 QualType heapBytePtrType = QualType(TY_BYTE).toPtr(nullptr);
119
1/2
✓ Branch 4 → 5 taken 516 times.
✗ Branch 4 → 60 not taken.
516 heapBytePtrType.makeHeap();
120
2/4
✓ Branch 5 → 6 taken 516 times.
✗ Branch 5 → 37 not taken.
✓ Branch 8 → 9 taken 516 times.
✗ Branch 8 → 34 not taken.
1032 const ParamList paramLst = {{heapBytePtrType.toRef(nullptr), false}};
121
5/10
✓ Branch 11 → 12 taken 516 times.
✗ Branch 11 → 48 not taken.
✓ Branch 12 → 13 taken 516 times.
✗ Branch 12 → 45 not taken.
✓ Branch 13 → 14 taken 516 times.
✗ Branch 13 → 44 not taken.
✓ Branch 16 → 17 taken 516 times.
✗ Branch 16 → 40 not taken.
✓ Branch 17 → 18 taken 516 times.
✗ Branch 17 → 38 not taken.
1548 const Function function("sDealloc", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr);
122
1/2
✓ Branch 22 → 23 taken 516 times.
✗ Branch 22 → 56 not taken.
516 const std::string mangledName = NameMangling::mangleFunction(function);
123
2/4
✓ Branch 23 → 24 taken 516 times.
✗ Branch 23 → 52 not taken.
✓ Branch 26 → 27 taken 516 times.
✗ Branch 26 → 52 not taken.
1032 return getProcedure(mangledName.c_str(), {builder.getPtrTy()});
124 516 }
125
126 8 llvm::Function *StdFunctionManager::getIterateFct(const Function *spiceFunc) const {
127
1/2
✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 25 not taken.
8 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
128
4/8
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 21 not taken.
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 21 not taken.
✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 18 not taken.
✓ Branch 9 → 10 taken 8 times.
✗ Branch 9 → 16 not taken.
24 return getSpiceFunction(functionName.c_str(), spiceFunc->returnType, {builder.getPtrTy(), builder.getInt64Ty()});
129 8 }
130
131 584 llvm::Function *StdFunctionManager::getIteratorFct(const Function *spiceFunc) const {
132
1/2
✓ Branch 2 → 3 taken 584 times.
✗ Branch 2 → 24 not taken.
584 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
133
3/6
✓ Branch 3 → 4 taken 584 times.
✗ Branch 3 → 20 not taken.
✓ Branch 6 → 7 taken 584 times.
✗ Branch 6 → 17 not taken.
✓ Branch 8 → 9 taken 584 times.
✗ Branch 8 → 15 not taken.
1752 return getSpiceFunction(functionName.c_str(), spiceFunc->returnType, {builder.getPtrTy()});
134 584 }
135
136 606 llvm::Function *StdFunctionManager::getIteratorGetFct(const Function *spiceFunc) const {
137
1/2
✓ Branch 2 → 3 taken 606 times.
✗ Branch 2 → 16 not taken.
606 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
138
3/6
✓ Branch 3 → 4 taken 606 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 606 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 606 times.
✗ Branch 7 → 12 not taken.
1212 return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy());
139 606 }
140
141 44 llvm::Function *StdFunctionManager::getIteratorGetIdxFct(const Function *spiceFunc) const {
142
1/2
✓ Branch 2 → 3 taken 44 times.
✗ Branch 2 → 24 not taken.
44 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
143
3/6
✓ Branch 3 → 4 taken 44 times.
✗ Branch 3 → 20 not taken.
✓ Branch 6 → 7 taken 44 times.
✗ Branch 6 → 17 not taken.
✓ Branch 8 → 9 taken 44 times.
✗ Branch 8 → 15 not taken.
132 return getSpiceFunction(functionName.c_str(), spiceFunc->returnType, {builder.getPtrTy()});
144 44 }
145
146 650 llvm::Function *StdFunctionManager::getIteratorIsValidFct(const Function *spiceFunc) const {
147
1/2
✓ Branch 2 → 3 taken 650 times.
✗ Branch 2 → 16 not taken.
650 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
148
3/6
✓ Branch 3 → 4 taken 650 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 650 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 650 times.
✗ Branch 7 → 12 not taken.
1300 return getFunction(functionName.c_str(), builder.getInt1Ty(), builder.getPtrTy());
149 650 }
150
151 650 llvm::Function *StdFunctionManager::getIteratorNextFct(const Function *spiceFunc) const {
152
1/2
✓ Branch 2 → 3 taken 650 times.
✗ Branch 2 → 15 not taken.
650 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
153
2/4
✓ Branch 3 → 4 taken 650 times.
✗ Branch 3 → 11 not taken.
✓ Branch 6 → 7 taken 650 times.
✗ Branch 6 → 11 not taken.
1300 return getProcedure(functionName.c_str(), builder.getPtrTy());
154 650 }
155
156 156 llvm::Function *StdFunctionManager::getResultIsErrFct(const Function *spiceFunc) const {
157
1/2
✓ Branch 2 → 3 taken 156 times.
✗ Branch 2 → 16 not taken.
156 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
158
3/6
✓ Branch 3 → 4 taken 156 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 156 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 156 times.
✗ Branch 7 → 12 not taken.
312 return getFunction(functionName.c_str(), builder.getInt1Ty(), builder.getPtrTy());
159 156 }
160
161 156 llvm::Function *StdFunctionManager::getResultUnwrapFct(const Function *spiceFunc) const {
162
1/2
✓ Branch 2 → 3 taken 156 times.
✗ Branch 2 → 16 not taken.
156 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
163
3/6
✓ Branch 3 → 4 taken 156 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 156 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 156 times.
✗ Branch 7 → 12 not taken.
312 return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy());
164 156 }
165
166 156 llvm::Function *StdFunctionManager::getResultGetErrFct(const Function *spiceFunc) const {
167
1/2
✓ Branch 2 → 3 taken 156 times.
✗ Branch 2 → 16 not taken.
156 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
168
3/6
✓ Branch 3 → 4 taken 156 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 156 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 156 times.
✗ Branch 7 → 12 not taken.
312 return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy());
169 156 }
170
171 156 llvm::Function *StdFunctionManager::getResultErrCtorFct(const Function *spiceFunc) const {
172
1/2
✓ Branch 2 → 3 taken 156 times.
✗ Branch 2 → 24 not taken.
156 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
173
3/6
✓ Branch 3 → 4 taken 156 times.
✗ Branch 3 → 20 not taken.
✓ Branch 6 → 7 taken 156 times.
✗ Branch 6 → 17 not taken.
✓ Branch 8 → 9 taken 156 times.
✗ Branch 8 → 15 not taken.
468 return getSpiceFunction(functionName.c_str(), spiceFunc->returnType, {builder.getPtrTy()});
174 156 }
175
176 10 llvm::Function *StdFunctionManager::getErrTraceResetFct() const {
177
1/2
✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 62 not taken.
10 QualType unsignedInt(TY_INT);
178
1/2
✓ Branch 3 → 4 taken 10 times.
✗ Branch 3 → 62 not taken.
10 unsignedInt.makeUnsigned();
179 10 const ParamList paramLst = {
180
3/6
✓ Branch 4 → 5 taken 10 times.
✗ Branch 4 → 39 not taken.
✓ Branch 5 → 6 taken 10 times.
✗ Branch 5 → 39 not taken.
✓ Branch 8 → 9 taken 10 times.
✗ Branch 8 → 36 not taken.
20 {QualType(TY_STRING), false}, {QualType(TY_STRING), false}, {unsignedInt, false}, {unsignedInt, false}};
181
5/10
✓ Branch 11 → 12 taken 10 times.
✗ Branch 11 → 50 not taken.
✓ Branch 12 → 13 taken 10 times.
✗ Branch 12 → 47 not taken.
✓ Branch 13 → 14 taken 10 times.
✗ Branch 13 → 46 not taken.
✓ Branch 16 → 17 taken 10 times.
✗ Branch 16 → 42 not taken.
✓ Branch 17 → 18 taken 10 times.
✗ Branch 17 → 40 not taken.
30 const Function function("sErrTraceReset", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr);
182
1/2
✓ Branch 22 → 23 taken 10 times.
✗ Branch 22 → 58 not taken.
10 const std::string mangledName = NameMangling::mangleFunction(function);
183
5/10
✓ Branch 23 → 24 taken 10 times.
✗ Branch 23 → 54 not taken.
✓ Branch 24 → 25 taken 10 times.
✗ Branch 24 → 54 not taken.
✓ Branch 25 → 26 taken 10 times.
✗ Branch 25 → 54 not taken.
✓ Branch 26 → 27 taken 10 times.
✗ Branch 26 → 54 not taken.
✓ Branch 29 → 30 taken 10 times.
✗ Branch 29 → 54 not taken.
20 return getProcedure(mangledName.c_str(), {builder.getPtrTy(), builder.getPtrTy(), builder.getInt32Ty(), builder.getInt32Ty()});
184 10 }
185
186 6 llvm::Function *StdFunctionManager::getErrTracePushFct() const {
187
1/2
✓ Branch 2 → 3 taken 6 times.
✗ Branch 2 → 62 not taken.
6 QualType unsignedInt(TY_INT);
188
1/2
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 62 not taken.
6 unsignedInt.makeUnsigned();
189 6 const ParamList paramLst = {
190
3/6
✓ Branch 4 → 5 taken 6 times.
✗ Branch 4 → 39 not taken.
✓ Branch 5 → 6 taken 6 times.
✗ Branch 5 → 39 not taken.
✓ Branch 8 → 9 taken 6 times.
✗ Branch 8 → 36 not taken.
12 {QualType(TY_STRING), false}, {QualType(TY_STRING), false}, {unsignedInt, false}, {unsignedInt, false}};
191
5/10
✓ Branch 11 → 12 taken 6 times.
✗ Branch 11 → 50 not taken.
✓ Branch 12 → 13 taken 6 times.
✗ Branch 12 → 47 not taken.
✓ Branch 13 → 14 taken 6 times.
✗ Branch 13 → 46 not taken.
✓ Branch 16 → 17 taken 6 times.
✗ Branch 16 → 42 not taken.
✓ Branch 17 → 18 taken 6 times.
✗ Branch 17 → 40 not taken.
18 const Function function("sErrTracePush", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr);
192
1/2
✓ Branch 22 → 23 taken 6 times.
✗ Branch 22 → 58 not taken.
6 const std::string mangledName = NameMangling::mangleFunction(function);
193
5/10
✓ Branch 23 → 24 taken 6 times.
✗ Branch 23 → 54 not taken.
✓ Branch 24 → 25 taken 6 times.
✗ Branch 24 → 54 not taken.
✓ Branch 25 → 26 taken 6 times.
✗ Branch 25 → 54 not taken.
✓ Branch 26 → 27 taken 6 times.
✗ Branch 26 → 54 not taken.
✓ Branch 29 → 30 taken 6 times.
✗ Branch 29 → 54 not taken.
12 return getProcedure(mangledName.c_str(), {builder.getPtrTy(), builder.getPtrTy(), builder.getInt32Ty(), builder.getInt32Ty()});
194 6 }
195
196 3911 llvm::Function *StdFunctionManager::getErrTraceDumpFct() const {
197
4/8
✓ Branch 4 → 5 taken 3911 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 3911 times.
✗ Branch 5 → 29 not taken.
✓ Branch 8 → 9 taken 3911 times.
✗ Branch 8 → 25 not taken.
✓ Branch 9 → 10 taken 3911 times.
✗ Branch 9 → 23 not taken.
11733 const Function function("sErrTraceDump", nullptr, QualType(TY_DYN), QualType(TY_DYN), {}, {}, nullptr);
198
1/2
✓ Branch 14 → 15 taken 3911 times.
✗ Branch 14 → 40 not taken.
3911 const std::string mangledName = NameMangling::mangleFunction(function);
199
1/2
✓ Branch 17 → 18 taken 3911 times.
✗ Branch 17 → 37 not taken.
7822 return getProcedure(mangledName.c_str(), {});
200 3911 }
201
202 ✗ llvm::Function *StdFunctionManager::getDumpStacktraceFct() const {
203 // Defaults are resolved by the time a function is mangled, so the params are not optional
204 ✗ const ParamList paramLst = {{QualType(TY_BOOL), false}, {QualType(TY_BOOL), false}};
205 ✗ const Function function("sDumpStacktrace", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr);
206 ✗ const std::string mangledName = NameMangling::mangleFunction(function);
207 ✗ return getProcedure(mangledName.c_str(), {builder.getInt1Ty(), builder.getInt1Ty()});
208 ✗ }
209
210 56 llvm::Function *StdFunctionManager::getAcrtIOFuncFct() const {
211
3/6
✓ Branch 2 → 3 taken 56 times.
✗ Branch 2 → 12 not taken.
✓ Branch 4 → 5 taken 56 times.
✗ Branch 4 → 12 not taken.
✓ Branch 5 → 6 taken 56 times.
✗ Branch 5 → 12 not taken.
56 llvm::Function *stdErrPFct = getFunction("__acrt_iob_func", builder.getPtrTy(), builder.getInt32Ty());
212 56 stdErrPFct->setDSOLocal(true);
213 // Set attributes
214 56 stdErrPFct->addFnAttr(llvm::Attribute::NoUnwind);
215 56 stdErrPFct->addParamAttr(0, llvm::Attribute::NoUndef);
216 56 stdErrPFct->addRetAttr(llvm::Attribute::NoUndef);
217 56 return stdErrPFct;
218 }
219
220 38760 llvm::Function *StdFunctionManager::getFunction(const char *funcName, llvm::Type *returnType, llvm::ArrayRef<llvm::Type *> args,
221 bool varArg /*=false*/) const {
222 // Check if function already exists in the current module
223
2/4
✓ Branch 2 → 3 taken 38760 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 38759 times.
✗ Branch 3 → 14 not taken.
38760 llvm::Function *opFct = module->getFunction(funcName);
224
2/2
✓ Branch 4 → 5 taken 29660 times.
✓ Branch 4 → 6 taken 9099 times.
38759 if (opFct != nullptr)
225 29660 return opFct;
226
227 // Add function to the current module
228 9099 llvm::FunctionType *opFctTy = llvm::FunctionType::get(returnType, args, varArg);
229
2/4
✓ Branch 7 → 8 taken 9100 times.
✗ Branch 7 → 15 not taken.
✓ Branch 8 → 9 taken 9100 times.
✗ Branch 8 → 15 not taken.
9100 module->getOrInsertFunction(funcName, opFctTy);
230
2/4
✓ Branch 9 → 10 taken 9100 times.
✗ Branch 9 → 16 not taken.
✓ Branch 10 → 11 taken 9100 times.
✗ Branch 10 → 16 not taken.
9100 return module->getFunction(funcName);
231 }
232
233 792 llvm::Function *StdFunctionManager::getSpiceFunction(const char *funcName, const QualType &returnType,
234 const std::vector<llvm::Type *> &args) const {
235 // Check if function already exists in the current module
236 // The result is handed out as non-const pointer, which misc-const-correctness does not recognize as pointee mutation
237 // NOLINTNEXTLINE(misc-const-correctness)
238
4/6
✓ Branch 2 → 3 taken 792 times.
✗ Branch 2 → 17 not taken.
✓ Branch 3 → 4 taken 792 times.
✗ Branch 3 → 17 not taken.
✓ Branch 4 → 5 taken 426 times.
✓ Branch 4 → 6 taken 366 times.
792 if (llvm::Function *fct = module->getFunction(funcName))
239 426 return fct;
240
241 // Add function with the return value lowered to the calling convention of the target to the current module
242
2/4
✓ Branch 7 → 8 taken 366 times.
✗ Branch 7 → 18 not taken.
✓ Branch 8 → 9 taken 366 times.
✗ Branch 8 → 18 not taken.
366 module->getOrInsertFunction(funcName, irGenerator->getFunctionType(returnType, args));
243
2/4
✓ Branch 9 → 10 taken 366 times.
✗ Branch 9 → 19 not taken.
✓ Branch 10 → 11 taken 366 times.
✗ Branch 10 → 19 not taken.
366 llvm::Function *fct = module->getFunction(funcName);
244
3/4
✓ Branch 11 → 12 taken 366 times.
✗ Branch 11 → 20 not taken.
✓ Branch 13 → 14 taken 346 times.
✓ Branch 13 → 15 taken 20 times.
366 if (const ReturnABIInfo returnABI = irGenerator->getReturnABIInfo(returnType); returnABI.isIndirect())
245
1/2
✓ Branch 14 → 15 taken 346 times.
✗ Branch 14 → 20 not taken.
346 irGenerator->addSRetParamAttrs(fct, returnABI.memoryType);
246 366 return fct;
247 }
248
249 20358 llvm::Function *StdFunctionManager::getProcedure(const char *procName, llvm::ArrayRef<llvm::Type *> args) const {
250 20358 return getFunction(procName, builder.getVoidTy(), args, false);
251 }
252
253 } // namespace spice::compiler
254