vsapsai created this revision. vsapsai added reviewers: rsmith, arphaman. Herald added subscribers: jdoerfert, dexonsmith, jkorous.
Fixes the assertion > no Attr* for AttributedType* > UNREACHABLE executed at llvm-project/clang/lib/Sema/SemaType.cpp:298! In `TypeProcessingState::getAttributedType` we put into `AttrsForTypes` types with `auto` but later in `TypeProcessingState::takeAttrForAttributedType` we use transformed types and that's why cannot find `Attr` corresponding to `AttributedType`. Fix by keeping `AttrsForTypes` up to date after replacing `AutoType`. rdar://problem/47689465 https://reviews.llvm.org/D58659 Files: clang/lib/Sema/SemaType.cpp clang/test/SemaCXX/auto-cxx0x.cpp Index: clang/test/SemaCXX/auto-cxx0x.cpp =================================================================== --- clang/test/SemaCXX/auto-cxx0x.cpp +++ clang/test/SemaCXX/auto-cxx0x.cpp @@ -15,3 +15,11 @@ // expected-error@-2 {{'auto' not allowed in lambda parameter}} #endif } + +void rdar47689465() { + int x = 0; + [](auto __attribute__((noderef)) *){}(&x); +#if __cplusplus == 201103L + // expected-error@-2 {{'auto' not allowed in lambda parameter}} +#endif +} Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -255,6 +255,23 @@ return T; } + /// Completely replace the \c auto in \p TypeWithAuto by + /// \p Replacement. Also replace \p TypeWithAuto in \c TypeAttrPair if + /// necessary. + QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement) { + QualType T = sema.ReplaceAutoType(TypeWithAuto, Replacement); + if (auto *AttrTy = TypeWithAuto->getAs<AttributedType>()) { + // Attributed type still should be an attributed type after replacement. + auto *NewAttrTy = cast<AttributedType>(T.getTypePtr()); + for (TypeAttrPair &A : AttrsForTypes) { + if (A.first == AttrTy) + A.first = NewAttrTy; + } + AttrsForTypesSorted = false; + } + return T; + } + /// Extract and remove the Attr* for a given attributed type. const Attr *takeAttrForAttributedType(const AttributedType *AT) { if (!AttrsForTypesSorted) { @@ -2935,7 +2952,7 @@ // template type parameter. // FIXME: Retain some type sugar to indicate that this was written // as 'auto'. - T = SemaRef.ReplaceAutoType( + T = state.ReplaceAutoType( T, QualType(CorrespondingTemplateParam->getTypeForDecl(), 0)); } break;
Index: clang/test/SemaCXX/auto-cxx0x.cpp =================================================================== --- clang/test/SemaCXX/auto-cxx0x.cpp +++ clang/test/SemaCXX/auto-cxx0x.cpp @@ -15,3 +15,11 @@ // expected-error@-2 {{'auto' not allowed in lambda parameter}} #endif } + +void rdar47689465() { + int x = 0; + [](auto __attribute__((noderef)) *){}(&x); +#if __cplusplus == 201103L + // expected-error@-2 {{'auto' not allowed in lambda parameter}} +#endif +} Index: clang/lib/Sema/SemaType.cpp =================================================================== --- clang/lib/Sema/SemaType.cpp +++ clang/lib/Sema/SemaType.cpp @@ -255,6 +255,23 @@ return T; } + /// Completely replace the \c auto in \p TypeWithAuto by + /// \p Replacement. Also replace \p TypeWithAuto in \c TypeAttrPair if + /// necessary. + QualType ReplaceAutoType(QualType TypeWithAuto, QualType Replacement) { + QualType T = sema.ReplaceAutoType(TypeWithAuto, Replacement); + if (auto *AttrTy = TypeWithAuto->getAs<AttributedType>()) { + // Attributed type still should be an attributed type after replacement. + auto *NewAttrTy = cast<AttributedType>(T.getTypePtr()); + for (TypeAttrPair &A : AttrsForTypes) { + if (A.first == AttrTy) + A.first = NewAttrTy; + } + AttrsForTypesSorted = false; + } + return T; + } + /// Extract and remove the Attr* for a given attributed type. const Attr *takeAttrForAttributedType(const AttributedType *AT) { if (!AttrsForTypesSorted) { @@ -2935,7 +2952,7 @@ // template type parameter. // FIXME: Retain some type sugar to indicate that this was written // as 'auto'. - T = SemaRef.ReplaceAutoType( + T = state.ReplaceAutoType( T, QualType(CorrespondingTemplateParam->getTypeForDecl(), 0)); } break;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits