diff options
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/AST/ASTContext.cpp | 27 | ||||
| -rw-r--r-- | clang/test/CodeGenObjC/encode-test-3.m | 11 |
2 files changed, 30 insertions, 8 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 605f46b44bf..181ea906911 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -2214,16 +2214,27 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, } else if (const ArrayType *AT = // Ignore type qualifiers etc. dyn_cast<ArrayType>(T->getCanonicalTypeInternal())) { - S += '['; + if (isa<IncompleteArrayType>(AT)) { + // Incomplete arrays are encoded as a pointer to the array element. + S += '^'; + + getObjCEncodingForTypeImpl(AT->getElementType(), S, + false, ExpandStructures, FD); + } else { + S += '['; - if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) - S += llvm::utostr(CAT->getSize().getZExtValue()); - else - assert(0 && "Unhandled array type!"); + if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(AT)) + S += llvm::utostr(CAT->getSize().getZExtValue()); + else { + //Variable length arrays are encoded as a regular array with 0 elements. + assert(isa<VariableArrayType>(AT) && "Unknown array type!"); + S += '0'; + } - getObjCEncodingForTypeImpl(AT->getElementType(), S, - false, ExpandStructures, FD); - S += ']'; + getObjCEncodingForTypeImpl(AT->getElementType(), S, + false, ExpandStructures, FD); + S += ']'; + } } else if (T->getAsFunctionType()) { S += '?'; } else if (const RecordType *RTy = T->getAsRecordType()) { diff --git a/clang/test/CodeGenObjC/encode-test-3.m b/clang/test/CodeGenObjC/encode-test-3.m new file mode 100644 index 00000000000..8bd4421d6c1 --- /dev/null +++ b/clang/test/CodeGenObjC/encode-test-3.m @@ -0,0 +1,11 @@ +// RUN: clang -triple=i686-apple-darwin9 -fnext-runtime -emit-llvm -o %t %s && +// RUN: grep -e "\^i" %t | count 1 && +// RUN: grep -e "\[0i\]" %t | count 1 + +int main() +{ + int n; + + const char * inc = @encode(int[]); + const char * vla = @encode(int[n]); +} |

