[cfe-commits] r65255 - in /cfe/trunk: lib/AST/ASTContext.cpp test/CodeGenObjC/encode-test-3.m
Anders Carlsson
andersca at mac.com
Sat Feb 21 17:38:57 PST 2009
Author: andersca
Date: Sat Feb 21 19:38:57 2009
New Revision: 65255
URL: http://llvm.org/viewvc/llvm-project?rev=65255&view=rev
Log:
Correctly encode incomplete and variable length arrays. Fixes PR3639.
Added:
cfe/trunk/test/CodeGenObjC/encode-test-3.m
Modified:
cfe/trunk/lib/AST/ASTContext.cpp
Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=65255&r1=65254&r2=65255&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat Feb 21 19:38:57 2009
@@ -2214,16 +2214,27 @@
} 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()) {
Added: cfe/trunk/test/CodeGenObjC/encode-test-3.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/encode-test-3.m?rev=65255&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/encode-test-3.m (added)
+++ cfe/trunk/test/CodeGenObjC/encode-test-3.m Sat Feb 21 19:38:57 2009
@@ -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]);
+}
More information about the cfe-commits
mailing list