Skip to content

Commit f95bd18

Browse files
committed
Revert "[Attr] support btf_type_tag attribute"
This reverts commits 737e421 and ce7ac9e. After those commits, the compiler can crash with a reduced testcase like this: $ cat reduced.c void a(*); void a() {} $ clang -c reduced.c -O2 -g
1 parent 7af584e commit f95bd18

File tree

9 files changed

+55
-361
lines changed

9 files changed

+55
-361
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 35 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -929,28 +929,8 @@ static llvm::dwarf::Tag getNextQualifier(Qualifiers &Q) {
929929
return (llvm::dwarf::Tag)0;
930930
}
931931

932-
// Strip MacroQualifiedTypeLoc and AttributedTypeLoc
933-
// as their corresponding types will be ignored
934-
// during code generation. Stripping them allows
935-
// to maintain proper TypeLoc for a given type
936-
// during code generation.
937-
static TypeLoc StripMacroAttributed(TypeLoc TL) {
938-
if (!TL)
939-
return TL;
940-
941-
while (true) {
942-
if (auto MTL = TL.getAs<MacroQualifiedTypeLoc>())
943-
TL = MTL.getInnerLoc();
944-
else if (auto ATL = TL.getAs<AttributedTypeLoc>())
945-
TL = ATL.getModifiedLoc();
946-
else
947-
break;
948-
}
949-
return TL;
950-
}
951-
952-
llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile *Unit,
953-
TypeLoc TL) {
932+
llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty,
933+
llvm::DIFile *Unit) {
954934
QualifierCollector Qc;
955935
const Type *T = Qc.strip(Ty);
956936

@@ -964,15 +944,7 @@ llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DIFile *Unit,
964944
return getOrCreateType(QualType(T, 0), Unit);
965945
}
966946

967-
QualType NextTy = Qc.apply(CGM.getContext(), T);
968-
TypeLoc NextTL;
969-
if (NextTy.hasQualifiers())
970-
NextTL = TL;
971-
else if (TL) {
972-
if (auto QTL = TL.getAs<QualifiedTypeLoc>())
973-
NextTL = StripMacroAttributed(QTL.getNextTypeLoc());
974-
}
975-
auto *FromTy = getOrCreateType(NextTy, Unit, NextTL);
947+
auto *FromTy = getOrCreateType(Qc.apply(CGM.getContext(), T), Unit);
976948

977949
// No need to fill in the Name, Line, Size, Alignment, Offset in case of
978950
// CVR derived types.
@@ -1016,10 +988,10 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
1016988
Ty->getPointeeType(), Unit);
1017989
}
1018990

1019-
llvm::DIType *CGDebugInfo::CreateType(const PointerType *Ty, llvm::DIFile *Unit,
1020-
TypeLoc TL) {
991+
llvm::DIType *CGDebugInfo::CreateType(const PointerType *Ty,
992+
llvm::DIFile *Unit) {
1021993
return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1022-
Ty->getPointeeType(), Unit, TL);
994+
Ty->getPointeeType(), Unit);
1023995
}
1024996

1025997
/// \return whether a C++ mangling exists for the type defined by TD.
@@ -1160,8 +1132,7 @@ CGDebugInfo::getOrCreateRecordFwdDecl(const RecordType *Ty,
11601132
llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
11611133
const Type *Ty,
11621134
QualType PointeeTy,
1163-
llvm::DIFile *Unit,
1164-
TypeLoc TL) {
1135+
llvm::DIFile *Unit) {
11651136
// Bit size, align and offset of the type.
11661137
// Size is always the size of a pointer. We can't use getTypeSize here
11671138
// because that does not return the correct value for references.
@@ -1171,52 +1142,13 @@ llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
11711142
Optional<unsigned> DWARFAddressSpace =
11721143
CGM.getTarget().getDWARFAddressSpace(AddressSpace);
11731144

1174-
llvm::DINodeArray Annotations = nullptr;
1175-
TypeLoc NextTL;
1176-
if (TL) {
1177-
SmallVector<llvm::Metadata *, 4> Annots;
1178-
NextTL = TL.getNextTypeLoc();
1179-
if (NextTL) {
1180-
// Traverse all MacroQualifiedTypeLoc, QualifiedTypeLoc and
1181-
// AttributedTypeLoc type locations so we can collect
1182-
// BTFTypeTag attributes for this pointer.
1183-
while (true) {
1184-
if (auto MTL = NextTL.getAs<MacroQualifiedTypeLoc>()) {
1185-
NextTL = MTL.getInnerLoc();
1186-
} else if (auto QTL = NextTL.getAs<QualifiedTypeLoc>()) {
1187-
NextTL = QTL.getNextTypeLoc();
1188-
} else if (auto ATL = NextTL.getAs<AttributedTypeLoc>()) {
1189-
if (const auto *A = ATL.getAttrAs<BTFTypeTagAttr>()) {
1190-
StringRef BTFTypeTag = A->getBTFTypeTag();
1191-
if (!BTFTypeTag.empty()) {
1192-
llvm::Metadata *Ops[2] = {
1193-
llvm::MDString::get(CGM.getLLVMContext(),
1194-
StringRef("btf_type_tag")),
1195-
llvm::MDString::get(CGM.getLLVMContext(), BTFTypeTag)};
1196-
Annots.insert(Annots.begin(),
1197-
llvm::MDNode::get(CGM.getLLVMContext(), Ops));
1198-
}
1199-
}
1200-
NextTL = ATL.getModifiedLoc();
1201-
} else {
1202-
break;
1203-
}
1204-
}
1205-
}
1206-
1207-
NextTL = StripMacroAttributed(TL.getNextTypeLoc());
1208-
if (Annots.size() > 0)
1209-
Annotations = DBuilder.getOrCreateArray(Annots);
1210-
}
1211-
12121145
if (Tag == llvm::dwarf::DW_TAG_reference_type ||
12131146
Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
12141147
return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
12151148
Size, Align, DWARFAddressSpace);
12161149
else
1217-
return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit, NextTL),
1218-
Size, Align, DWARFAddressSpace,
1219-
StringRef(), Annotations);
1150+
return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1151+
Align, DWARFAddressSpace);
12201152
}
12211153

12221154
llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
@@ -1333,11 +1265,8 @@ llvm::DIType *CGDebugInfo::CreateType(const TemplateSpecializationType *Ty,
13331265

13341266
llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
13351267
llvm::DIFile *Unit) {
1336-
TypeLoc TL;
1337-
if (const TypeSourceInfo *TSI = Ty->getDecl()->getTypeSourceInfo())
1338-
TL = TSI->getTypeLoc();
13391268
llvm::DIType *Underlying =
1340-
getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit, TL);
1269+
getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
13411270

13421271
if (Ty->getDecl()->hasAttr<NoDebugAttr>())
13431272
return Underlying;
@@ -1411,7 +1340,7 @@ static llvm::DINode::DIFlags getRefFlags(const FunctionProtoType *Func) {
14111340
}
14121341

14131342
llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
1414-
llvm::DIFile *Unit, TypeLoc TL) {
1343+
llvm::DIFile *Unit) {
14151344
const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
14161345
if (FPT) {
14171346
if (llvm::DIType *QTy = CreateQualifiedType(FPT, Unit))
@@ -1423,41 +1352,17 @@ llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
14231352
SmallVector<llvm::Metadata *, 16> EltTys;
14241353

14251354
// Add the result type at least.
1426-
TypeLoc RetTL;
1427-
if (TL) {
1428-
if (auto FTL = TL.getAs<FunctionTypeLoc>())
1429-
RetTL = FTL.getReturnLoc();
1430-
}
1431-
EltTys.push_back(getOrCreateType(Ty->getReturnType(), Unit, RetTL));
1355+
EltTys.push_back(getOrCreateType(Ty->getReturnType(), Unit));
14321356

14331357
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
14341358
// Set up remainder of arguments if there is a prototype.
14351359
// otherwise emit it as a variadic function.
1436-
if (!FPT) {
1360+
if (!FPT)
14371361
EltTys.push_back(DBuilder.createUnspecifiedParameter());
1438-
} else {
1362+
else {
14391363
Flags = getRefFlags(FPT);
1440-
bool DoneWithTL = false;
1441-
if (TL) {
1442-
if (auto FTL = TL.getAs<FunctionTypeLoc>()) {
1443-
DoneWithTL = true;
1444-
int Idx = 0;
1445-
for (const QualType &ParamType : FPT->param_types()) {
1446-
TypeLoc ParamTL;
1447-
if (ParmVarDecl *Param = FTL.getParam(Idx)) {
1448-
if (const TypeSourceInfo *TSI = Param->getTypeSourceInfo())
1449-
ParamTL = TSI->getTypeLoc();
1450-
}
1451-
EltTys.push_back(getOrCreateType(ParamType, Unit, ParamTL));
1452-
Idx++;
1453-
}
1454-
}
1455-
}
1456-
1457-
if (!DoneWithTL) {
1458-
for (const QualType &ParamType : FPT->param_types())
1459-
EltTys.push_back(getOrCreateType(ParamType, Unit));
1460-
}
1364+
for (const QualType &ParamType : FPT->param_types())
1365+
EltTys.push_back(getOrCreateType(ParamType, Unit));
14611366
if (FPT->isVariadic())
14621367
EltTys.push_back(DBuilder.createUnspecifiedParameter());
14631368
}
@@ -1528,13 +1433,11 @@ llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl,
15281433
Flags, DebugType, Annotations);
15291434
}
15301435

1531-
llvm::DIType *
1532-
CGDebugInfo::createFieldType(StringRef name, QualType type, SourceLocation loc,
1533-
AccessSpecifier AS, uint64_t offsetInBits,
1534-
uint32_t AlignInBits, llvm::DIFile *tunit,
1535-
llvm::DIScope *scope, const RecordDecl *RD,
1536-
llvm::DINodeArray Annotations, TypeLoc TL) {
1537-
llvm::DIType *debugType = getOrCreateType(type, tunit, TL);
1436+
llvm::DIType *CGDebugInfo::createFieldType(
1437+
StringRef name, QualType type, SourceLocation loc, AccessSpecifier AS,
1438+
uint64_t offsetInBits, uint32_t AlignInBits, llvm::DIFile *tunit,
1439+
llvm::DIScope *scope, const RecordDecl *RD, llvm::DINodeArray Annotations) {
1440+
llvm::DIType *debugType = getOrCreateType(type, tunit);
15381441

15391442
// Get the location for the field.
15401443
llvm::DIFile *file = getOrCreateFile(loc);
@@ -1642,12 +1545,9 @@ void CGDebugInfo::CollectRecordNormalField(
16421545
} else {
16431546
auto Align = getDeclAlignIfRequired(field, CGM.getContext());
16441547
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(field);
1645-
TypeLoc TL;
1646-
if (const TypeSourceInfo *TSI = field->getTypeSourceInfo())
1647-
TL = TSI->getTypeLoc();
1648-
FieldType = createFieldType(name, type, field->getLocation(),
1649-
field->getAccess(), OffsetInBits, Align, tunit,
1650-
RecordTy, RD, Annotations, TL);
1548+
FieldType =
1549+
createFieldType(name, type, field->getLocation(), field->getAccess(),
1550+
OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
16511551
}
16521552

16531553
elements.push_back(FieldType);
@@ -3405,8 +3305,7 @@ void CGDebugInfo::completeUnusedClass(const CXXRecordDecl &D) {
34053305
RetainedTypes.push_back(CGM.getContext().getRecordType(&D).getAsOpaquePtr());
34063306
}
34073307

3408-
llvm::DIType *CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile *Unit,
3409-
TypeLoc TL) {
3308+
llvm::DIType *CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile *Unit) {
34103309
if (Ty.isNull())
34113310
return nullptr;
34123311

@@ -3423,7 +3322,7 @@ llvm::DIType *CGDebugInfo::getOrCreateType(QualType Ty, llvm::DIFile *Unit,
34233322
if (auto *T = getTypeOrNull(Ty))
34243323
return T;
34253324

3426-
llvm::DIType *Res = CreateTypeNode(Ty, Unit, TL);
3325+
llvm::DIType *Res = CreateTypeNode(Ty, Unit);
34273326
void *TyPtr = Ty.getAsOpaquePtr();
34283327

34293328
// And update the type cache.
@@ -3467,11 +3366,10 @@ llvm::DIModule *CGDebugInfo::getParentModuleOrNull(const Decl *D) {
34673366
return nullptr;
34683367
}
34693368

3470-
llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit,
3471-
TypeLoc TL) {
3369+
llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
34723370
// Handle qualifiers, which recursively handles what they refer to.
34733371
if (Ty.hasLocalQualifiers())
3474-
return CreateQualifiedType(Ty, Unit, TL);
3372+
return CreateQualifiedType(Ty, Unit);
34753373

34763374
// Work out details of type.
34773375
switch (Ty->getTypeClass()) {
@@ -3500,7 +3398,7 @@ llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit,
35003398
case Type::Complex:
35013399
return CreateType(cast<ComplexType>(Ty));
35023400
case Type::Pointer:
3503-
return CreateType(cast<PointerType>(Ty), Unit, TL);
3401+
return CreateType(cast<PointerType>(Ty), Unit);
35043402
case Type::BlockPointer:
35053403
return CreateType(cast<BlockPointerType>(Ty), Unit);
35063404
case Type::Typedef:
@@ -3511,7 +3409,7 @@ llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit,
35113409
return CreateEnumType(cast<EnumType>(Ty));
35123410
case Type::FunctionProto:
35133411
case Type::FunctionNoProto:
3514-
return CreateType(cast<FunctionType>(Ty), Unit, TL);
3412+
return CreateType(cast<FunctionType>(Ty), Unit);
35153413
case Type::ConstantArray:
35163414
case Type::VariableArray:
35173415
case Type::IncompleteArray:
@@ -4056,12 +3954,7 @@ llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(const Decl *D,
40563954
getDwarfCC(CC));
40573955
}
40583956

4059-
TypeLoc TL;
4060-
if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
4061-
if (const TypeSourceInfo *TSI = FD->getTypeSourceInfo())
4062-
TL = TSI->getTypeLoc();
4063-
}
4064-
return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F, TL));
3957+
return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
40653958
}
40663959

40673960
QualType
@@ -4463,12 +4356,8 @@ llvm::DILocalVariable *CGDebugInfo::EmitDeclare(const VarDecl *VD,
44634356
uint64_t XOffset = 0;
44644357
if (VD->hasAttr<BlocksAttr>())
44654358
Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
4466-
else {
4467-
TypeLoc TL;
4468-
if (const TypeSourceInfo *TSI = VD->getTypeSourceInfo())
4469-
TL = TSI->getTypeLoc();
4470-
Ty = getOrCreateType(VD->getType(), Unit, TL);
4471-
}
4359+
else
4360+
Ty = getOrCreateType(VD->getType(), Unit);
44724361

44734362
// If there is no debug info for this type then do not emit debug info
44744363
// for this variable.
@@ -5192,14 +5081,10 @@ void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
51925081
}
51935082
AppendAddressSpaceXDeref(AddressSpace, Expr);
51945083

5195-
TypeLoc TL;
5196-
if (const TypeSourceInfo *TSI = D->getTypeSourceInfo())
5197-
TL = TSI->getTypeLoc();
5198-
51995084
llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
52005085
GVE = DBuilder.createGlobalVariableExpression(
5201-
DContext, DeclName, LinkageName, Unit, LineNo,
5202-
getOrCreateType(T, Unit, TL), Var->hasLocalLinkage(), true,
5086+
DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
5087+
Var->hasLocalLinkage(), true,
52035088
Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
52045089
getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
52055090
Align, Annotations);

clang/lib/CodeGen/CGDebugInfo.h

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,16 @@ class CGDebugInfo {
178178
llvm::DIType *CreateType(const ComplexType *Ty);
179179
llvm::DIType *CreateType(const AutoType *Ty);
180180
llvm::DIType *CreateType(const ExtIntType *Ty);
181-
llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg,
182-
TypeLoc TL = TypeLoc());
181+
llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
183182
llvm::DIType *CreateQualifiedType(const FunctionProtoType *Ty,
184183
llvm::DIFile *Fg);
185184
llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
186185
llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
187186
llvm::DIFile *Fg);
188187
llvm::DIType *CreateType(const ObjCObjectPointerType *Ty, llvm::DIFile *F);
189-
llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F,
190-
TypeLoc TL = TypeLoc());
188+
llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
191189
llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
192-
llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F,
193-
TypeLoc TL = TypeLoc());
190+
llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
194191
/// Get structure or union type.
195192
llvm::DIType *CreateType(const RecordType *Tyg);
196193
llvm::DIType *CreateTypeDefinition(const RecordType *Ty);
@@ -245,8 +242,7 @@ class CGDebugInfo {
245242
/// \return namespace descriptor for the given namespace decl.
246243
llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
247244
llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
248-
QualType PointeeTy, llvm::DIFile *F,
249-
TypeLoc TL = TypeLoc());
245+
QualType PointeeTy, llvm::DIFile *F);
250246
llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
251247

252248
/// A helper function to create a subprogram for a single member
@@ -312,8 +308,7 @@ class CGDebugInfo {
312308
uint64_t offsetInBits, uint32_t AlignInBits,
313309
llvm::DIFile *tunit, llvm::DIScope *scope,
314310
const RecordDecl *RD = nullptr,
315-
llvm::DINodeArray Annotations = nullptr,
316-
TypeLoc TL = TypeLoc());
311+
llvm::DINodeArray Annotations = nullptr);
317312

318313
llvm::DIType *createFieldType(StringRef name, QualType type,
319314
SourceLocation loc, AccessSpecifier AS,
@@ -633,8 +628,7 @@ class CGDebugInfo {
633628
Optional<StringRef> Source);
634629

635630
/// Get the type from the cache or create a new type if necessary.
636-
llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg,
637-
TypeLoc TL = TypeLoc());
631+
llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
638632

639633
/// Get a reference to a clang module. If \p CreateSkeletonCU is true,
640634
/// this also creates a split dwarf skeleton compile unit.
@@ -649,8 +643,7 @@ class CGDebugInfo {
649643
llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty);
650644

651645
/// Create type metadata for a source language type.
652-
llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg,
653-
TypeLoc TL = TypeLoc());
646+
llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
654647

655648
/// Create new member and increase Offset by FType's size.
656649
llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,

0 commit comments

Comments
 (0)