|
6 | 6 | #include <string> |
7 | 7 | #include <vector> |
8 | 8 |
|
| 9 | +#include "helpers.hpp" |
| 10 | + |
9 | 11 | namespace llvm |
10 | 12 | { |
11 | 13 | class Module; |
@@ -45,19 +47,98 @@ struct FunctionResult |
45 | 47 | bool exceedsLimit = false; // maxStack > config.stackLimit |
46 | 48 | }; |
47 | 49 |
|
| 50 | +/* |
| 51 | + DiagnosticSeverity EnumTraits specialization |
| 52 | +*/ |
| 53 | + |
| 54 | +enum class LanguageType |
| 55 | +{ |
| 56 | + Unknown = 0, |
| 57 | + LLVM_IR = 1, |
| 58 | + C = 2, |
| 59 | + CXX = 3 |
| 60 | +}; |
| 61 | + |
| 62 | +template<> |
| 63 | +struct EnumTraits<LanguageType> |
| 64 | +{ |
| 65 | + static constexpr std::array<std::string_view, 4> names = { |
| 66 | + "UNKNOWN", |
| 67 | + "LLVM_IR", |
| 68 | + "C", |
| 69 | + "CXX" |
| 70 | + }; |
| 71 | +}; |
| 72 | + |
| 73 | +/* |
| 74 | + DiagnosticSeverity EnumTraits specialization |
| 75 | +*/ |
| 76 | + |
48 | 77 | enum class DiagnosticSeverity |
49 | 78 | { |
50 | 79 | Info = 0, |
51 | 80 | Warning = 1, |
52 | 81 | Error = 2 |
53 | 82 | }; |
54 | 83 |
|
| 84 | +template<> |
| 85 | +struct EnumTraits<DiagnosticSeverity> |
| 86 | +{ |
| 87 | + static constexpr std::array<std::string_view, 3> names = { |
| 88 | + "INFO", |
| 89 | + "WARNING", |
| 90 | + "ERROR" |
| 91 | + }; |
| 92 | +}; |
| 93 | + |
| 94 | +/* |
| 95 | + DescriptiveErrorCode EnumTraits specialization |
| 96 | +*/ |
| 97 | + |
| 98 | +enum class DescriptiveErrorCode |
| 99 | +{ |
| 100 | + None = 0, |
| 101 | + StackBufferOverflow = 1, |
| 102 | + NegativeStackIndex = 2, |
| 103 | + VLAUsage = 3, |
| 104 | + StackPointerEscape = 4, |
| 105 | + MemcpyWithStackDest = 5, |
| 106 | + MultipleStoresToStackBuffer = 6 |
| 107 | +}; |
| 108 | + |
| 109 | +template<> |
| 110 | +struct EnumTraits<DescriptiveErrorCode> |
| 111 | +{ |
| 112 | + static constexpr std::array<std::string_view, 7> names = { |
| 113 | + "None", |
| 114 | + "StackBufferOverflow", |
| 115 | + "NegativeStackIndex", |
| 116 | + "VLAUsage", |
| 117 | + "StackPointerEscape", |
| 118 | + "MemcpyWithStackDest", |
| 119 | + "MultipleStoresToStackBuffer" |
| 120 | + }; |
| 121 | +}; |
| 122 | + |
| 123 | +/* |
| 124 | + Diagnostic struct |
| 125 | +*/ |
| 126 | + |
55 | 127 | struct Diagnostic |
56 | 128 | { |
57 | 129 | std::string funcName; |
58 | | - unsigned line = 0; |
59 | | - unsigned column = 0; |
60 | | - DiagnosticSeverity severity = DiagnosticSeverity::Warning; |
| 130 | + unsigned line = 0; |
| 131 | + unsigned column = 0; |
| 132 | + |
| 133 | + // for SARIF / structured reporting |
| 134 | + unsigned startLine = 0; |
| 135 | + unsigned startColumn = 0; |
| 136 | + unsigned endLine = 0; |
| 137 | + unsigned endColumn = 0; |
| 138 | + |
| 139 | + DiagnosticSeverity severity = DiagnosticSeverity::Warning; |
| 140 | + DescriptiveErrorCode errCode = DescriptiveErrorCode::None; |
| 141 | + std::vector<std::string> variableAliasingVec; |
61 | 142 | std::string message; |
62 | 143 | }; |
63 | 144 |
|
|
0 commit comments