diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-05-14 20:32:39 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-05-14 20:32:39 +0000 |
commit | 7da04c636728570fc66e9a2fc605d8674738b602 (patch) | |
tree | 3bbe137754812536fda7dba9b70f5f75ca1e0b6d /clang/lib/Sema/SemaExprObjC.cpp | |
parent | cb7e56e592b769daa459838db54066db1ce6d766 (diff) | |
download | bcm5719-llvm-7da04c636728570fc66e9a2fc605d8674738b602.tar.gz bcm5719-llvm-7da04c636728570fc66e9a2fc605d8674738b602.zip |
Emit an error when trying to @encode an incomplete type.
There are APIs, e.g. [NSValue valueWithBytes:objCType:], which use the encoding to find out
the size of an object pointed to by a pointer. Make things safer by making it illegal to @encode
incomplete types.
llvm-svn: 131364
Diffstat (limited to 'clang/lib/Sema/SemaExprObjC.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExprObjC.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 2a262f09392..3444cb5a494 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/lib/Sema/SemaExprObjC.cpp @@ -119,7 +119,7 @@ ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs, return new (Context) ObjCStringLiteral(S, Ty, AtLocs[0]); } -Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, +ExprResult Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, TypeSourceInfo *EncodedTypeInfo, SourceLocation RParenLoc) { QualType EncodedType = EncodedTypeInfo->getType(); @@ -127,6 +127,12 @@ Expr *Sema::BuildObjCEncodeExpression(SourceLocation AtLoc, if (EncodedType->isDependentType()) StrTy = Context.DependentTy; else { + if (!EncodedType->getAsArrayTypeUnsafe()) // Incomplete array is handled. + if (RequireCompleteType(AtLoc, EncodedType, + PDiag(diag::err_incomplete_type_objc_at_encode) + << EncodedTypeInfo->getTypeLoc().getSourceRange())) + return ExprError(); + std::string Str; Context.getObjCEncodingForType(EncodedType, Str); |