emilio created this revision.
Herald added subscribers: cfe-commits, arphaman.
Herald added a project: clang.
When the type is not deducible, return an error instead of crashing.
This fixes https://bugs.llvm.org/show_bug.cgi?id=40813.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D58569
Files:
clang/include/clang-c/Index.h
clang/test/Index/print-type-size.cpp
clang/tools/c-index-test/c-index-test.c
clang/tools/libclang/CXType.cpp
Index: clang/tools/libclang/CXType.cpp
===================================================================
--- clang/tools/libclang/CXType.cpp
+++ clang/tools/libclang/CXType.cpp
@@ -891,6 +891,9 @@
return CXTypeLayoutError_Incomplete;
if (QT->isDependentType())
return CXTypeLayoutError_Dependent;
+ if (const auto *Deduced = dyn_cast<DeducedType>(QT))
+ if (Deduced->getDeducedType().isNull())
+ return CXTypeLayoutError_Undeduced;
// Exceptions by GCC extension - see ASTContext.cpp:1313 getTypeInfoImpl
// if (QT->isFunctionType()) return 4; // Bug #15511 - should be 1
// if (QT->isVoidType()) return 1;
@@ -928,6 +931,9 @@
return CXTypeLayoutError_Dependent;
if (!QT->isConstantSizeType())
return CXTypeLayoutError_NotConstantSize;
+ if (const auto *Deduced = dyn_cast<DeducedType>(QT))
+ if (Deduced->getDeducedType().isNull())
+ return CXTypeLayoutError_Undeduced;
// [gcc extension] lib/AST/ExprConstant.cpp:1372
// HandleSizeof : {voidtype,functype} == 1
// not handled by ASTContext.cpp:1313 getTypeInfoImpl
Index: clang/tools/c-index-test/c-index-test.c
===================================================================
--- clang/tools/c-index-test/c-index-test.c
+++ clang/tools/c-index-test/c-index-test.c
@@ -1670,29 +1670,44 @@
return CXChildVisit_Recurse;
}
-static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
- CXClientData d) {
- CXType T;
- enum CXCursorKind K = clang_getCursorKind(cursor);
- if (clang_isInvalid(K))
- return CXChildVisit_Recurse;
- T = clang_getCursorType(cursor);
- PrintCursor(cursor, NULL);
- PrintTypeAndTypeKind(T, " [type=%s] [typekind=%s]");
+static void PrintSingleTypeSize(CXType T, const char *TypeKindFormat,
+ const char *SizeFormat,
+ const char *AlignFormat) {
+ PrintTypeAndTypeKind(T, TypeKindFormat);
/* Print the type sizeof if applicable. */
{
long long Size = clang_Type_getSizeOf(T);
if (Size >= 0 || Size < -1 ) {
- printf(" [sizeof=%lld]", Size);
+ printf(SizeFormat, Size);
}
}
/* Print the type alignof if applicable. */
{
long long Align = clang_Type_getAlignOf(T);
if (Align >= 0 || Align < -1) {
- printf(" [alignof=%lld]", Align);
+ printf(AlignFormat, Align);
}
}
+
+ /* Print the return type if it exists. */
+ {
+ CXType RT = clang_getResultType(T);
+ if (RT.kind != CXType_Invalid)
+ PrintSingleTypeSize(RT, " [resulttype=%s] [resulttypekind=%s]",
+ " [resultsizeof=%lld]", " [resultalignof=%lld]");
+ }
+}
+
+static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p,
+ CXClientData d) {
+ CXType T;
+ enum CXCursorKind K = clang_getCursorKind(cursor);
+ if (clang_isInvalid(K))
+ return CXChildVisit_Recurse;
+ T = clang_getCursorType(cursor);
+ PrintCursor(cursor, NULL);
+ PrintSingleTypeSize(T, " [type=%s] [typekind=%s]", " [sizeof=%lld]",
+ " [alignof=%lld]");
/* Print the record field offset if applicable. */
{
CXString FieldSpelling = clang_getCursorSpelling(cursor);
@@ -1730,7 +1745,9 @@
if (IsBitfield)
printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor));
}
+
printf("\n");
+
return CXChildVisit_Recurse;
}
Index: clang/test/Index/print-type-size.cpp
===================================================================
--- clang/test/Index/print-type-size.cpp
+++ clang/test/Index/print-type-size.cpp
@@ -391,6 +391,10 @@
Foo<Sizes::A> t1;
Foo<Sizes::I> t2;
+class BrowsingContext {
+ auto Tie(void*) const;
+};
+
void c;
plopplop;
Index: clang/include/clang-c/Index.h
===================================================================
--- clang/include/clang-c/Index.h
+++ clang/include/clang-c/Index.h
@@ -3839,7 +3839,11 @@
/**
* The Field name is not valid for this record.
*/
- CXTypeLayoutError_InvalidFieldName = -5
+ CXTypeLayoutError_InvalidFieldName = -5,
+ /**
+ * The type is undeduced.
+ */
+ CXTypeLayoutError_Undeduced = -6
};
/**
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits