summaryrefslogtreecommitdiff
path: root/tools/libclang
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2019-05-07 14:00:49 +0000
committerAaron Ballman <aaron@aaronballman.com>2019-05-07 14:00:49 +0000
commit81af6acbd988223940e497387e2a1bc7d8913ad7 (patch)
treecdcec358f9da7aadafde0e49704560c9c83ccee0 /tools/libclang
parentf16eeb943facb90735c606d63e18d9f31f5e77f8 (diff)
downloadclang-81af6acbd988223940e497387e2a1bc7d8913ad7.tar.gz
Allow field offset lookups in types with incomplete arrays within libclang.
Patch thanks to Jorn Vernee git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@360147 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/libclang')
-rw-r--r--tools/libclang/CXType.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/tools/libclang/CXType.cpp b/tools/libclang/CXType.cpp
index 6cb680a64d..47a9bb9c1d 100644
--- a/tools/libclang/CXType.cpp
+++ b/tools/libclang/CXType.cpp
@@ -885,6 +885,10 @@ long long clang_getArraySize(CXType CT) {
return result;
}
+static bool isIncompleteTypeWithAlignment(QualType QT) {
+ return QT->isIncompleteArrayType() || !QT->isIncompleteType();
+}
+
long long clang_Type_getAlignOf(CXType T) {
if (T.kind == CXType_Invalid)
return CXTypeLayoutError_Invalid;
@@ -895,7 +899,7 @@ long long clang_Type_getAlignOf(CXType T) {
// [expr.alignof] p3: if reference type, return size of referenced type
if (QT->isReferenceType())
QT = QT.getNonReferenceType();
- if (QT->isIncompleteType())
+ if (!isIncompleteTypeWithAlignment(QT))
return CXTypeLayoutError_Incomplete;
if (QT->isDependentType())
return CXTypeLayoutError_Dependent;
@@ -950,10 +954,14 @@ long long clang_Type_getSizeOf(CXType T) {
return Ctx.getTypeSizeInChars(QT).getQuantity();
}
+static bool isTypeIncompleteForLayout(QualType QT) {
+ return QT->isIncompleteType() && !QT->isIncompleteArrayType();
+}
+
static long long visitRecordForValidation(const RecordDecl *RD) {
for (const auto *I : RD->fields()){
QualType FQT = I->getType();
- if (FQT->isIncompleteType())
+ if (isTypeIncompleteForLayout(FQT))
return CXTypeLayoutError_Incomplete;
if (FQT->isDependentType())
return CXTypeLayoutError_Dependent;