summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ASTContext.cpp
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2009-02-22 01:38:57 +0000
committerAnders Carlsson <andersca@mac.com>2009-02-22 01:38:57 +0000
commitd05f44b5ca40284f09fe418df711fd969ccaa23b (patch)
tree6ccb18e6660c93ed1d19c805972dca57888858a8 /clang/lib/AST/ASTContext.cpp
parentf175ba1d17e7e6e38ad279dbc73acb3d75fb3f9f (diff)
downloadbcm5719-llvm-d05f44b5ca40284f09fe418df711fd969ccaa23b.tar.gz
bcm5719-llvm-d05f44b5ca40284f09fe418df711fd969ccaa23b.zip
Correctly encode incomplete and variable length arrays. Fixes PR3639.
llvm-svn: 65255
Diffstat (limited to 'clang/lib/AST/ASTContext.cpp')
-rw-r--r--clang/lib/AST/ASTContext.cpp27
1 files changed, 19 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()) {
OpenPOWER on IntegriCloud