Skip to content

Commit b0fcd3b

Browse files
author
huqizhi
committed
[Clang][Sema] fix crash of attribute transform
1 parent c87e94b commit b0fcd3b

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

clang/include/clang/AST/TypeLoc.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,10 @@ class AttributedTypeLoc : public ConcreteTypeLoc<UnqualTypeLoc,
884884
return getInnerTypeLoc();
885885
}
886886

887+
TypeLoc getEquivalentTypeLoc() const {
888+
return TypeLoc(getTypePtr()->getEquivalentType(), getNonLocalData());
889+
}
890+
887891
/// The type attribute.
888892
const Attr *getAttr() const {
889893
return getLocalData()->TypeAttr;

clang/lib/Sema/TreeTransform.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6124,7 +6124,11 @@ QualType TreeTransform<Derived>::TransformFunctionProtoType(
61246124
// "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
61256125
// and the end of the function-definition, member-declarator, or
61266126
// declarator.
6127-
Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
6127+
auto *RD =
6128+
dyn_cast_or_null<CXXRecordDecl>(SemaRef.getCurLexicalContext());
6129+
Sema::CXXThisScopeRAII ThisScope(
6130+
SemaRef, ThisContext == nullptr && nullptr != RD ? RD : ThisContext,
6131+
ThisTypeQuals);
61286132

61296133
ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
61306134
if (ResultType.isNull())
@@ -7081,10 +7085,10 @@ QualType TreeTransform<Derived>::TransformAttributedType(
70817085
// FIXME: dependent operand expressions?
70827086
if (getDerived().AlwaysRebuild() ||
70837087
modifiedType != oldType->getModifiedType()) {
7084-
// TODO: this is really lame; we should really be rebuilding the
7085-
// equivalent type from first principles.
7086-
QualType equivalentType
7087-
= getDerived().TransformType(oldType->getEquivalentType());
7088+
TypeLocBuilder AuxiliaryTLB;
7089+
AuxiliaryTLB.reserve(TL.getFullDataSize());
7090+
QualType equivalentType =
7091+
getDerived().TransformType(AuxiliaryTLB, TL.getEquivalentTypeLoc());
70887092
if (equivalentType.isNull())
70897093
return QualType();
70907094

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %clang_cc1 %s -verify -fsyntax-only
2+
3+
// expected-no-diagnostics
4+
5+
template<typename T>
6+
struct Bar {
7+
int* data;
8+
9+
auto operator[](const int index) const [[clang::lifetimebound]] -> decltype(data[index]) {
10+
return data[index];
11+
}
12+
};
13+
14+
int main() {
15+
Bar<int> b;
16+
(void)b[2];
17+
}

0 commit comments

Comments
 (0)