Thanks for the quick fix. ASAN is happy now. --Artem
On Tue, Sep 13, 2016 at 3:09 PM, Manman <m...@apple.com> wrote: > I checked in r281404. Hopefully it will fix the issue. > > Let me know if it does not. > > Thanks, > Manman > > On Sep 13, 2016, at 3:03 PM, Artem Belevich via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > > Manman, > > FYI, It appears that some of your ObjC commits today trigger asan error. > Sanitizer bots are broken by PR30341, so they don't report the issue yet. > > --Artem > > $ llvm/tools/clang/clang -cc1 -internal-isystem > llvm/tools/clang/staging/include > -nostdsysteminc -fblocks -fsyntax-only -Wnullable-to-nonnull-conversion > llvm/tools/clang/test/SemaObjC/parameterized_classes_subst.m -verify > ================================================================= > ==223101==ERROR: AddressSanitizer: use-after-poison on address > 0x621000091288 at pc 0x000001a02b3f bp 0x7fffff2996f0 sp 0x7fffff2996e8 > WRITE of size 4 at 0x621000091288 thread T0 > #0 0x1a02b3e in clang::ObjCTypeParamTypeLoc:: > setProtocolRAngleLoc(clang::SourceLocation) third_party/llvm/llvm/tools/ > clang/include/clang/AST/TypeLoc.h:737:55 > #1 0x213f86b in > clang::Sema::actOnObjCTypeArgsAndProtocolQualifiers(clang::Scope*, > clang::SourceLocation, clang::OpaquePtr<clang::QualType>, > clang::SourceLocation, llvm::ArrayRef<clang::OpaquePtr<clang::QualType> > >, clang::SourceLocation, clang::SourceLocation, > llvm::ArrayRef<clang::Decl*>, llvm::ArrayRef<clang::SourceLocation>, > clang::SourceLocation) third_party/llvm/llvm/tools/ > clang/lib/Sema/SemaType.cpp:1165:13 > #2 0x2060347 in clang::Parser::parseObjCTypeArgsAndProtocolQu > alifiers(clang::SourceLocation, clang::OpaquePtr<clang::QualType>, bool, > clang::SourceLocation&) third_party/llvm/llvm/tools/ > clang/lib/Parse/ParseObjc.cpp:1878:18 > #3 0x1ffca6f in > clang::Parser::TryAnnotateTypeOrScopeTokenAfterScopeSpec(bool, > bool, clang::CXXScopeSpec&, bool) third_party/llvm/llvm/tools/ > clang/lib/Parse/Parser.cpp:1770:13 > #4 0x1ffd4fc in clang::Parser::TryAnnotateTypeOrScopeToken(bool, > bool) third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:1733:10 > #5 0x20df910 in clang::Parser::isTypeSpecifierQualifier() > third_party/llvm/llvm/tools/clang/lib/Parse/ParseDecl.cpp:4381:9 > #6 0x205ecf5 in clang::Parser::ParseObjCTypeName(clang::ObjCDeclSpec&, > clang::Declarator::TheContext, clang::ParsedAttributes*) > third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1274:7 > #7 0x205c8f9 in clang::Parser::ParseObjCMethodDecl(clang::SourceLocation, > clang::tok::TokenKind, clang::tok::ObjCKeywordKind, bool) > third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:1428:22 > #8 0x2058e8b in > clang::Parser::ParseObjCInterfaceDeclList(clang::tok::ObjCKeywordKind, > clang::Decl*) third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp: > 633:11 > #9 0x2053154 in > clang::Parser::ParseObjCAtInterfaceDeclaration(clang::SourceLocation, > clang::ParsedAttributes&) third_party/llvm/llvm/tools/ > clang/lib/Parse/ParseObjc.cpp:388:3 > #10 0x2051fa9 in clang::Parser::ParseObjCAtDirectives() > third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:63:18 > #11 0x1ff7871 in clang::Parser::ParseExternalDeclaration( > clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) > third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:757:12 > #12 0x1ff6c61 in clang::Parser::ParseTopLevelDecl(clang:: > OpaquePtr<clang::DeclGroupRef>&) third_party/llvm/llvm/tools/ > clang/lib/Parse/Parser.cpp:628:12 > #13 0x1ff016d in clang::ParseAST(clang::Sema&, bool, bool) > third_party/llvm/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18 > #14 0x1ab05d3 in clang::FrontendAction::Execute() > third_party/llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:458:8 > #15 0x184fbd6 in > clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) > third_party/llvm/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:871:11 > #16 0x5c6f47 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) > third_party/llvm/llvm/tools/clang/lib/FrontendTool/ > ExecuteCompilerInvocation.cpp:249:25 > #17 0x5a114d in cc1_main(llvm::ArrayRef<char const*>, char const*, > void*) third_party/llvm/llvm/tools/clang/tools/driver/cc1_main.cpp:183:13 > #18 0x5bb3f6 in ExecuteCC1Tool(llvm::ArrayRef<char const*>, > llvm::StringRef) third_party/llvm/llvm/tools/ > clang/tools/driver/driver.cpp:299:12 > #19 0x5ba314 in main third_party/llvm/llvm/tools/ > clang/tools/driver/driver.cpp:380:12 > > 0x621000091288 is located 392 bytes inside of 4096-byte region > [0x621000091100,0x621000092100) > allocated by thread T0 here: > #0 0x58a52c in __interceptor_malloc third_party/llvm/llvm/ > projects/compiler-rt/lib/asan/asan_malloc_linux.cc:64:3 > #1 0x5a5d0b in llvm::MallocAllocator::Allocate(unsigned long, > unsigned long) third_party/llvm/llvm/include/ > llvm/Support/Allocator.h:95:12 > #2 0x691b67 in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, > 4096ul, 4096ul>::StartNewSlab() third_party/llvm/llvm/include/ > llvm/Support/Allocator.h:324:31 > #3 0x6916aa in llvm::BumpPtrAllocatorImpl<llvm::MallocAllocator, > 4096ul, 4096ul>::Allocate(unsigned long, unsigned long) > third_party/llvm/llvm/include/llvm/Support/Allocator.h:249:5 > #4 0x6913d1 in clang::ASTContext::Allocate(unsigned long, unsigned > int) const third_party/llvm/llvm/tools/clang/include/clang/AST/ > ASTContext.h:588:22 > #5 0x3010c16 in clang::ObjCInterfaceDecl::Create(clang::ASTContext > const&, clang::DeclContext*, clang::SourceLocation, clang::IdentifierInfo*, > clang::ObjCTypeParamList*, clang::ObjCInterfaceDecl*, > clang::SourceLocation, bool) third_party/llvm/llvm/tools/ > clang/lib/AST/DeclObjC.cpp:1396:31 > #6 0x2838c96 in clang::Sema::ActOnStartClassInterface(clang::Scope*, > clang::SourceLocation, clang::IdentifierInfo*, clang::SourceLocation, > clang::ObjCTypeParamList*, clang::IdentifierInfo*, clang::SourceLocation, > llvm::ArrayRef<clang::OpaquePtr<clang::QualType> >, clang::SourceRange, > clang::Decl* const*, unsigned int, clang::SourceLocation const*, > clang::SourceLocation, clang::AttributeList*) third_party/llvm/llvm/tools/ > clang/lib/Sema/SemaDeclObjC.cpp:981:7 > #7 0x2053112 in > clang::Parser::ParseObjCAtInterfaceDeclaration(clang::SourceLocation, > clang::ParsedAttributes&) third_party/llvm/llvm/tools/ > clang/lib/Parse/ParseObjc.cpp:375:13 > #8 0x2051fa9 in clang::Parser::ParseObjCAtDirectives() > third_party/llvm/llvm/tools/clang/lib/Parse/ParseObjc.cpp:63:18 > #9 0x1ff7871 in clang::Parser::ParseExternalDeclaration( > clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) > third_party/llvm/llvm/tools/clang/lib/Parse/Parser.cpp:757:12 > #10 0x1ff6c61 in clang::Parser::ParseTopLevelDecl(clang:: > OpaquePtr<clang::DeclGroupRef>&) third_party/llvm/llvm/tools/ > clang/lib/Parse/Parser.cpp:628:12 > #11 0x1ff016d in clang::ParseAST(clang::Sema&, bool, bool) > third_party/llvm/llvm/tools/clang/lib/Parse/ParseAST.cpp:147:18 > #12 0x1ab05d3 in clang::FrontendAction::Execute() > third_party/llvm/llvm/tools/clang/lib/Frontend/FrontendAction.cpp:458:8 > #13 0x184fbd6 in > clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) > third_party/llvm/llvm/tools/clang/lib/Frontend/CompilerInstance.cpp:871:11 > #14 0x5c6f47 in clang::ExecuteCompilerInvocation(clang::CompilerInstance*) > third_party/llvm/llvm/tools/clang/lib/FrontendTool/ > ExecuteCompilerInvocation.cpp:249:25 > #15 0x5a114d in cc1_main(llvm::ArrayRef<char const*>, char const*, > void*) third_party/llvm/llvm/tools/clang/tools/driver/cc1_main.cpp:183:13 > #16 0x5bb3f6 in ExecuteCC1Tool(llvm::ArrayRef<char const*>, > llvm::StringRef) third_party/llvm/llvm/tools/ > clang/tools/driver/driver.cpp:299:12 > #17 0x5ba314 in main third_party/llvm/llvm/tools/ > clang/tools/driver/driver.cpp:380:12 > > SUMMARY: AddressSanitizer: use-after-poison third_party/llvm/llvm/tools/ > clang/include/clang/AST/TypeLoc.h:737:55 in clang::ObjCTypeParamTypeLoc:: > setProtocolRAngleLoc(clang::SourceLocation) > Shadow bytes around the buggy address: > 0x0c428000a200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa > 0x0c428000a210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa > 0x0c428000a220: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 0x0c428000a230: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 > 0x0c428000a240: 00 00 00 04 00 04 00 04 00 00 00 00 00 00 00 00 > =>0x0c428000a250: 00[f7]f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 > 0x0c428000a260: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 > 0x0c428000a270: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 > 0x0c428000a280: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 > 0x0c428000a290: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 > 0x0c428000a2a0: f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 f7 > Shadow byte legend (one shadow byte represents 8 application bytes): > Addressable: 00 > Partially addressable: 01 02 03 04 05 06 07 > Heap left redzone: fa > Heap right redzone: fb > Freed heap region: fd > Stack left redzone: f1 > Stack mid redzone: f2 > Stack right redzone: f3 > Stack partial redzone: f4 > Stack after return: f5 > Stack use after scope: f8 > Global redzone: f9 > Global init order: f6 > Poisoned by user: f7 > Container overflow: fc > Array cookie: ac > Intra object redzone: bb > ASan internal: fe > Left alloca redzone: ca > Right alloca redzone: cb > > On Tue, Sep 13, 2016 at 9:45 AM, Manman Ren via cfe-commits < > cfe-commits@lists.llvm.org> wrote: > >> Author: mren >> Date: Tue Sep 13 11:45:29 2016 >> New Revision: 281351 >> >> URL: http://llvm.org/viewvc/llvm-project?rev=281351&view=rev >> Log: >> Add a class ObjCProtocolQualifiers to wrap APIs for ObjC protocol list. >> >> Now ObjCObjectType extends from ObjCProtocolQualifiers. We save number of >> protocols in ObjCProtocolQualifiers. >> >> This is in preparation of adding a new type class ObjCTypeParamType that >> can take protocol qualifiers. >> >> rdar://24619481 >> rdar://25060179 >> >> Differential Revision: http://reviews.llvm.org/D23078 >> >> Modified: >> cfe/trunk/include/clang/AST/Type.h >> cfe/trunk/lib/AST/Type.cpp >> >> Modified: cfe/trunk/include/clang/AST/Type.h >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ >> AST/Type.h?rev=281351&r1=281350&r2=281351&view=diff >> ============================================================ >> ================== >> --- cfe/trunk/include/clang/AST/Type.h (original) >> +++ cfe/trunk/include/clang/AST/Type.h Tue Sep 13 11:45:29 2016 >> @@ -4699,6 +4699,59 @@ public: >> } >> }; >> >> +/// This class wraps the list of protocol qualifiers. For types that can >> +/// take ObjC protocol qualifers, they can subclass this class. >> +template <class T> >> +class ObjCProtocolQualifiers { >> +protected: >> + ObjCProtocolQualifiers() {} >> + ObjCProtocolDecl * const *getProtocolStorage() const { >> + return const_cast<ObjCProtocolQualifiers*>(this)-> >> getProtocolStorage(); >> + } >> + >> + ObjCProtocolDecl **getProtocolStorage() { >> + return static_cast<T*>(this)->getProtocolStorageImpl(); >> + } >> + void setNumProtocols(unsigned N) { >> + static_cast<T*>(this)->setNumProtocolsImpl(N); >> + } >> + void initialize(ArrayRef<ObjCProtocolDecl *> protocols) { >> + setNumProtocols(protocols.size()); >> + assert(getNumProtocols() == protocols.size() && >> + "bitfield overflow in protocol count"); >> + if (!protocols.empty()) >> + memcpy(getProtocolStorage(), protocols.data(), >> + protocols.size() * sizeof(ObjCProtocolDecl*)); >> + } >> + >> +public: >> + typedef ObjCProtocolDecl * const *qual_iterator; >> + typedef llvm::iterator_range<qual_iterator> qual_range; >> + >> + qual_range quals() const { return qual_range(qual_begin(), >> qual_end()); } >> + qual_iterator qual_begin() const { return getProtocolStorage(); } >> + qual_iterator qual_end() const { return qual_begin() + >> getNumProtocols(); } >> + >> + bool qual_empty() const { return getNumProtocols() == 0; } >> + >> + /// Return the number of qualifying protocols in this type, or 0 if >> + /// there are none. >> + unsigned getNumProtocols() const { >> + return static_cast<const T*>(this)->getNumProtocolsImpl(); >> + } >> + >> + /// Fetch a protocol by index. >> + ObjCProtocolDecl *getProtocol(unsigned I) const { >> + assert(I < getNumProtocols() && "Out-of-range protocol access"); >> + return qual_begin()[I]; >> + } >> + >> + /// Retrieve all of the protocol qualifiers. >> + ArrayRef<ObjCProtocolDecl *> getProtocols() const { >> + return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols()); >> + } >> +}; >> + >> /// Represents a class type in Objective C. >> /// >> /// Every Objective C type is a combination of a base type, a set of >> @@ -4727,7 +4780,9 @@ public: >> /// 'id<P>' is an ObjCObjectPointerType whose pointee is an >> ObjCObjectType >> /// with base BuiltinType::ObjCIdType and protocol list [P]. Eventually >> /// this should get its own sugar class to better represent the source. >> -class ObjCObjectType : public Type { >> +class ObjCObjectType : public Type, >> + public ObjCProtocolQualifiers<ObjCObjectType> { >> + friend class ObjCProtocolQualifiers<ObjCObjectType>; >> // ObjCObjectType.NumTypeArgs - the number of type arguments stored >> // after the ObjCObjectPointerType node. >> // ObjCObjectType.NumProtocols - the number of protocols stored >> @@ -4747,16 +4802,20 @@ class ObjCObjectType : public Type { >> mutable llvm::PointerIntPair<const ObjCObjectType *, 1, bool> >> CachedSuperClassType; >> >> - ObjCProtocolDecl * const *getProtocolStorage() const { >> - return const_cast<ObjCObjectType*>(this)->getProtocolStorage(); >> - } >> - >> QualType *getTypeArgStorage(); >> const QualType *getTypeArgStorage() const { >> return const_cast<ObjCObjectType *>(this)->getTypeArgStorage(); >> } >> >> - ObjCProtocolDecl **getProtocolStorage(); >> + ObjCProtocolDecl **getProtocolStorageImpl(); >> + /// Return the number of qualifying protocols in this interface type, >> + /// or 0 if there are none. >> + unsigned getNumProtocolsImpl() const { >> + return ObjCObjectTypeBits.NumProtocols; >> + } >> + void setNumProtocolsImpl(unsigned N) { >> + ObjCObjectTypeBits.NumProtocols = N; >> + } >> >> protected: >> ObjCObjectType(QualType Canonical, QualType Base, >> @@ -4833,30 +4892,6 @@ public: >> ObjCObjectTypeBits.NumTypeArgs); >> } >> >> - typedef ObjCProtocolDecl * const *qual_iterator; >> - typedef llvm::iterator_range<qual_iterator> qual_range; >> - >> - qual_range quals() const { return qual_range(qual_begin(), >> qual_end()); } >> - qual_iterator qual_begin() const { return getProtocolStorage(); } >> - qual_iterator qual_end() const { return qual_begin() + >> getNumProtocols(); } >> - >> - bool qual_empty() const { return getNumProtocols() == 0; } >> - >> - /// Return the number of qualifying protocols in this interface type, >> - /// or 0 if there are none. >> - unsigned getNumProtocols() const { return >> ObjCObjectTypeBits.NumProtocols; } >> - >> - /// Fetch a protocol by index. >> - ObjCProtocolDecl *getProtocol(unsigned I) const { >> - assert(I < getNumProtocols() && "Out-of-range protocol access"); >> - return qual_begin()[I]; >> - } >> - >> - /// Retrieve all of the protocol qualifiers. >> - ArrayRef<ObjCProtocolDecl *> getProtocols() const { >> - return ArrayRef<ObjCProtocolDecl *>(qual_begin(), getNumProtocols()); >> - } >> - >> /// Whether this is a "__kindof" type as written. >> bool isKindOfTypeAsWritten() const { return >> ObjCObjectTypeBits.IsKindOf; } >> >> @@ -4919,7 +4954,7 @@ inline QualType *ObjCObjectType::getType >> return reinterpret_cast<QualType *>(static_cast<ObjCObjectTypeI >> mpl*>(this)+1); >> } >> >> -inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorage() { >> +inline ObjCProtocolDecl **ObjCObjectType::getProtocolStorageImpl() { >> return reinterpret_cast<ObjCProtocolDecl**>( >> getTypeArgStorage() + ObjCObjectTypeBits.NumTypeArgs); >> } >> >> Modified: cfe/trunk/lib/AST/Type.cpp >> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type. >> cpp?rev=281351&r1=281350&r2=281351&view=diff >> ============================================================ >> ================== >> --- cfe/trunk/lib/AST/Type.cpp (original) >> +++ cfe/trunk/lib/AST/Type.cpp Tue Sep 13 11:45:29 2016 >> @@ -546,15 +546,9 @@ ObjCObjectType::ObjCObjectType(QualType >> ObjCObjectTypeBits.NumTypeArgs = typeArgs.size(); >> assert(getTypeArgsAsWritten().size() == typeArgs.size() && >> "bitfield overflow in type argument count"); >> - ObjCObjectTypeBits.NumProtocols = protocols.size(); >> - assert(getNumProtocols() == protocols.size() && >> - "bitfield overflow in protocol count"); >> if (!typeArgs.empty()) >> memcpy(getTypeArgStorage(), typeArgs.data(), >> typeArgs.size() * sizeof(QualType)); >> - if (!protocols.empty()) >> - memcpy(getProtocolStorage(), protocols.data(), >> - protocols.size() * sizeof(ObjCProtocolDecl*)); >> >> for (auto typeArg : typeArgs) { >> if (typeArg->isDependentType()) >> @@ -565,6 +559,9 @@ ObjCObjectType::ObjCObjectType(QualType >> if (typeArg->containsUnexpandedParameterPack()) >> setContainsUnexpandedParameterPack(); >> } >> + // Initialize the protocol qualifiers. The protocol storage is known >> + // after we set number of type arguments. >> + initialize(protocols); >> } >> >> bool ObjCObjectType::isSpecialized() const { >> >> >> _______________________________________________ >> cfe-commits mailing list >> cfe-commits@lists.llvm.org >> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits >> > > > > -- > --Artem Belevich > _______________________________________________ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits > > > -- --Artem Belevich
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits