Skip to content

Commit 38ca7b1

Browse files
slowhogAaronBallman
authored andcommitted
Expose AtomicType in the libclang C API.
1 parent bac85ab commit 38ca7b1

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

clang/include/clang-c/Index.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* compatible, thus CINDEX_VERSION_MAJOR is expected to remain stable.
3434
*/
3535
#define CINDEX_VERSION_MAJOR 0
36-
#define CINDEX_VERSION_MINOR 59
36+
#define CINDEX_VERSION_MINOR 60
3737

3838
#define CINDEX_VERSION_ENCODE(major, minor) (((major)*10000) + ((minor)*1))
3939

@@ -3342,7 +3342,8 @@ enum CXTypeKind {
33423342

33433343
CXType_OCLIntelSubgroupAVCImeDualRefStreamin = 175,
33443344

3345-
CXType_ExtVector = 176
3345+
CXType_ExtVector = 176,
3346+
CXType_Atomic = 177
33463347
};
33473348

33483349
/**
@@ -3932,6 +3933,13 @@ CINDEX_LINKAGE long long clang_Type_getOffsetOf(CXType T, const char *S);
39323933
*/
39333934
CINDEX_LINKAGE CXType clang_Type_getModifiedType(CXType T);
39343935

3936+
/**
3937+
* Gets the type contained by this atomic type.
3938+
*
3939+
* If a non-atomic type is passed in, an invalid type is returned.
3940+
*/
3941+
CINDEX_LINKAGE CXType clang_Type_getValueType(CXType CT);
3942+
39353943
/**
39363944
* Return the offset of the field represented by the Cursor.
39373945
*

clang/test/Index/print-type.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ struct {
2222

2323
struct {
2424
struct {
25-
int x;
25+
_Atomic int x;
2626
int y;
2727
};
2828
} bar;
2929

3030
void fun(struct { int x; int y; } *param);
3131

32+
_Atomic(unsigned long) aul;
33+
3234
// RUN: c-index-test -test-print-type %s | FileCheck %s
3335
// CHECK: FunctionDecl=f:3:6 (Definition) [type=int *(int *, char *, FooType, int *, void (*)(int))] [typekind=FunctionProto] [canonicaltype=int *(int *, char *, int, int *, void (*)(int))] [canonicaltypekind=FunctionProto] [resulttype=int *] [resulttypekind=Pointer] [args= [int *] [Pointer] [char *] [Pointer] [FooType] [Typedef] [int [5]] [ConstantArray] [void (*)(int)] [Pointer]] [isPOD=0]
3436
// CHECK: ParmDecl=p:3:13 (Definition) [type=int *] [typekind=Pointer] [isPOD=1] [pointeetype=int] [pointeekind=Int]
@@ -70,4 +72,7 @@ void fun(struct { int x; int y; } *param);
7072
// CHECK: StructDecl=:18:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:18:1)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
7173
// CHECK: StructDecl=:23:1 (Definition) [type=struct (anonymous at {{.*}}print-type.c:23:1)] [typekind=Record] [isPOD=1] [nbFields=1] [isAnon=1] [isAnonRecDecl=0]
7274
// CHECK: StructDecl=:24:3 (Definition) [type=struct (anonymous at {{.*}}print-type.c:24:3)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=1]
75+
// CHECK: FieldDecl=x:25:17 (Definition) [type=_Atomic(int)] [typekind=Atomic] [valuetype=int] [valuetypekind=Int] [isPOD=0] [isAnonRecDecl=0]
76+
// CHECK: FieldDecl=y:26:9 (Definition) [type=int] [typekind=Int] [isPOD=1] [isAnonRecDecl=0]
7377
// CHECK: StructDecl=:30:10 (Definition) [type=struct (anonymous at {{.*}}print-type.c:30:10)] [typekind=Record] [isPOD=1] [nbFields=2] [isAnon=1] [isAnonRecDecl=0]
78+
// CHECK: VarDecl=aul:32:24 [type=_Atomic(unsigned long)] [typekind=Atomic] [valuetype=unsigned long] [valuetypekind=ULong] [isPOD=0] [isAnonRecDecl=0]

clang/tools/c-index-test/c-index-test.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,12 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p,
15791579
PrintTypeTemplateArgs(CT, " [canonicaltemplateargs/%d=");
15801580
}
15811581
}
1582+
/* Print the value type if it exists. */
1583+
{
1584+
CXType VT = clang_Type_getValueType(T);
1585+
if (VT.kind != CXType_Invalid)
1586+
PrintTypeAndTypeKind(VT, " [valuetype=%s] [valuetypekind=%s]");
1587+
}
15821588
/* Print the modified type if it exists. */
15831589
{
15841590
CXType MT = clang_Type_getModifiedType(T);

clang/tools/libclang/CXType.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static CXTypeKind GetTypeKind(QualType T) {
115115
TKCASE(Elaborated);
116116
TKCASE(Pipe);
117117
TKCASE(Attributed);
118+
TKCASE(Atomic);
118119
default:
119120
return CXType_Unexposed;
120121
}
@@ -616,6 +617,7 @@ CXString clang_getTypeKindSpelling(enum CXTypeKind K) {
616617
TKIND(OCLEvent);
617618
TKIND(OCLQueue);
618619
TKIND(OCLReserveID);
620+
TKIND(Atomic);
619621
}
620622
#undef TKIND
621623
return cxstring::createRef(s);
@@ -1318,3 +1320,13 @@ enum CXTypeNullabilityKind clang_Type_getNullability(CXType CT) {
13181320
}
13191321
return CXTypeNullability_Invalid;
13201322
}
1323+
1324+
CXType clang_Type_getValueType(CXType CT) {
1325+
QualType T = GetQualType(CT);
1326+
1327+
if (T.isNull() || !T->isAtomicType())
1328+
return MakeCXType(QualType(), GetTU(CT));
1329+
1330+
const auto *AT = T->castAs<AtomicType>();
1331+
return MakeCXType(AT->getValueType(), GetTU(CT));
1332+
}

clang/tools/libclang/libclang.exports

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ clang_Type_getNumObjCTypeArgs
109109
clang_Type_getObjCTypeArg
110110
clang_Type_getModifiedType
111111
clang_Type_getNullability
112+
clang_Type_getValueType
112113
clang_VerbatimBlockLineComment_getText
113114
clang_VerbatimLineComment_getText
114115
clang_HTMLTagComment_getAsString

0 commit comments

Comments
 (0)