diff options
author | Emilio Cobos Alvarez <emilio@crisal.io> | 2019-02-26 15:04:18 +0000 |
---|---|---|
committer | Emilio Cobos Alvarez <emilio@crisal.io> | 2019-02-26 15:04:18 +0000 |
commit | 0d76dc285c17c3e87994e46e4e0dc8383c755e4b (patch) | |
tree | 6df0b7408f9c6ba05a6594c1fd3c76994539fb04 /clang/tools/c-index-test/c-index-test.c | |
parent | 582d46328ce644d791f4dce31b005fc260d33611 (diff) | |
download | llvm-0d76dc285c17c3e87994e46e4e0dc8383c755e4b.zip llvm-0d76dc285c17c3e87994e46e4e0dc8383c755e4b.tar.gz llvm-0d76dc285c17c3e87994e46e4e0dc8383c755e4b.tar.bz2 |
[libclang] Avoid crashing when getting layout info of an undeduced type.
When the type is not deducible, return an error instead of crashing.
This fixes https://bugs.llvm.org/show_bug.cgi?id=40813.
Differential Revision: https://reviews.llvm.org/D58569
llvm-svn: 354885
Diffstat (limited to 'clang/tools/c-index-test/c-index-test.c')
-rw-r--r-- | clang/tools/c-index-test/c-index-test.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c index fc6ba46..2cf442e 100644 --- a/clang/tools/c-index-test/c-index-test.c +++ b/clang/tools/c-index-test/c-index-test.c @@ -1670,29 +1670,44 @@ static enum CXChildVisitResult PrintType(CXCursor cursor, CXCursor p, 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 @@ static enum CXChildVisitResult PrintTypeSize(CXCursor cursor, CXCursor p, if (IsBitfield) printf(" [BitFieldSize=%d]", clang_getFieldDeclBitWidth(cursor)); } + printf("\n"); + return CXChildVisit_Recurse; } |