• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

daisytuner / sdfglib / 20764569418

06 Jan 2026 10:50PM UTC coverage: 62.168% (+21.4%) from 40.764%
20764569418

push

github

web-flow
Merge pull request #433 from daisytuner/clang-coverage

updates clang coverage flags

14988 of 24109 relevant lines covered (62.17%)

88.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.14
/src/types/utils.cpp
1
#include "sdfg/types/utils.h"
2
#include <memory>
3
#include <string>
4

5
#include "sdfg/codegen/utils.h"
6
#include "sdfg/function.h"
7
#include "sdfg/symbolic/symbolic.h"
8

9
#include "sdfg/types/structure.h"
10
#include "sdfg/types/type.h"
11

12
namespace sdfg {
13
namespace types {
14

15
const types::IType&
16
infer_type_internal(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
2,310✔
17
    if (subset.empty()) {
2,310✔
18
        return type;
1,560✔
19
    }
1,560✔
20

21
    if (type.type_id() == TypeID::Scalar) {
750✔
22
        if (!subset.empty()) {
×
23
            throw InvalidSDFGException("Scalar type must have no subset");
×
24
        }
×
25

26
        return type;
×
27
    } else if (type.type_id() == TypeID::Array) {
750✔
28
        auto& array_type = static_cast<const types::Array&>(type);
739✔
29

30
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
739✔
31
        return infer_type_internal(function, array_type.element_type(), element_subset);
739✔
32
    } else if (type.type_id() == TypeID::Structure) {
739✔
33
        auto& structure_type = static_cast<const types::Structure&>(type);
11✔
34

35
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
11✔
36

37
        auto& definition = function.structure(structure_type.name());
11✔
38
        if (definition.is_vector()) {
11✔
39
            return infer_type_internal(function, definition.vector_element_type(), element_subset);
10✔
40
        }
10✔
41
        auto member = SymEngine::rcp_dynamic_cast<const SymEngine::Integer>(subset.at(0));
1✔
42
        return infer_type_internal(function, definition.member_type(member), element_subset);
1✔
43
    } else if (type.type_id() == TypeID::Pointer) {
11✔
44
        throw InvalidSDFGException("Subset references non-contiguous memory");
×
45
    }
×
46

47
    throw InvalidSDFGException("Type inference failed because of unknown type");
×
48
};
750✔
49

50
const types::IType& infer_type(const sdfg::Function& function, const types::IType& type, const data_flow::Subset& subset) {
3,263✔
51
    if (subset.empty()) {
3,263✔
52
        return type;
1,703✔
53
    }
1,703✔
54

55
    if (type.type_id() == TypeID::Pointer) {
1,560✔
56
        auto& pointer_type = static_cast<const types::Pointer&>(type);
1,160✔
57
        if (!pointer_type.has_pointee_type()) {
1,160✔
58
            throw InvalidSDFGException("Opaque pointer with non-empty subset");
×
59
        }
×
60

61
        auto& pointee_type = pointer_type.pointee_type();
1,160✔
62
        data_flow::Subset element_subset(subset.begin() + 1, subset.end());
1,160✔
63
        return infer_type_internal(function, pointee_type, element_subset);
1,160✔
64
    } else {
1,160✔
65
        return infer_type_internal(function, type, subset);
400✔
66
    }
400✔
67
};
1,560✔
68

69
std::unique_ptr<types::IType> recombine_array_type(const types::IType& type, uint depth, const types::IType& inner_type) {
21✔
70
    if (depth == 0) {
21✔
71
        return inner_type.clone();
9✔
72
    } else {
12✔
73
        if (auto atype = dynamic_cast<const types::Array*>(&type)) {
12✔
74
            return std::make_unique<types::Array>(
12✔
75
                atype->storage_type(),
12✔
76
                atype->alignment(),
12✔
77
                atype->initializer(),
12✔
78
                *recombine_array_type(atype->element_type(), depth - 1, inner_type).get(),
12✔
79
                atype->num_elements()
12✔
80
            );
12✔
81
        } else {
12✔
82
            throw std::runtime_error("construct_type: Non array types are not supported yet!");
×
83
        }
×
84
    }
12✔
85
};
21✔
86

87
const IType& peel_to_innermost_element(const IType& type, int follow_ptr) {
13✔
88
    int next_follow = follow_ptr;
13✔
89
    if (follow_ptr == PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
13✔
90
        next_follow = 0; // only follow an outermost pointer
5✔
91
    }
5✔
92

93
    switch (type.type_id()) {
13✔
94
        case TypeID::Array:
3✔
95
            return peel_to_innermost_element(dynamic_cast<const types::Array&>(type).element_type(), next_follow);
3✔
96
        case TypeID::Reference:
×
97
            return peel_to_innermost_element(dynamic_cast<const codegen::Reference&>(type).reference_type(), next_follow);
×
98
        case TypeID::Pointer:
6✔
99
            if (follow_ptr != 0) {
6✔
100
                if (follow_ptr != PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR) {
5✔
101
                    next_follow = follow_ptr - 1; // follow one less pointer
×
102
                }
×
103

104
                auto& pointer_type = dynamic_cast<const types::Pointer&>(type);
5✔
105
                if (pointer_type.has_pointee_type()) {
5✔
106
                    return peel_to_innermost_element(pointer_type.pointee_type(), next_follow);
5✔
107
                } else {
5✔
108
                    return type;
×
109
                }
×
110
            }
5✔
111
            // fall back to cut-off if we did not follow the pointer
112
        default:
5✔
113
            return type;
5✔
114
    }
13✔
115
}
13✔
116

117
symbolic::Expression get_contiguous_element_size(const types::IType& type, bool allow_comp_time_eval) {
5✔
118
    // need to peel explicitly, primitive_type() would follow ALL pointers, even ***, even though this is not contiguous
119
    auto& innermost = peel_to_innermost_element(type, PEEL_TO_INNERMOST_ELEMENT_FOLLOW_ONLY_OUTER_PTR);
5✔
120
    return get_type_size(innermost, allow_comp_time_eval);
5✔
121
}
5✔
122

123
symbolic::Expression get_type_size(const types::IType& type, bool allow_comp_time_eval) {
20✔
124
    bool only_symbolic = false;
20✔
125

126
    auto id = type.type_id();
20✔
127
    if (id == TypeID::Pointer || id == TypeID::Reference || id == TypeID::Function) {
20✔
128
        return symbolic::integer(8); // assume 64-bit pointers
3✔
129
    } else if (id == TypeID::Structure) {
17✔
130
        // TODO if we have the target definition, we could evaluate the StructureDefinition to a size
131
        only_symbolic = true;
5✔
132
    } else if (id == TypeID::Array) {
12✔
133
        auto& arr = dynamic_cast<const types::Array&>(type);
1✔
134
        auto inner_element_size = get_type_size(arr.element_type(), allow_comp_time_eval);
1✔
135
        if (!inner_element_size.is_null()) {
1✔
136
            return symbolic::mul(inner_element_size, arr.num_elements());
1✔
137
        } else {
1✔
138
            return {};
×
139
        }
×
140
    }
1✔
141

142
    if (only_symbolic) {
16✔
143
        // Could not statically figure out the size
144
        // Could be struct we could evaluate by its definition or sth. we do not understand here
145
        if (allow_comp_time_eval) {
5✔
146
            return symbolic::size_of_type(type);
4✔
147
        } else { // size unknown
4✔
148
            return {};
1✔
149
        }
1✔
150
    } else { // should just be a primitive type
11✔
151
        auto prim_type = type.primitive_type();
11✔
152

153
        long size_of_type = static_cast<long>(types::bit_width(prim_type)) / 8;
11✔
154
        if (size_of_type != 0) {
11✔
155
            return symbolic::integer(size_of_type);
11✔
156
        } else {
11✔
157
            return {};
×
158
        }
×
159
    }
11✔
160
}
16✔
161

162
const types::IType* peel_to_next_element(const types::IType& type) {
5✔
163
    switch (type.type_id()) {
5✔
164
        case TypeID::Array:
2✔
165
            return &dynamic_cast<const types::Array&>(type).element_type();
2✔
166
        case TypeID::Reference:
×
167
            return &dynamic_cast<const codegen::Reference&>(type).reference_type();
×
168
        case TypeID::Pointer: {
2✔
169
            auto& pointer_type = dynamic_cast<const types::Pointer&>(type);
2✔
170
            if (pointer_type.has_pointee_type()) {
2✔
171
                return &pointer_type.pointee_type();
2✔
172
            } else {
2✔
173
                return nullptr;
×
174
            }
×
175
        }
2✔
176
        default:
1✔
177
            return &type;
1✔
178
    }
5✔
179
}
5✔
180

181
} // namespace types
182
} // namespace sdfg
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc