From 9ffd706bd4fd643dd9e4c8127ef34ecf5a121658 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 13 Apr 2010 23:45:47 +0000 Subject: [PATCH] Add encoding of reference types like gcc does for objc methods and blocks. Fixes PR6468. llvm-svn: 101196 --- clang/lib/AST/ASTContext.cpp | 11 +++++++--- clang/test/CodeGenCXX/reference-in-blocks.cpp | 21 +++++++++++++++++++ clang/test/CodeGenObjCXX/mangle.mm | 12 +++++++++++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 clang/test/CodeGenCXX/reference-in-blocks.cpp diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 1fa17f0b4b98..68620dc346bd 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -3494,13 +3494,18 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, return; } + // encoding for pointer or r3eference types. + QualType PointeeTy; if (const PointerType *PT = T->getAs()) { if (PT->isObjCSelType()) { S += ':'; return; } - QualType PointeeTy = PT->getPointeeType(); - + PointeeTy = PT->getPointeeType(); + } + else if (const ReferenceType *RT = T->getAs()) + PointeeTy = RT->getPointeeType(); + if (!PointeeTy.isNull()) { bool isReadOnly = false; // For historical/compatibility reasons, the read-only qualifier of the // pointee gets emitted _before_ the '^'. The read-only qualifier of @@ -3559,7 +3564,7 @@ void ASTContext::getObjCEncodingForTypeImpl(QualType T, std::string& S, NULL); return; } - + if (const ArrayType *AT = // Ignore type qualifiers etc. dyn_cast(T->getCanonicalTypeInternal())) { diff --git a/clang/test/CodeGenCXX/reference-in-blocks.cpp b/clang/test/CodeGenCXX/reference-in-blocks.cpp new file mode 100644 index 000000000000..ef09e4305b5c --- /dev/null +++ b/clang/test/CodeGenCXX/reference-in-blocks.cpp @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fblocks %s -emit-llvm + +extern "C" int printf(const char*, ...); + +template class range { +public: +T _i; + range(T i) {_i = i;}; + T get() {return _i;}; +}; + +int main() { + + // works + void (^bl)(range ) = ^(range i){printf("Hello Blocks %d\n", i.get()); }; + + //crashes in godegen? + void (^bl2)(range& ) = ^(range& i){printf("Hello Blocks %d\n", i.get()); }; + return 0; +} + diff --git a/clang/test/CodeGenObjCXX/mangle.mm b/clang/test/CodeGenObjCXX/mangle.mm index d277c4e51581..7a75a5b40e4c 100644 --- a/clang/test/CodeGenObjCXX/mangle.mm +++ b/clang/test/CodeGenObjCXX/mangle.mm @@ -2,6 +2,7 @@ // CHECK: @"_ZZ11+[A shared]E1a" = internal global // CHECK: @"_ZZ11-[A(Foo) f]E1a" = internal global +// CHECK: v56@0:8i16i20i24i28i32i36i40i44^i48 @interface A @end @@ -30,3 +31,14 @@ return 0; } @end + +// PR6468 +@interface Test +- (void) process: (int)r3 :(int)r4 :(int)r5 :(int)r6 :(int)r7 :(int)r8 :(int)r9 :(int)r10 :(int &)i; +@end + +@implementation Test +- (void) process: (int)r3 :(int)r4 :(int)r5 :(int)r6 :(int)r7 :(int)r8 :(int)r9 :(int)r10 :(int &)i { +} +@end + -- GitLab