Skip to content

Commit 9434360

Browse files
committed
Revert "[BPF] Add preserve_access_index attribute for record definition"
This reverts commit 4a5aa1a. There are some other test failures. Investigate them first.
1 parent 4a5aa1a commit 9434360

14 files changed

+8
-448
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ class TargetArch<list<string> arches> : TargetSpec {
332332
}
333333
def TargetARM : TargetArch<["arm", "thumb", "armeb", "thumbeb"]>;
334334
def TargetAVR : TargetArch<["avr"]>;
335-
def TargetBPF : TargetArch<["bpfel", "bpfeb"]>;
336335
def TargetMips32 : TargetArch<["mips", "mipsel"]>;
337336
def TargetAnyMips : TargetArch<["mips", "mipsel", "mips64", "mips64el"]>;
338337
def TargetMSP430 : TargetArch<["msp430"]>;
@@ -1579,12 +1578,6 @@ def AMDGPUNumVGPR : InheritableAttr {
15791578
let Subjects = SubjectList<[Function], ErrorDiag, "kernel functions">;
15801579
}
15811580

1582-
def BPFPreserveAccessIndex : InheritableAttr,
1583-
TargetSpecificAttr<TargetBPF> {
1584-
let Spellings = [Clang<"preserve_access_index">];
1585-
let Documentation = [BPFPreserveAccessIndexDocs];
1586-
}
1587-
15881581
def WebAssemblyImportModule : InheritableAttr,
15891582
TargetSpecificAttr<TargetWebAssembly> {
15901583
let Spellings = [Clang<"import_module">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,17 +1634,6 @@ The semantics are as follows:
16341634
}];
16351635
}
16361636

1637-
def BPFPreserveAccessIndexDocs : Documentation {
1638-
let Category = DocCatFunction;
1639-
let Content = [{
1640-
Clang supports the ``__attribute__((preserve_access_index))``
1641-
attribute for the BPF target. This attribute may be attached to a
1642-
struct or union declaration, where if -g is specified, it enables
1643-
preserving struct or union member access debuginfo indicies of this
1644-
struct or union, similar to clang ``__builtin_preserve_acceess_index()``.
1645-
}];
1646-
}
1647-
16481637
def MipsInterruptDocs : Documentation {
16491638
let Category = DocCatFunction;
16501639
let Heading = "interrupt (MIPS)";

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10065,7 +10065,6 @@ def err_preserve_field_info_not_field : Error<
1006510065
"__builtin_preserve_field_info argument %0 not a field access">;
1006610066
def err_preserve_field_info_not_const: Error<
1006710067
"__builtin_preserve_field_info argument %0 not a constant">;
10068-
def err_preserve_access_index_wrong_type: Error<"%0 attribute only applies to %1">;
1006910068

1007010069
def err_bit_cast_non_trivially_copyable : Error<
1007110070
"__builtin_bit_cast %select{source|destination}0 type must be trivially copyable">;

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 7 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,67 +3402,11 @@ static QualType getFixedSizeElementType(const ASTContext &ctx,
34023402
return eltType;
34033403
}
34043404

3405-
/// Given an array base, check whether its member access belongs to a record
3406-
/// with preserve_access_index attribute or not.
3407-
static bool IsPreserveAIArrayBase(CodeGenFunction &CGF, const Expr *ArrayBase) {
3408-
if (!ArrayBase || !CGF.getDebugInfo())
3409-
return false;
3410-
3411-
const auto *ImplicitCast = dyn_cast<ImplicitCastExpr>(ArrayBase);
3412-
if (!ImplicitCast)
3413-
return false;
3414-
3415-
// Only support base as either a MemberExpr or DeclRefExpr.
3416-
// DeclRefExpr to cover cases like:
3417-
// struct s { int a; int b[10]; };
3418-
// struct s *p;
3419-
// p[1].a
3420-
// p[1] will generate a DeclRefExpr and p[1].a is a MemberExpr.
3421-
// p->b[5] is a MemberExpr example.
3422-
const Expr *E = ImplicitCast->getSubExpr();
3423-
const auto *MemberCast = dyn_cast<MemberExpr>(E);
3424-
if (MemberCast)
3425-
return MemberCast->getMemberDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
3426-
3427-
const auto *DeclRefCast = dyn_cast<DeclRefExpr>(E);
3428-
if (DeclRefCast) {
3429-
const VarDecl *VarDef = dyn_cast<VarDecl>(DeclRefCast->getDecl());
3430-
if (!VarDef)
3431-
return false;
3432-
3433-
const auto *PtrT = dyn_cast<PointerType>(VarDef->getType().getTypePtr());
3434-
if (!PtrT)
3435-
return false;
3436-
const auto *PointeeT = PtrT->getPointeeType().getTypePtr();
3437-
3438-
// Peel off typedef's
3439-
const auto *TypedefT = dyn_cast<TypedefType>(PointeeT);
3440-
while (TypedefT) {
3441-
PointeeT = TypedefT->desugar().getTypePtr();
3442-
TypedefT = dyn_cast<TypedefType>(PointeeT);
3443-
}
3444-
3445-
// Not a typedef any more, it should be an elaborated type.
3446-
const auto ElaborateT = dyn_cast<ElaboratedType>(PointeeT);
3447-
if (!ElaborateT)
3448-
return false;
3449-
3450-
const auto *RecT = dyn_cast<RecordType>(ElaborateT->desugar().getTypePtr());
3451-
if (!RecT)
3452-
return false;
3453-
3454-
return RecT->getDecl()->hasAttr<BPFPreserveAccessIndexAttr>();
3455-
}
3456-
3457-
return false;
3458-
}
3459-
34603405
static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
34613406
ArrayRef<llvm::Value *> indices,
34623407
QualType eltType, bool inbounds,
34633408
bool signedIndices, SourceLocation loc,
34643409
QualType *arrayType = nullptr,
3465-
const Expr *Base = nullptr,
34663410
const llvm::Twine &name = "arrayidx") {
34673411
// All the indices except that last must be zero.
34683412
#ifndef NDEBUG
@@ -3484,8 +3428,7 @@ static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
34843428

34853429
llvm::Value *eltPtr;
34863430
auto LastIndex = dyn_cast<llvm::ConstantInt>(indices.back());
3487-
if (!LastIndex ||
3488-
(!CGF.IsInPreservedAIRegion && !IsPreserveAIArrayBase(CGF, Base))) {
3431+
if (!CGF.IsInPreservedAIRegion || !LastIndex) {
34893432
eltPtr = emitArraySubscriptGEP(
34903433
CGF, addr.getPointer(), indices, inbounds, signedIndices,
34913434
loc, name);
@@ -3639,7 +3582,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
36393582
Addr = emitArraySubscriptGEP(
36403583
*this, ArrayLV.getAddress(), {CGM.getSize(CharUnits::Zero()), Idx},
36413584
E->getType(), !getLangOpts().isSignedOverflowDefined(), SignedIndices,
3642-
E->getExprLoc(), &arrayType, E->getBase());
3585+
E->getExprLoc(), &arrayType);
36433586
EltBaseInfo = ArrayLV.getBaseInfo();
36443587
EltTBAAInfo = CGM.getTBAAInfoForSubobject(ArrayLV, E->getType());
36453588
} else {
@@ -3649,8 +3592,7 @@ LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E,
36493592
QualType ptrType = E->getBase()->getType();
36503593
Addr = emitArraySubscriptGEP(*this, Addr, Idx, E->getType(),
36513594
!getLangOpts().isSignedOverflowDefined(),
3652-
SignedIndices, E->getExprLoc(), &ptrType,
3653-
E->getBase());
3595+
SignedIndices, E->getExprLoc(), &ptrType);
36543596
}
36553597

36563598
LValue LV = MakeAddrLValue(Addr, E->getType(), EltBaseInfo, EltTBAAInfo);
@@ -4051,13 +3993,12 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
40513993
const CGBitFieldInfo &Info = RL.getBitFieldInfo(field);
40523994
Address Addr = base.getAddress();
40533995
unsigned Idx = RL.getLLVMFieldNo(field);
4054-
const RecordDecl *rec = field->getParent();
4055-
if (!IsInPreservedAIRegion &&
4056-
(!getDebugInfo() || !rec->hasAttr<BPFPreserveAccessIndexAttr>())) {
3996+
if (!IsInPreservedAIRegion) {
40573997
if (Idx != 0)
40583998
// For structs, we GEP to the field that the record layout suggests.
40593999
Addr = Builder.CreateStructGEP(Addr, Idx, field->getName());
40604000
} else {
4001+
const RecordDecl *rec = field->getParent();
40614002
llvm::DIType *DbgInfo = getDebugInfo()->getOrCreateRecordType(
40624003
getContext().getRecordType(rec), rec->getLocation());
40634004
Addr = Builder.CreatePreserveStructAccessIndex(Addr, Idx,
@@ -4140,8 +4081,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
41404081
addr = Address(Builder.CreateLaunderInvariantGroup(addr.getPointer()),
41414082
addr.getAlignment());
41424083

4143-
if (IsInPreservedAIRegion ||
4144-
(getDebugInfo() && rec->hasAttr<BPFPreserveAccessIndexAttr>())) {
4084+
if (IsInPreservedAIRegion) {
41454085
// Remember the original union field index
41464086
llvm::DIType *DbgInfo = getDebugInfo()->getOrCreateRecordType(
41474087
getContext().getRecordType(rec), rec->getLocation());
@@ -4155,8 +4095,7 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
41554095
addr = Builder.CreateElementBitCast(
41564096
addr, CGM.getTypes().ConvertTypeForMem(FieldType), field->getName());
41574097
} else {
4158-
if (!IsInPreservedAIRegion &&
4159-
(!getDebugInfo() || !rec->hasAttr<BPFPreserveAccessIndexAttr>()))
4098+
if (!IsInPreservedAIRegion)
41604099
// For structs, we GEP to the field that the record layout suggests.
41614100
addr = emitAddrOfFieldStorage(*this, addr, field);
41624101
else

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5700,59 +5700,6 @@ static void handleAVRSignalAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
57005700
handleSimpleAttribute<AVRSignalAttr>(S, D, AL);
57015701
}
57025702

5703-
static void handleBPFPreserveAIRecord(Sema &S, RecordDecl *RD,
5704-
const BPFPreserveAccessIndexAttr &AL) {
5705-
// Add preserve_access_index attribute to all fields and inner records.
5706-
for (DeclContext::decl_iterator D = RD->decls_begin(), DEnd = RD->decls_end();
5707-
D != DEnd; ++D) {
5708-
// Any member or inner struct having attribute means done.
5709-
if (D->hasAttr<BPFPreserveAccessIndexAttr>())
5710-
return;
5711-
5712-
RecordDecl *Rec = dyn_cast<RecordDecl>(*D);
5713-
if (Rec) {
5714-
Rec->addAttr(::new (S.Context) BPFPreserveAccessIndexAttr(S.Context, AL));
5715-
handleBPFPreserveAIRecord(S, Rec, AL);
5716-
} else {
5717-
D->addAttr(::new (S.Context) BPFPreserveAccessIndexAttr(S.Context, AL));
5718-
}
5719-
}
5720-
}
5721-
5722-
static void handleBPFPreserveAIRecord(Sema &S, RecordDecl *RD,
5723-
const ParsedAttr &AL) {
5724-
// Add preserve_access_index attribute to all fields and inner records.
5725-
for (DeclContext::decl_iterator D = RD->decls_begin(), DEnd = RD->decls_end();
5726-
D != DEnd; ++D) {
5727-
RecordDecl *Rec = dyn_cast<RecordDecl>(*D);
5728-
if (Rec) {
5729-
// Inner record may have been processed.
5730-
if (!Rec->hasAttr<BPFPreserveAccessIndexAttr>()) {
5731-
Rec->addAttr(::new (S.Context) BPFPreserveAccessIndexAttr(S.Context, AL));
5732-
handleBPFPreserveAIRecord(S, Rec, AL);
5733-
}
5734-
} else {
5735-
D->addAttr(::new (S.Context) BPFPreserveAccessIndexAttr(S.Context, AL));
5736-
}
5737-
}
5738-
}
5739-
5740-
static void handleBPFPreserveAccessIndexAttr(Sema &S, Decl *D,
5741-
const ParsedAttr &AL) {
5742-
RecordDecl *Rec = dyn_cast<RecordDecl>(D);
5743-
if (!Rec) {
5744-
S.Diag(D->getLocation(), diag::err_preserve_access_index_wrong_type)
5745-
<< "preserve_addess_index" << "struct or union type";
5746-
return;
5747-
}
5748-
5749-
if (!checkAttributeNumArgs(S, AL, 0))
5750-
return;
5751-
5752-
handleBPFPreserveAIRecord(S, Rec, AL);
5753-
Rec->addAttr(::new (S.Context) BPFPreserveAccessIndexAttr(S.Context, AL));
5754-
}
5755-
57565703
static void handleWebAssemblyImportModuleAttr(Sema &S, Decl *D, const ParsedAttr &AL) {
57575704
if (!isFunctionOrMethod(D)) {
57585705
S.Diag(D->getLocation(), diag::warn_attribute_wrong_decl_type)
@@ -6629,9 +6576,6 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
66296576
case ParsedAttr::AT_AVRSignal:
66306577
handleAVRSignalAttr(S, D, AL);
66316578
break;
6632-
case ParsedAttr::AT_BPFPreserveAccessIndex:
6633-
handleBPFPreserveAccessIndexAttr(S, D, AL);
6634-
break;
66356579
case ParsedAttr::AT_WebAssemblyImportModule:
66366580
handleWebAssemblyImportModuleAttr(S, D, AL);
66376581
break;
@@ -7381,22 +7325,14 @@ void Sema::ProcessDeclAttributeList(Scope *S, Decl *D,
73817325
}
73827326
}
73837327

7384-
// Helper for delayed processing TransparentUnion or BPFPreserveAccessIndexAttr
7385-
// attribute.
7328+
// Helper for delayed processing TransparentUnion attribute.
73867329
void Sema::ProcessDeclAttributeDelayed(Decl *D,
73877330
const ParsedAttributesView &AttrList) {
73887331
for (const ParsedAttr &AL : AttrList)
73897332
if (AL.getKind() == ParsedAttr::AT_TransparentUnion) {
73907333
handleTransparentUnionAttr(*this, D, AL);
73917334
break;
73927335
}
7393-
7394-
// For BPFPreserveAccessIndexAttr, we want to populate the attributes
7395-
// to fields and inner records as well.
7396-
if (D->hasAttr<BPFPreserveAccessIndexAttr>()) {
7397-
handleBPFPreserveAIRecord(*this, cast<RecordDecl>(D),
7398-
*D->getAttr<BPFPreserveAccessIndexAttr>());
7399-
}
74007336
}
74017337

74027338
// Annotation attributes are the only attributes allowed after an access

clang/test/CodeGen/bpf-attr-preserve-access-index-1.c

Lines changed: 0 additions & 23 deletions
This file was deleted.

clang/test/CodeGen/bpf-attr-preserve-access-index-2.c

Lines changed: 0 additions & 24 deletions
This file was deleted.

clang/test/CodeGen/bpf-attr-preserve-access-index-3.c

Lines changed: 0 additions & 32 deletions
This file was deleted.

clang/test/CodeGen/bpf-attr-preserve-access-index-4.c

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)