summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorVolodymyr Sapsai <vsapsai@apple.com>2019-03-29 18:47:07 +0000
committerVolodymyr Sapsai <vsapsai@apple.com>2019-03-29 18:47:07 +0000
commit9e911f3a6476e92f633436045528b1ac2e7d4161 (patch)
tree72ed466c4ea9d6148c737f6ca3d0467e2fceb02f /clang/lib
parent4ccb3b96b630b74ac016070b3d0da4b987ad9dc6 (diff)
downloadbcm5719-llvm-9e911f3a6476e92f633436045528b1ac2e7d4161.tar.gz
bcm5719-llvm-9e911f3a6476e92f633436045528b1ac2e7d4161.zip
[Sema] Fix assertion when `auto` parameter in lambda has an attribute.
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 Reviewers: rsmith, arphaman, aaron.ballman Reviewed By: aaron.ballman Subscribers: jkorous, dexonsmith, jdoerfert, cfe-commits Differential Revision: https://reviews.llvm.org/D58659 llvm-svn: 357298
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaType.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index d5516bc7a95..ba028b07e3b 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -255,6 +255,23 @@ namespace {
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) {
@@ -2938,7 +2955,7 @@ static QualType GetDeclSpecTypeForDeclarator(TypeProcessingState &state,
// 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;
OpenPOWER on IntegriCloud