Skip to content

Commit 2484469

Browse files
committed
Revert "[BPF] Attribute preserve_static_offset for structs"
This reverts commit cb13e92. Buildbot reports MSAN failures in tests added in this commit: https://lab.llvm.org/buildbot/#/builders/5/builds/38806 Failing tests: LLVM :: CodeGen/BPF/preserve-static-offset/load-arr-pai.ll LLVM :: CodeGen/BPF/preserve-static-offset/load-ptr-pai.ll LLVM :: CodeGen/BPF/preserve-static-offset/load-struct-pai.ll LLVM :: CodeGen/BPF/preserve-static-offset/load-union-pai.ll LLVM :: CodeGen/BPF/preserve-static-offset/store-pai.ll
1 parent e86591b commit 2484469

File tree

65 files changed

+35
-4343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+35
-4343
lines changed

clang/include/clang/Basic/Attr.td

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2024,14 +2024,6 @@ def BPFPreserveAccessIndex : InheritableAttr,
20242024
let LangOpts = [COnly];
20252025
}
20262026

2027-
def BPFPreserveStaticOffset : InheritableAttr,
2028-
TargetSpecificAttr<TargetBPF> {
2029-
let Spellings = [Clang<"preserve_static_offset">];
2030-
let Subjects = SubjectList<[Record], ErrorDiag>;
2031-
let Documentation = [BPFPreserveStaticOffsetDocs];
2032-
let LangOpts = [COnly];
2033-
}
2034-
20352027
def BTFDeclTag : InheritableAttr {
20362028
let Spellings = [Clang<"btf_decl_tag">];
20372029
let Args = [StringArgument<"BTFDeclTag">];

clang/include/clang/Basic/AttrDocs.td

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,43 +2199,6 @@ preserving struct or union member access debuginfo indices of this
21992199
struct or union, similar to clang ``__builtin_preserve_access_index()``.
22002200
}];
22012201
}
2202-
2203-
def BPFPreserveStaticOffsetDocs : Documentation {
2204-
let Category = DocCatFunction;
2205-
let Content = [{
2206-
Clang supports the ``__attribute__((preserve_static_offset))``
2207-
attribute for the BPF target. This attribute may be attached to a
2208-
struct or union declaration. Reading or writing fields of types having
2209-
such annotation is guaranteed to generate LDX/ST/STX instruction with
2210-
offset corresponding to the field.
2211-
2212-
For example:
2213-
2214-
.. code-block:: c
2215-
2216-
struct foo {
2217-
int a;
2218-
int b;
2219-
};
2220-
2221-
struct bar {
2222-
int a;
2223-
struct foo b;
2224-
} __attribute__((preserve_static_offset));
2225-
2226-
void buz(struct bar *g) {
2227-
g->b.a = 42;
2228-
}
2229-
2230-
The assignment to ``g``'s field would produce an ST instruction with
2231-
offset 8: ``*(u32)(r1 + 8) = 42;``.
2232-
2233-
Without this attribute generated instructions might be different,
2234-
depending on optimizations behavior. E.g. the example above could be
2235-
rewritten as ``r1 += 8; *(u32)(r1 + 0) = 42;``.
2236-
}];
2237-
}
2238-
22392202
def BTFDeclTagDocs : Documentation {
22402203
let Category = DocCatFunction;
22412204
let Content = [{

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3833,33 +3833,6 @@ static QualType getFixedSizeElementType(const ASTContext &ctx,
38333833
return eltType;
38343834
}
38353835

3836-
static bool hasBPFPreserveStaticOffset(const RecordDecl *D) {
3837-
return D && D->hasAttr<BPFPreserveStaticOffsetAttr>();
3838-
}
3839-
3840-
static bool hasBPFPreserveStaticOffset(const Expr *E) {
3841-
if (!E)
3842-
return false;
3843-
QualType PointeeType = E->getType()->getPointeeType();
3844-
if (PointeeType.isNull())
3845-
return false;
3846-
if (const auto *BaseDecl = PointeeType->getAsRecordDecl())
3847-
return hasBPFPreserveStaticOffset(BaseDecl);
3848-
return false;
3849-
}
3850-
3851-
// Wraps Addr with a call to llvm.preserve.static.offset intrinsic.
3852-
static Address wrapWithBPFPreserveStaticOffset(CodeGenFunction &CGF,
3853-
Address &Addr) {
3854-
if (!CGF.getTarget().getTriple().isBPF())
3855-
return Addr;
3856-
3857-
llvm::Function *Fn =
3858-
CGF.CGM.getIntrinsic(llvm::Intrinsic::preserve_static_offset);
3859-
llvm::CallInst *Call = CGF.Builder.CreateCall(Fn, {Addr.getPointer()});
3860-
return Address(Call, Addr.getElementType(), Addr.getAlignment());
3861-
}
3862-
38633836
/// Given an array base, check whether its member access belongs to a record
38643837
/// with preserve_access_index attribute or not.
38653838
static bool IsPreserveAIArrayBase(CodeGenFunction &CGF, const Expr *ArrayBase) {
@@ -3921,9 +3894,6 @@ static Address emitArraySubscriptGEP(CodeGenFunction &CGF, Address addr,
39213894
CharUnits eltAlign =
39223895
getArrayElementAlign(addr.getAlignment(), indices.back(), eltSize);
39233896

3924-
if (hasBPFPreserveStaticOffset(Base))
3925-
addr = wrapWithBPFPreserveStaticOffset(CGF, addr);
3926-
39273897
llvm::Value *eltPtr;
39283898
auto LastIndex = dyn_cast<llvm::ConstantInt>(indices.back());
39293899
if (!LastIndex ||
@@ -4552,8 +4522,6 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
45524522
Address Addr = base.getAddress(*this);
45534523
unsigned Idx = RL.getLLVMFieldNo(field);
45544524
const RecordDecl *rec = field->getParent();
4555-
if (hasBPFPreserveStaticOffset(rec))
4556-
Addr = wrapWithBPFPreserveStaticOffset(*this, Addr);
45574525
if (!UseVolatile) {
45584526
if (!IsInPreservedAIRegion &&
45594527
(!getDebugInfo() || !rec->hasAttr<BPFPreserveAccessIndexAttr>())) {
@@ -4626,8 +4594,6 @@ LValue CodeGenFunction::EmitLValueForField(LValue base,
46264594
}
46274595

46284596
Address addr = base.getAddress(*this);
4629-
if (hasBPFPreserveStaticOffset(rec))
4630-
addr = wrapWithBPFPreserveStaticOffset(*this, addr);
46314597
if (auto *ClassDef = dyn_cast<CXXRecordDecl>(rec)) {
46324598
if (CGM.getCodeGenOpts().StrictVTablePointers &&
46334599
ClassDef->isDynamicClass()) {

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9036,9 +9036,6 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL,
90369036
case ParsedAttr::AT_BPFPreserveAccessIndex:
90379037
handleBPFPreserveAccessIndexAttr(S, D, AL);
90389038
break;
9039-
case ParsedAttr::AT_BPFPreserveStaticOffset:
9040-
handleSimpleAttribute<BPFPreserveStaticOffsetAttr>(S, D, AL);
9041-
break;
90429039
case ParsedAttr::AT_BTFDeclTag:
90439040
handleBTFDeclTagAttr(S, D, AL);
90449041
break;

clang/test/CodeGen/bpf-preserve-static-offset-arr.c

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

clang/test/CodeGen/bpf-preserve-static-offset-bitfield.c

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

clang/test/CodeGen/bpf-preserve-static-offset-lvalue.c

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

clang/test/CodeGen/bpf-preserve-static-offset-non-bpf.c

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

clang/test/CodeGen/bpf-preserve-static-offset-pai.c

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

clang/test/Misc/pragma-attribute-supported-attributes-list.test

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
// CHECK-NEXT: Availability ((SubjectMatchRule_record, SubjectMatchRule_enum, SubjectMatchRule_enum_constant, SubjectMatchRule_field, SubjectMatchRule_function, SubjectMatchRule_namespace, SubjectMatchRule_objc_category, SubjectMatchRule_objc_implementation, SubjectMatchRule_objc_interface, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property, SubjectMatchRule_objc_protocol, SubjectMatchRule_record, SubjectMatchRule_type_alias, SubjectMatchRule_variable))
2424
// CHECK-NEXT: AvailableOnlyInDefaultEvalMethod (SubjectMatchRule_type_alias)
2525
// CHECK-NEXT: BPFPreserveAccessIndex (SubjectMatchRule_record)
26-
// CHECK-NEXT: BPFPreserveStaticOffset (SubjectMatchRule_record)
2726
// CHECK-NEXT: BTFDeclTag (SubjectMatchRule_variable, SubjectMatchRule_function, SubjectMatchRule_record, SubjectMatchRule_field, SubjectMatchRule_type_alias)
2827
// CHECK-NEXT: BuiltinAlias (SubjectMatchRule_function)
2928
// CHECK-NEXT: CFAuditedTransfer (SubjectMatchRule_function)

clang/test/Sema/bpf-attr-preserve-static-offset-warns-nonbpf.c

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

clang/test/Sema/bpf-attr-preserve-static-offset-warns.c

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

clang/test/Sema/bpf-attr-preserve-static-offset.c

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

llvm/include/llvm/IR/Intrinsics.td

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,10 +2469,6 @@ def int_preserve_struct_access_index : DefaultAttrsIntrinsic<[llvm_anyptr_ty],
24692469
[IntrNoMem,
24702470
ImmArg<ArgIndex<1>>,
24712471
ImmArg<ArgIndex<2>>]>;
2472-
def int_preserve_static_offset : DefaultAttrsIntrinsic<[llvm_ptr_ty],
2473-
[llvm_ptr_ty],
2474-
[IntrNoMem, IntrSpeculatable,
2475-
ReadNone <ArgIndex<0>>]>;
24762472

24772473
//===------------ Intrinsics to perform common vector shuffles ------------===//
24782474

llvm/include/llvm/IR/IntrinsicsBPF.td

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -37,43 +37,4 @@ let TargetPrefix = "bpf" in { // All intrinsics start with "llvm.bpf."
3737
def int_bpf_compare : ClangBuiltin<"__builtin_bpf_compare">,
3838
Intrinsic<[llvm_i1_ty], [llvm_i32_ty, llvm_anyint_ty, llvm_anyint_ty],
3939
[IntrNoMem]>;
40-
def int_bpf_getelementptr_and_load : ClangBuiltin<"__builtin_bpf_getelementptr_and_load">,
41-
Intrinsic<[llvm_any_ty],
42-
[llvm_ptr_ty, // base ptr for getelementptr
43-
llvm_i1_ty, // volatile
44-
llvm_i8_ty, // atomic order
45-
llvm_i8_ty, // synscope id
46-
llvm_i8_ty, // alignment
47-
llvm_i1_ty, // inbounds
48-
llvm_vararg_ty], // indices for getelementptr insn
49-
[IntrNoCallback,
50-
IntrNoFree,
51-
IntrWillReturn,
52-
NoCapture <ArgIndex<0>>,
53-
ImmArg <ArgIndex<1>>, // volatile
54-
ImmArg <ArgIndex<2>>, // atomic order
55-
ImmArg <ArgIndex<3>>, // synscope id
56-
ImmArg <ArgIndex<4>>, // alignment
57-
ImmArg <ArgIndex<5>>, // inbounds
58-
]>;
59-
def int_bpf_getelementptr_and_store : ClangBuiltin<"__builtin_bpf_getelementptr_and_store">,
60-
Intrinsic<[],
61-
[llvm_any_ty, // value to store
62-
llvm_ptr_ty, // base ptr for getelementptr
63-
llvm_i1_ty, // volatile
64-
llvm_i8_ty, // atomic order
65-
llvm_i8_ty, // syncscope id
66-
llvm_i8_ty, // alignment
67-
llvm_i1_ty, // inbounds
68-
llvm_vararg_ty], // indexes for getelementptr insn
69-
[IntrNoCallback,
70-
IntrNoFree,
71-
IntrWillReturn,
72-
NoCapture <ArgIndex<1>>,
73-
ImmArg <ArgIndex<2>>, // volatile
74-
ImmArg <ArgIndex<3>>, // atomic order
75-
ImmArg <ArgIndex<4>>, // syncscope id
76-
ImmArg <ArgIndex<5>>, // alignment
77-
ImmArg <ArgIndex<6>>, // inbounds
78-
]>;
7940
}

0 commit comments

Comments
 (0)