GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 92.7% 164 / 0 / 177
Functions: 92.9% 26 / 0 / 28
Branches: 46.4% 156 / 0 / 336

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/NameMangling.h>
9 #include <model/Function.h>
10
11 #include <llvm/IR/Module.h>
12
13 namespace spice::compiler {
14
15 4601 StdFunctionManager::StdFunctionManager(SourceFile *sourceFile, GlobalResourceManager &resourceManager, llvm::Module *module)
16
2/2
✓ Branch 2 → 3 taken 4 times.
✓ Branch 2 → 4 taken 4597 times.
4601 : sourceFile(sourceFile), context(resourceManager.cliOptions.useLTO ? resourceManager.ltoContext : sourceFile->context),
17 4601 builder(sourceFile->builder), module(module) {}
18
19 2841 llvm::Function *StdFunctionManager::getPrintfFct() const {
20
3/6
✓ Branch 2 → 3 taken 2841 times.
✗ Branch 2 → 17 not taken.
✓ Branch 4 → 5 taken 2841 times.
✗ Branch 4 → 17 not taken.
✓ Branch 5 → 6 taken 2841 times.
✗ Branch 5 → 17 not taken.
2841 llvm::Function *printfFct = getFunction("printf", builder.getInt32Ty(), builder.getPtrTy(), true);
21 // Set attributes
22 2841 printfFct->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Local);
23 2841 printfFct->addFnAttr(llvm::Attribute::NoFree);
24 2841 printfFct->addFnAttr(llvm::Attribute::NoUnwind);
25 2841 printfFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
26 2841 printfFct->addParamAttr(0, llvm::Attribute::NoUndef);
27 2841 printfFct->addParamAttr(0, llvm::Attribute::ReadOnly);
28 2841 printfFct->addRetAttr(llvm::Attribute::NoUndef);
29 2841 return printfFct;
30 }
31
32 11194 llvm::Function *StdFunctionManager::getFPrintfFct() const {
33
4/8
✓ Branch 2 → 3 taken 11194 times.
✗ Branch 2 → 21 not taken.
✓ Branch 3 → 4 taken 11194 times.
✗ Branch 3 → 21 not taken.
✓ Branch 5 → 6 taken 11194 times.
✗ Branch 5 → 21 not taken.
✓ Branch 6 → 7 taken 11194 times.
✗ Branch 6 → 21 not taken.
11194 llvm::Function *fprintfFct = getFunction("fprintf", builder.getInt32Ty(), {builder.getPtrTy(), builder.getPtrTy()}, true);
34 // Set attributes
35 11194 fprintfFct->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Local);
36 11194 fprintfFct->addFnAttr(llvm::Attribute::NoFree);
37 11194 fprintfFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
38 11194 fprintfFct->addParamAttr(0, llvm::Attribute::NoUndef);
39 11194 fprintfFct->addParamAttr(1, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
40 11194 fprintfFct->addParamAttr(1, llvm::Attribute::NoUndef);
41 11194 fprintfFct->addParamAttr(1, llvm::Attribute::ReadOnly);
42 11194 fprintfFct->addRetAttr(llvm::Attribute::NoUndef);
43 11194 return fprintfFct;
44 }
45
46 11194 llvm::Function *StdFunctionManager::getExitFct() const {
47
2/4
✓ Branch 2 → 3 taken 11194 times.
✗ Branch 2 → 10 not taken.
✓ Branch 4 → 5 taken 11194 times.
✗ Branch 4 → 10 not taken.
11194 llvm::Function *exitFct = getProcedure("exit", builder.getInt32Ty());
48 // Set attributes
49 11194 exitFct->addFnAttr(llvm::Attribute::Cold);
50 11194 exitFct->addFnAttr(llvm::Attribute::NoReturn);
51 11194 exitFct->addFnAttr(llvm::Attribute::NoUnwind);
52 11194 return exitFct;
53 }
54
55 ✗ llvm::Function *StdFunctionManager::getFreeFct() const {
56 ✗ llvm::Function *freeFct = getProcedure("free", builder.getPtrTy());
57 // Set attributes
58 ✗ freeFct->addFnAttr(llvm::Attribute::NoUnwind);
59 ✗ freeFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
60 ✗ freeFct->addParamAttr(0, llvm::Attribute::NoUndef);
61 ✗ freeFct->addParamAttr(0, llvm::Attribute::ReadOnly);
62 ✗ return freeFct;
63 }
64
65 112 llvm::Function *StdFunctionManager::getMemcmpFct() const {
66 112 llvm::Type *ptrTy = builder.getPtrTy();
67
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()});
68 // Set attributes
69 112 memcmpFct->addFnAttr(llvm::Attribute::NoUnwind);
70 112 memcmpFct->addParamAttr(0, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
71 112 memcmpFct->addParamAttr(0, llvm::Attribute::NoUndef);
72 112 memcmpFct->addParamAttr(0, llvm::Attribute::ReadOnly);
73 112 memcmpFct->addParamAttr(1, llvm::Attribute::getWithCaptureInfo(context, llvm::CaptureInfo::none()));
74 112 memcmpFct->addParamAttr(1, llvm::Attribute::NoUndef);
75 112 memcmpFct->addParamAttr(1, llvm::Attribute::ReadOnly);
76 112 memcmpFct->addParamAttr(2, llvm::Attribute::NoUndef);
77 112 memcmpFct->addRetAttr(llvm::Attribute::NoUndef);
78 112 return memcmpFct;
79 }
80
81 2769 llvm::Function *StdFunctionManager::getMemcpyIntrinsic() const {
82 2769 llvm::Type *ptrTy = builder.getPtrTy();
83
3/6
✓ Branch 3 → 4 taken 2769 times.
✗ Branch 3 → 13 not taken.
✓ Branch 4 → 5 taken 2769 times.
✗ Branch 4 → 13 not taken.
✓ Branch 6 → 7 taken 2769 times.
✗ Branch 6 → 13 not taken.
2769 llvm::Function *memcpyFct = getProcedure("llvm.memcpy.p0.p0.i64", {ptrTy, ptrTy, builder.getInt64Ty(), builder.getInt1Ty()});
84 // Set attributes
85 2769 memcpyFct->addFnAttr(llvm::Attribute::NoCallback);
86 2769 memcpyFct->addFnAttr(llvm::Attribute::NoFree);
87 2769 memcpyFct->addFnAttr(llvm::Attribute::NoUnwind);
88 2769 memcpyFct->addFnAttr(llvm::Attribute::WillReturn);
89 2769 return memcpyFct;
90 }
91
92 124 llvm::Function *StdFunctionManager::getStringGetRawLengthStringFct() const {
93
2/4
✓ Branch 2 → 3 taken 124 times.
✗ Branch 2 → 34 not taken.
✓ Branch 5 → 6 taken 124 times.
✗ Branch 5 → 31 not taken.
248 const ParamList paramLst = {{QualType(TY_STRING), false}};
94
5/10
✓ Branch 8 → 9 taken 124 times.
✗ Branch 8 → 45 not taken.
✓ Branch 9 → 10 taken 124 times.
✗ Branch 9 → 42 not taken.
✓ Branch 10 → 11 taken 124 times.
✗ Branch 10 → 41 not taken.
✓ Branch 13 → 14 taken 124 times.
✗ Branch 13 → 37 not taken.
✓ Branch 14 → 15 taken 124 times.
✗ Branch 14 → 35 not taken.
372 const Function function("getRawLength", nullptr, QualType(TY_DYN), QualType(TY_LONG), paramLst, {}, nullptr);
95
1/2
✓ Branch 19 → 20 taken 124 times.
✗ Branch 19 → 53 not taken.
124 const std::string mangledName = NameMangling::mangleFunction(function);
96
3/6
✓ Branch 20 → 21 taken 124 times.
✗ Branch 20 → 49 not taken.
✓ Branch 22 → 23 taken 124 times.
✗ Branch 22 → 49 not taken.
✓ Branch 24 → 25 taken 124 times.
✗ Branch 24 → 49 not taken.
248 return getFunction(mangledName.c_str(), builder.getInt64Ty(), {builder.getPtrTy()});
97 124 }
98
99 732 llvm::Function *StdFunctionManager::getStringIsRawEqualStringStringFct() const {
100
3/6
✓ Branch 2 → 3 taken 732 times.
✗ Branch 2 → 36 not taken.
✓ Branch 3 → 4 taken 732 times.
✗ Branch 3 → 36 not taken.
✓ Branch 6 → 7 taken 732 times.
✗ Branch 6 → 33 not taken.
1464 const ParamList paramLst = {{QualType(TY_STRING), false}, {QualType(TY_STRING), false}};
101
5/10
✓ Branch 9 → 10 taken 732 times.
✗ Branch 9 → 47 not taken.
✓ Branch 10 → 11 taken 732 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 732 times.
✗ Branch 11 → 43 not taken.
✓ Branch 14 → 15 taken 732 times.
✗ Branch 14 → 39 not taken.
✓ Branch 15 → 16 taken 732 times.
✗ Branch 15 → 37 not taken.
2196 const Function function("isRawEqual", nullptr, QualType(TY_DYN), QualType(TY_BOOL), paramLst, {}, nullptr);
102
1/2
✓ Branch 20 → 21 taken 732 times.
✗ Branch 20 → 55 not taken.
732 const std::string mangledName = NameMangling::mangleFunction(function);
103
4/8
✓ Branch 21 → 22 taken 732 times.
✗ Branch 21 → 51 not taken.
✓ Branch 22 → 23 taken 732 times.
✗ Branch 22 → 51 not taken.
✓ Branch 24 → 25 taken 732 times.
✗ Branch 24 → 51 not taken.
✓ Branch 26 → 27 taken 732 times.
✗ Branch 26 → 51 not taken.
1464 return getFunction(mangledName.c_str(), builder.getInt1Ty(), {builder.getPtrTy(), builder.getPtrTy()});
104 732 }
105
106 495 llvm::Function *StdFunctionManager::getAllocUnsafeLongFct() const {
107
1/2
✓ Branch 2 → 3 taken 495 times.
✗ Branch 2 → 60 not taken.
495 QualType unsignedLong(TY_LONG);
108
1/2
✓ Branch 3 → 4 taken 495 times.
✗ Branch 3 → 60 not taken.
495 unsignedLong.makeUnsigned();
109
1/2
✓ Branch 6 → 7 taken 495 times.
✗ Branch 6 → 33 not taken.
990 const ParamList paramLst = {{unsignedLong, false}};
110
6/12
✓ Branch 9 → 10 taken 495 times.
✗ Branch 9 → 48 not taken.
✓ Branch 10 → 11 taken 495 times.
✗ Branch 10 → 44 not taken.
✓ Branch 11 → 12 taken 495 times.
✗ Branch 11 → 44 not taken.
✓ Branch 12 → 13 taken 495 times.
✗ Branch 12 → 43 not taken.
✓ Branch 15 → 16 taken 495 times.
✗ Branch 15 → 39 not taken.
✓ Branch 16 → 17 taken 495 times.
✗ Branch 16 → 37 not taken.
1485 const Function function("sAllocUnsafe", nullptr, QualType(TY_DYN), QualType(TY_BYTE).toPtr(nullptr), paramLst, {}, nullptr);
111
1/2
✓ Branch 21 → 22 taken 495 times.
✗ Branch 21 → 56 not taken.
495 const std::string mangledName = NameMangling::mangleFunction(function);
112
3/6
✓ Branch 22 → 23 taken 495 times.
✗ Branch 22 → 52 not taken.
✓ Branch 24 → 25 taken 495 times.
✗ Branch 24 → 52 not taken.
✓ Branch 26 → 27 taken 495 times.
✗ Branch 26 → 52 not taken.
990 return getFunction(mangledName.c_str(), builder.getPtrTy(), {builder.getInt64Ty()});
113 495 }
114
115 514 llvm::Function *StdFunctionManager::getDeallocBytePtrRefFct() const {
116
2/4
✓ Branch 2 → 3 taken 514 times.
✗ Branch 2 → 33 not taken.
✓ Branch 3 → 4 taken 514 times.
✗ Branch 3 → 33 not taken.
514 QualType heapBytePtrType = QualType(TY_BYTE).toPtr(nullptr);
117
1/2
✓ Branch 4 → 5 taken 514 times.
✗ Branch 4 → 60 not taken.
514 heapBytePtrType.makeHeap();
118
2/4
✓ Branch 5 → 6 taken 514 times.
✗ Branch 5 → 37 not taken.
✓ Branch 8 → 9 taken 514 times.
✗ Branch 8 → 34 not taken.
1028 const ParamList paramLst = {{heapBytePtrType.toRef(nullptr), false}};
119
5/10
✓ Branch 11 → 12 taken 514 times.
✗ Branch 11 → 48 not taken.
✓ Branch 12 → 13 taken 514 times.
✗ Branch 12 → 45 not taken.
✓ Branch 13 → 14 taken 514 times.
✗ Branch 13 → 44 not taken.
✓ Branch 16 → 17 taken 514 times.
✗ Branch 16 → 40 not taken.
✓ Branch 17 → 18 taken 514 times.
✗ Branch 17 → 38 not taken.
1542 const Function function("sDealloc", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr);
120
1/2
✓ Branch 22 → 23 taken 514 times.
✗ Branch 22 → 56 not taken.
514 const std::string mangledName = NameMangling::mangleFunction(function);
121
2/4
✓ Branch 23 → 24 taken 514 times.
✗ Branch 23 → 52 not taken.
✓ Branch 26 → 27 taken 514 times.
✗ Branch 26 → 52 not taken.
1028 return getProcedure(mangledName.c_str(), {builder.getPtrTy()});
122 514 }
123
124 8 llvm::Function *StdFunctionManager::getIterateFct(const Function *spiceFunc) const {
125
1/2
✓ Branch 2 → 3 taken 8 times.
✗ Branch 2 → 17 not taken.
8 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
126
1/2
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 15 not taken.
8 llvm::Type *iteratorType = spiceFunc->returnType.toLLVMType(sourceFile);
127
3/6
✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 13 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 13 not taken.
✓ Branch 8 → 9 taken 8 times.
✗ Branch 8 → 13 not taken.
16 return getFunction(functionName.c_str(), iteratorType, {builder.getPtrTy(), builder.getInt64Ty()});
128 8 }
129
130 556 llvm::Function *StdFunctionManager::getIteratorFct(const Function *spiceFunc) const {
131
1/2
✓ Branch 2 → 3 taken 556 times.
✗ Branch 2 → 16 not taken.
556 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
132
1/2
✓ Branch 3 → 4 taken 556 times.
✗ Branch 3 → 14 not taken.
556 llvm::Type *iteratorType = spiceFunc->returnType.toLLVMType(sourceFile);
133
2/4
✓ Branch 4 → 5 taken 556 times.
✗ Branch 4 → 12 not taken.
✓ Branch 7 → 8 taken 556 times.
✗ Branch 7 → 12 not taken.
1112 return getFunction(functionName.c_str(), iteratorType, builder.getPtrTy());
134 556 }
135
136 578 llvm::Function *StdFunctionManager::getIteratorGetFct(const Function *spiceFunc) const {
137
1/2
✓ Branch 2 → 3 taken 578 times.
✗ Branch 2 → 16 not taken.
578 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
138
3/6
✓ Branch 3 → 4 taken 578 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 578 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 578 times.
✗ Branch 7 → 12 not taken.
1156 return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy());
139 578 }
140
141 44 llvm::Function *StdFunctionManager::getIteratorGetIdxFct(const Function *spiceFunc) const {
142
1/2
✓ Branch 2 → 3 taken 44 times.
✗ Branch 2 → 16 not taken.
44 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
143
1/2
✓ Branch 3 → 4 taken 44 times.
✗ Branch 3 → 14 not taken.
44 llvm::Type *pairTy = spiceFunc->returnType.toLLVMType(sourceFile);
144
2/4
✓ Branch 4 → 5 taken 44 times.
✗ Branch 4 → 12 not taken.
✓ Branch 7 → 8 taken 44 times.
✗ Branch 7 → 12 not taken.
88 return getFunction(functionName.c_str(), pairTy, builder.getPtrTy());
145 44 }
146
147 622 llvm::Function *StdFunctionManager::getIteratorIsValidFct(const Function *spiceFunc) const {
148
1/2
✓ Branch 2 → 3 taken 622 times.
✗ Branch 2 → 16 not taken.
622 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
149
3/6
✓ Branch 3 → 4 taken 622 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 622 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 622 times.
✗ Branch 7 → 12 not taken.
1244 return getFunction(functionName.c_str(), builder.getInt1Ty(), builder.getPtrTy());
150 622 }
151
152 622 llvm::Function *StdFunctionManager::getIteratorNextFct(const Function *spiceFunc) const {
153
1/2
✓ Branch 2 → 3 taken 622 times.
✗ Branch 2 → 15 not taken.
622 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
154
2/4
✓ Branch 3 → 4 taken 622 times.
✗ Branch 3 → 11 not taken.
✓ Branch 6 → 7 taken 622 times.
✗ Branch 6 → 11 not taken.
1244 return getProcedure(functionName.c_str(), builder.getPtrTy());
155 622 }
156
157 138 llvm::Function *StdFunctionManager::getResultIsErrFct(const Function *spiceFunc) const {
158
1/2
✓ Branch 2 → 3 taken 138 times.
✗ Branch 2 → 16 not taken.
138 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
159
3/6
✓ Branch 3 → 4 taken 138 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 138 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 138 times.
✗ Branch 7 → 12 not taken.
276 return getFunction(functionName.c_str(), builder.getInt1Ty(), builder.getPtrTy());
160 138 }
161
162 138 llvm::Function *StdFunctionManager::getResultUnwrapFct(const Function *spiceFunc) const {
163
1/2
✓ Branch 2 → 3 taken 138 times.
✗ Branch 2 → 16 not taken.
138 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
164
3/6
✓ Branch 3 → 4 taken 138 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 138 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 138 times.
✗ Branch 7 → 12 not taken.
276 return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy());
165 138 }
166
167 138 llvm::Function *StdFunctionManager::getResultGetErrFct(const Function *spiceFunc) const {
168
1/2
✓ Branch 2 → 3 taken 138 times.
✗ Branch 2 → 16 not taken.
138 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
169
3/6
✓ Branch 3 → 4 taken 138 times.
✗ Branch 3 → 12 not taken.
✓ Branch 5 → 6 taken 138 times.
✗ Branch 5 → 12 not taken.
✓ Branch 7 → 8 taken 138 times.
✗ Branch 7 → 12 not taken.
276 return getFunction(functionName.c_str(), builder.getPtrTy(), builder.getPtrTy());
170 138 }
171
172 138 llvm::Function *StdFunctionManager::getResultErrCtorFct(const Function *spiceFunc) const {
173
1/2
✓ Branch 2 → 3 taken 138 times.
✗ Branch 2 → 16 not taken.
138 const std::string functionName = NameMangling::mangleFunction(*spiceFunc);
174
1/2
✓ Branch 3 → 4 taken 138 times.
✗ Branch 3 → 14 not taken.
138 llvm::Type *resultType = spiceFunc->returnType.toLLVMType(sourceFile);
175
2/4
✓ Branch 4 → 5 taken 138 times.
✗ Branch 4 → 12 not taken.
✓ Branch 7 → 8 taken 138 times.
✗ Branch 7 → 12 not taken.
276 return getFunction(functionName.c_str(), resultType, builder.getPtrTy());
176 138 }
177
178 10 llvm::Function *StdFunctionManager::getErrTraceResetFct() const {
179
1/2
✓ Branch 2 → 3 taken 10 times.
✗ Branch 2 → 62 not taken.
10 QualType unsignedInt(TY_INT);
180
1/2
✓ Branch 3 → 4 taken 10 times.
✗ Branch 3 → 62 not taken.
10 unsignedInt.makeUnsigned();
181 10 const ParamList paramLst = {
182
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}};
183
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);
184
1/2
✓ Branch 22 → 23 taken 10 times.
✗ Branch 22 → 58 not taken.
10 const std::string mangledName = NameMangling::mangleFunction(function);
185
1/2
✓ Branch 29 → 30 taken 10 times.
✗ Branch 29 → 54 not taken.
10 return getProcedure(mangledName.c_str(),
186
4/8
✓ 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.
30 {builder.getPtrTy(), builder.getPtrTy(), builder.getInt32Ty(), builder.getInt32Ty()});
187 10 }
188
189 6 llvm::Function *StdFunctionManager::getErrTracePushFct() const {
190
1/2
✓ Branch 2 → 3 taken 6 times.
✗ Branch 2 → 62 not taken.
6 QualType unsignedInt(TY_INT);
191
1/2
✓ Branch 3 → 4 taken 6 times.
✗ Branch 3 → 62 not taken.
6 unsignedInt.makeUnsigned();
192 6 const ParamList paramLst = {
193
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}};
194
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);
195
1/2
✓ Branch 22 → 23 taken 6 times.
✗ Branch 22 → 58 not taken.
6 const std::string mangledName = NameMangling::mangleFunction(function);
196
1/2
✓ Branch 29 → 30 taken 6 times.
✗ Branch 29 → 54 not taken.
6 return getProcedure(mangledName.c_str(),
197
4/8
✓ 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.
18 {builder.getPtrTy(), builder.getPtrTy(), builder.getInt32Ty(), builder.getInt32Ty()});
198 6 }
199
200 3537 llvm::Function *StdFunctionManager::getErrTraceDumpFct() const {
201
4/8
✓ Branch 4 → 5 taken 3537 times.
✗ Branch 4 → 30 not taken.
✓ Branch 5 → 6 taken 3537 times.
✗ Branch 5 → 29 not taken.
✓ Branch 8 → 9 taken 3537 times.
✗ Branch 8 → 25 not taken.
✓ Branch 9 → 10 taken 3537 times.
✗ Branch 9 → 23 not taken.
10611 const Function function("sErrTraceDump", nullptr, QualType(TY_DYN), QualType(TY_DYN), {}, {}, nullptr);
202
1/2
✓ Branch 14 → 15 taken 3537 times.
✗ Branch 14 → 40 not taken.
3537 const std::string mangledName = NameMangling::mangleFunction(function);
203
1/2
✓ Branch 17 → 18 taken 3537 times.
✗ Branch 17 → 37 not taken.
7074 return getProcedure(mangledName.c_str(), {});
204 3537 }
205
206 ✗ llvm::Function *StdFunctionManager::getDumpStacktraceFct() const {
207 // Defaults are resolved by the time a function is mangled, so the params are not optional
208 ✗ const ParamList paramLst = {{QualType(TY_BOOL), false}, {QualType(TY_BOOL), false}};
209 ✗ const Function function("sDumpStacktrace", nullptr, QualType(TY_DYN), QualType(TY_DYN), paramLst, {}, nullptr);
210 ✗ const std::string mangledName = NameMangling::mangleFunction(function);
211 ✗ return getProcedure(mangledName.c_str(), {builder.getInt1Ty(), builder.getInt1Ty()});
212 ✗ }
213
214 30 llvm::Function *StdFunctionManager::getAcrtIOFuncFct() const {
215
3/6
✓ Branch 2 → 3 taken 30 times.
✗ Branch 2 → 12 not taken.
✓ Branch 4 → 5 taken 30 times.
✗ Branch 4 → 12 not taken.
✓ Branch 5 → 6 taken 30 times.
✗ Branch 5 → 12 not taken.
30 llvm::Function *stdErrPFct = getFunction("__acrt_iob_func", builder.getPtrTy(), builder.getInt32Ty());
216 30 stdErrPFct->setDSOLocal(true);
217 // Set attributes
218 30 stdErrPFct->addFnAttr(llvm::Attribute::NoUnwind);
219 30 stdErrPFct->addParamAttr(0, llvm::Attribute::NoUndef);
220 30 stdErrPFct->addRetAttr(llvm::Attribute::NoUndef);
221 30 return stdErrPFct;
222 }
223
224 36540 llvm::Function *StdFunctionManager::getFunction(const char *funcName, llvm::Type *returnType, llvm::ArrayRef<llvm::Type *> args,
225 bool varArg /*=false*/) const {
226 // Check if function already exists in the current module
227
2/4
✓ Branch 2 → 3 taken 36540 times.
✗ Branch 2 → 14 not taken.
✓ Branch 3 → 4 taken 36540 times.
✗ Branch 3 → 14 not taken.
36540 llvm::Function *opFct = module->getFunction(funcName);
228
2/2
✓ Branch 4 → 5 taken 27905 times.
✓ Branch 4 → 6 taken 8635 times.
36540 if (opFct != nullptr)
229 27905 return opFct;
230
231 // Add function to the current module
232 8635 llvm::FunctionType *opFctTy = llvm::FunctionType::get(returnType, args, varArg);
233
2/4
✓ Branch 7 → 8 taken 8635 times.
✗ Branch 7 → 15 not taken.
✓ Branch 8 → 9 taken 8635 times.
✗ Branch 8 → 15 not taken.
8635 module->getOrInsertFunction(funcName, opFctTy);
234
2/4
✓ Branch 9 → 10 taken 8635 times.
✗ Branch 9 → 16 not taken.
✓ Branch 10 → 11 taken 8635 times.
✗ Branch 10 → 16 not taken.
8635 return module->getFunction(funcName);
235 }
236
237 18652 llvm::Function *StdFunctionManager::getProcedure(const char *procName, llvm::ArrayRef<llvm::Type *> args) const {
238 18652 return getFunction(procName, builder.getVoidTy(), args, false);
239 }
240
241 } // namespace spice::compiler
242