Skip to content

Commit b1a5896

Browse files
committedJun 30, 2023
feat: add isThreadLocal to VariableInfo
1 parent a864552 commit b1a5896

File tree

7 files changed

+60
-6
lines changed

7 files changed

+60
-6
lines changed
 

‎include/mrdox/Metadata/Variable.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ union VariableFlags0
2929
BitField<0, 3, StorageClassKind> storageClass;
3030
BitField<3, 2, ConstexprKind> constexprKind;
3131
BitFlag<5> isConstinit;
32+
BitFlag<6> isThreadLocal;
3233
};
3334

3435
/** A variable.

‎source/-XML/CXXTags.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ inline void write(VariableFlags0 const& bits, XMLTags& tags)
185185
fw.write(&VariableFlags0::storageClass, "storage-class");
186186
fw.write(&VariableFlags0::constexprKind, "constexpr-kind");
187187
fw.write(&VariableFlags0::isConstinit, "is-constinit");
188+
fw.write(&VariableFlags0::isThreadLocal, "is-thread-local");
188189
}
189190

190191
inline

‎source/AST/ASTVisitor.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -1364,6 +1364,11 @@ buildVar(
13641364
convertToStorageClassKind(
13651365
D->getStorageClass());
13661366

1367+
// this handles thread_local, as well as the C
1368+
// __thread and __Thread_local specifiers
1369+
I.specs.isThreadLocal = D->getTSCSpec() !=
1370+
ThreadStorageClassSpecifier::TSCS_unspecified;
1371+
13671372
// KRYSTIAN NOTE: VarDecl does not provide getConstexprKind,
13681373
// nor does it use getConstexprKind to store whether
13691374
// a variable is constexpr/constinit. Although

‎test-files/old-tests/ns-variables.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ double pi = 3.14;
1414
struct T {};
1515

1616
extern T t;
17+
18+
thread_local int x0 = 0;
19+
thread_local static int x1 = 0;
20+
constexpr thread_local static int x2 = 0;

‎test-files/old-tests/ns-variables.xml

+18
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,23 @@
3838
<attr id="storage-class" name="extern" value="1"/>
3939
<type class="tag" id="CgGNdHpW5mG/i5741WPYQDw28OQ=" name="T"/>
4040
</variable>
41+
<variable name="x0" id="LESPWJfwRpePfANf2Vm0O/W1Lfw=">
42+
<file path="ns-variables.cpp" line="18" class="def"/>
43+
<attr id="is-thread-local"/>
44+
<type name="int"/>
45+
</variable>
46+
<variable name="x1" id="bMKl4XYJf8MQ48jSHwRmFHM3MiA=">
47+
<file path="ns-variables.cpp" line="19" class="def"/>
48+
<attr id="storage-class" name="static" value="2"/>
49+
<attr id="is-thread-local"/>
50+
<type name="int"/>
51+
</variable>
52+
<variable name="x2" id="EpcDWput1W/SJ3IYEINS0W815Zw=">
53+
<file path="ns-variables.cpp" line="20" class="def"/>
54+
<attr id="storage-class" name="static" value="2"/>
55+
<attr id="constexpr-kind" name="constexpr" value="1"/>
56+
<attr id="is-thread-local"/>
57+
<type name="int" cv-qualifiers="const"/>
58+
</variable>
4159
</namespace>
4260
</mrdox>

‎test-files/old-tests/static-data-def.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ struct A
1212
static constexpr int v7 = 7;
1313
};
1414

15+
struct B
16+
{
17+
static thread_local const int x0 = 0;
18+
static constexpr thread_local int x1 = 0;
19+
};
20+
1521
template<typename T>
1622
int A<T>::v0 = 0;
1723

@@ -39,3 +45,5 @@ auto f()
3945
A<int>::v6 +
4046
A<int>::v7;
4147
}
48+
49+
thread_local const int B::x0;

‎test-files/old-tests/static-data-def.xml

+23-6
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@
77
<struct name="A" id="5tUSuMtQqtYE49jBjSYSWp0DJAM=">
88
<file path="static-data-def.cpp" line="2" class="def"/>
99
<variable name="v0" id="rW6h+mCfZLROHlYzwXFIUPN6oSE=">
10-
<file path="static-data-def.cpp" line="15" class="def"/>
10+
<file path="static-data-def.cpp" line="21" class="def"/>
1111
<file path="static-data-def.cpp" line="4"/>
1212
<attr id="storage-class" name="static" value="2"/>
1313
<type name="int"/>
1414
</variable>
1515
<variable name="v1" id="nkB0lMmDvMsu9GDrKr3Mzwi5g6I=">
16-
<file path="static-data-def.cpp" line="18" class="def"/>
16+
<file path="static-data-def.cpp" line="24" class="def"/>
1717
<file path="static-data-def.cpp" line="5"/>
1818
<attr id="storage-class" name="static" value="2"/>
1919
<type name="int"/>
2020
</variable>
2121
<variable name="v2" id="e48c97dC3AIWJHWE5T0yWVxezgg=">
22-
<file path="static-data-def.cpp" line="21" class="def"/>
22+
<file path="static-data-def.cpp" line="27" class="def"/>
2323
<file path="static-data-def.cpp" line="6"/>
2424
<attr id="storage-class" name="static" value="2"/>
2525
<attr id="constexpr-kind" name="constexpr" value="1"/>
2626
<type name="int" cv-qualifiers="const"/>
2727
</variable>
2828
<variable name="v3" id="Wx5S5oWv5o4nV7I+zFEKTvWl40g=">
29-
<file path="static-data-def.cpp" line="24" class="def"/>
29+
<file path="static-data-def.cpp" line="30" class="def"/>
3030
<file path="static-data-def.cpp" line="7"/>
3131
<attr id="storage-class" name="static" value="2"/>
3232
<type name="int" cv-qualifiers="const"/>
3333
</variable>
3434
<variable name="v4" id="6a2wBN4mHiuAAqV0gYgYQeqFNVM=">
35-
<file path="static-data-def.cpp" line="27" class="def"/>
35+
<file path="static-data-def.cpp" line="33" class="def"/>
3636
<file path="static-data-def.cpp" line="8"/>
3737
<attr id="storage-class" name="static" value="2"/>
3838
<type name="int" cv-qualifiers="const"/>
@@ -55,8 +55,25 @@
5555
</variable>
5656
</struct>
5757
</template>
58+
<struct name="B" id="3JsK1DO0O+wZhv+0meptQrbs3fY=">
59+
<file path="static-data-def.cpp" line="15" class="def"/>
60+
<variable name="x0" id="+yhNlGuTVY4spCfBXSTBkEDzi30=">
61+
<file path="static-data-def.cpp" line="49" class="def"/>
62+
<file path="static-data-def.cpp" line="17"/>
63+
<attr id="storage-class" name="static" value="2"/>
64+
<attr id="is-thread-local"/>
65+
<type name="int" cv-qualifiers="const"/>
66+
</variable>
67+
<variable name="x1" id="vNYWHh2ovZiBP3uVEeJhMkaiF3w=">
68+
<file path="static-data-def.cpp" line="18" class="def"/>
69+
<attr id="storage-class" name="static" value="2"/>
70+
<attr id="constexpr-kind" name="constexpr" value="1"/>
71+
<attr id="is-thread-local"/>
72+
<type name="int" cv-qualifiers="const"/>
73+
</variable>
74+
</struct>
5875
<function name="f" id="s6nsa+zVhpzzrN+yUVPP5rvdXqs=">
59-
<file path="static-data-def.cpp" line="30" class="def"/>
76+
<file path="static-data-def.cpp" line="36" class="def"/>
6077
<return>
6178
<type name="int"/>
6279
</return>

0 commit comments

Comments
 (0)
Please sign in to comment.