Skip to content

Commit 33a8478

Browse files
authored
Revert "[BoundsSafety] Don't bind lvalues with temporary locations (#11082)
* Revert "[BoundsSafety] Don't bind lvalues with temporary locations (#10969)" This reverts commit e7a3802. * Adjust some CodeGen tests to match `next`
1 parent 20c93df commit 33a8478

29 files changed

+556
-1122
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7070,8 +7070,14 @@ LValue CodeGenFunction::EmitMaterializeSequenceExprLValue(
70707070
const MaterializeSequenceExpr *MSE) {
70717071
if (MSE->isBinding()) {
70727072
for (auto *OVE : MSE->opaquevalues()) {
7073-
CodeGenFunction::OpaqueValueMappingData::bind(
7074-
*this, OVE, OVE->getSourceExpr());
7073+
if (CodeGenFunction::OpaqueValueMappingData::shouldBindAsLValue(OVE)) {
7074+
RValue PtrRV = EmitAnyExpr(OVE->getSourceExpr());
7075+
LValue LV = MakeAddrLValue(PtrRV.getAggregateAddress(), OVE->getType());
7076+
CodeGenFunction::OpaqueValueMappingData::bind(*this, OVE, LV);
7077+
} else {
7078+
CodeGenFunction::OpaqueValueMappingData::bind(
7079+
*this, OVE, OVE->getSourceExpr());
7080+
}
70757081
}
70767082
}
70777083

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,13 @@ void AggExprEmitter::EmitWidePointerBitCast(CastExpr *E) {
441441
RValue SrcRV = CGF.EmitAnyExpr(E->getSubExpr());
442442
assert(SrcRV.isAggregate());
443443
Address SrcAddr = SrcRV.getAggregateAddress();
444-
llvm::Value *Ptr = CGF.GetWidePointerElement(SrcAddr, WPIndex::Pointer);
445-
llvm::Value *Upper = CGF.GetWidePointerElement(SrcAddr, WPIndex::Upper);
446-
llvm::Value *Lower = E->getType()->isBidiIndexablePointerType()
444+
EmitWidePointerToDest(E->getType(),
445+
CGF.GetWidePointerElement(SrcAddr, WPIndex::Pointer),
446+
CGF.GetWidePointerElement(SrcAddr, WPIndex::Upper),
447+
E->getType()->isBidiIndexablePointerType()
447448
? CGF.GetWidePointerElement(SrcAddr, WPIndex::Lower)
448-
: nullptr;
449-
450-
EmitWidePointerToDest(E->getType(), Ptr, Upper, Lower, ElemBitCast);
449+
: nullptr,
450+
ElemBitCast);
451451
}
452452

453453
void AggExprEmitter::EmitWidePointer(LValue DestLV, llvm::Value *Ptr,
@@ -596,7 +596,13 @@ void AggExprEmitter::VisitPredefinedBoundsCheckExpr(
596596
void AggExprEmitter::VisitMaterializeSequenceExpr(MaterializeSequenceExpr *MSE) {
597597
if (MSE->isBinding()) {
598598
for (auto *OVE : MSE->opaquevalues()) {
599-
CodeGenFunction::OpaqueValueMappingData::bind(CGF, OVE, OVE->getSourceExpr());
599+
if (CodeGenFunction::OpaqueValueMappingData::shouldBindAsLValue(OVE)) {
600+
RValue PtrRV = CGF.EmitAnyExpr(OVE->getSourceExpr());
601+
LValue LV = CGF.MakeAddrLValue(PtrRV.getAggregateAddress(), OVE->getType());
602+
CodeGenFunction::OpaqueValueMappingData::bind(CGF, OVE, LV);
603+
} else {
604+
CodeGenFunction::OpaqueValueMappingData::bind(CGF, OVE, OVE->getSourceExpr());
605+
}
600606
}
601607
}
602608

clang/test/BoundsSafety-legacy-checks/CodeGen/constant-eval-count-static-init.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ const Item oidRsa = { _oidRsa, sizeof(_oidRsa)};
1717
// CHECK-NEXT: entry:
1818
// CHECK-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
1919
// CHECK-NEXT: [[AGG_TEMP:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8
20+
// CHECK-NEXT: [[AGG_TEMP1:%.*]] = alloca [[STRUCT_ITEM:%.*]], align 8
2021
// CHECK-NEXT: store i32 0, ptr [[RETVAL]], align 4
21-
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr getelementptr inbounds nuw ([[STRUCT_ITEM:%.*]], ptr @oidRsa, i32 0, i32 1), align 8
22-
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr @oidRsa, align 8
22+
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP1]], ptr align 8 @oidRsa, i64 16, i1 false)
23+
// CHECK-NEXT: [[LENGTH:%.*]] = getelementptr inbounds nuw [[STRUCT_ITEM]], ptr [[AGG_TEMP1]], i32 0, i32 1
24+
// CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[LENGTH]], align 8
25+
// CHECK-NEXT: [[DATA:%.*]] = getelementptr inbounds nuw [[STRUCT_ITEM]], ptr [[AGG_TEMP1]], i32 0, i32 0
26+
// CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[DATA]], align 8
2327
// CHECK-NEXT: [[IDX_EXT:%.*]] = sext i32 [[TMP0]] to i64
2428
// CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i8, ptr [[TMP1]], i64 [[IDX_EXT]]
2529
// CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP]], i32 0, i32 0
@@ -42,11 +46,11 @@ const Item oidRsa = { _oidRsa, sizeof(_oidRsa)};
4246
// CHECK-NEXT: unreachable
4347
// CHECK: cont:
4448
// CHECK-NEXT: [[TMP7:%.*]] = icmp uge ptr [[TMP5]], [[WIDE_PTR_LB]], {{!annotation ![0-9]+}}
45-
// CHECK-NEXT: br i1 [[TMP7]], label %[[CONT3:.*]], label %[[TRAP2:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
46-
// CHECK: [[TRAP2]]:
49+
// CHECK-NEXT: br i1 [[TMP7]], label [[CONT3:%.*]], label [[TRAP2:%.*]], {{!annotation ![0-9]+}}
50+
// CHECK: trap2:
4751
// CHECK-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR3]], {{!annotation ![0-9]+}}
4852
// CHECK-NEXT: unreachable
49-
// CHECK: [[CONT3]]:
53+
// CHECK: cont3:
5054
// CHECK-NEXT: [[TMP8:%.*]] = load i32, ptr [[TMP5]], align 4
5155
// CHECK-NEXT: ret i32 [[TMP8]]
5256
//

clang/test/BoundsSafety-legacy-checks/CodeGen/count-dependent-assignment-checks/count-attr-fields-assign-2-oob2.c

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ struct S {
2727
// CHECK-O0-NEXT: [[AGG_TEMP33:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8
2828
// CHECK-O0-NEXT: [[I:%.*]] = alloca i32, align 4
2929
// CHECK-O0-NEXT: [[AGG_TEMP42:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8
30+
// CHECK-O0-NEXT: [[AGG_TEMP43:%.*]] = alloca [[STRUCT_S]], align 8
3031
// CHECK-O0-NEXT: [[AGG_TEMP56:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8
32+
// CHECK-O0-NEXT: [[AGG_TEMP57:%.*]] = alloca [[STRUCT_S]], align 8
3133
// CHECK-O0-NEXT: [[AGG_TEMP73:%.*]] = alloca %"__bounds_safety::wide_ptr.bidi_indexable", align 8
34+
// CHECK-O0-NEXT: [[AGG_TEMP74:%.*]] = alloca [[STRUCT_S]], align 8
3235
// CHECK-O0-NEXT: [[ARRAYDECAY:%.*]] = getelementptr inbounds [10 x i32], ptr [[ARR]], i64 0, i64 0
3336
// CHECK-O0-NEXT: [[UPPER:%.*]] = getelementptr inbounds i32, ptr [[ARRAYDECAY]], i64 10
3437
// CHECK-O0-NEXT: [[TMP0:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[TMP]], i32 0, i32 0
@@ -146,9 +149,10 @@ struct S {
146149
// CHECK-O0-NEXT: br i1 [[CMP]], label [[FOR_BODY:%.*]], label [[FOR_END:%.*]]
147150
// CHECK-O0: for.body:
148151
// CHECK-O0-NEXT: [[TMP24:%.*]] = load i32, ptr [[I]], align 4
149-
// CHECK-O0-NEXT: [[L44:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 2
152+
// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP43]], ptr align 8 [[S]], i64 24, i1 false)
153+
// CHECK-O0-NEXT: [[L44:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[AGG_TEMP43]], i32 0, i32 2
150154
// CHECK-O0-NEXT: [[TMP25:%.*]] = load i32, ptr [[L44]], align 8
151-
// CHECK-O0-NEXT: [[BP45:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 0
155+
// CHECK-O0-NEXT: [[BP45:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[AGG_TEMP43]], i32 0, i32 0
152156
// CHECK-O0-NEXT: [[TMP26:%.*]] = load ptr, ptr [[BP45]], align 8
153157
// CHECK-O0-NEXT: [[IDX_EXT:%.*]] = sext i32 [[TMP25]] to i64
154158
// CHECK-O0-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[TMP26]], i64 [[IDX_EXT]]
@@ -168,17 +172,17 @@ struct S {
168172
// CHECK-O0-NEXT: [[WIDE_PTR_LB_ADDR50:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP42]], i32 0, i32 2
169173
// CHECK-O0-NEXT: [[WIDE_PTR_LB51:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR50]], align 8
170174
// CHECK-O0-NEXT: [[TMP31:%.*]] = icmp ult ptr [[ARRAYIDX]], [[WIDE_PTR_UB49]], {{!annotation ![0-9]+}}
171-
// CHECK-O0-NEXT: br i1 [[TMP31]], label %[[CONT53:.*]], label %[[TRAP52:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
172-
// CHECK-O0: [[TRAP52]]:
175+
// CHECK-O0-NEXT: br i1 [[TMP31]], label [[CONT53:%.*]], label [[TRAP52:%.*]], {{!annotation ![0-9]+}}
176+
// CHECK-O0: trap52:
173177
// CHECK-O0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR4]], {{!annotation ![0-9]+}}
174178
// CHECK-O0-NEXT: unreachable, {{!annotation ![0-9]+}}
175-
// CHECK-O0: [[CONT53]]:
179+
// CHECK-O0: cont53:
176180
// CHECK-O0-NEXT: [[TMP32:%.*]] = icmp uge ptr [[ARRAYIDX]], [[WIDE_PTR_LB51]], {{!annotation ![0-9]+}}
177-
// CHECK-O0-NEXT: br i1 [[TMP32]], label %[[CONT55:.*]], label %[[TRAP54:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
178-
// CHECK-O0: [[TRAP54]]:
181+
// CHECK-O0-NEXT: br i1 [[TMP32]], label [[CONT55:%.*]], label [[TRAP54:%.*]], {{!annotation ![0-9]+}}
182+
// CHECK-O0: trap54:
179183
// CHECK-O0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR4]], {{!annotation ![0-9]+}}
180184
// CHECK-O0-NEXT: unreachable, {{!annotation ![0-9]+}}
181-
// CHECK-O0: [[CONT55]]:
185+
// CHECK-O0: cont55:
182186
// CHECK-O0-NEXT: store i32 [[TMP24]], ptr [[ARRAYIDX]], align 4
183187
// CHECK-O0-NEXT: br label [[FOR_INC:%.*]]
184188
// CHECK-O0: for.inc:
@@ -187,9 +191,10 @@ struct S {
187191
// CHECK-O0-NEXT: store i32 [[INC]], ptr [[I]], align 4
188192
// CHECK-O0-NEXT: br label [[FOR_COND]], !llvm.loop [[LOOP5:![0-9]+]]
189193
// CHECK-O0: for.end:
190-
// CHECK-O0-NEXT: [[L58:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 2
194+
// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP57]], ptr align 8 [[S]], i64 24, i1 false)
195+
// CHECK-O0-NEXT: [[L58:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[AGG_TEMP57]], i32 0, i32 2
191196
// CHECK-O0-NEXT: [[TMP34:%.*]] = load i32, ptr [[L58]], align 8
192-
// CHECK-O0-NEXT: [[BP259:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 1
197+
// CHECK-O0-NEXT: [[BP259:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[AGG_TEMP57]], i32 0, i32 1
193198
// CHECK-O0-NEXT: [[TMP35:%.*]] = load ptr, ptr [[BP259]], align 8
194199
// CHECK-O0-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP34]], 1
195200
// CHECK-O0-NEXT: [[IDX_EXT60:%.*]] = sext i32 [[ADD]] to i64
@@ -208,21 +213,22 @@ struct S {
208213
// CHECK-O0-NEXT: [[WIDE_PTR_LB_ADDR67:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP56]], i32 0, i32 2
209214
// CHECK-O0-NEXT: [[WIDE_PTR_LB68:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR67]], align 8
210215
// CHECK-O0-NEXT: [[TMP39:%.*]] = icmp ult ptr [[ARRAYIDX64]], [[WIDE_PTR_UB66]], {{!annotation ![0-9]+}}
211-
// CHECK-O0-NEXT: br i1 [[TMP39]], label %[[CONT70:.*]], label %[[TRAP69:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
212-
// CHECK-O0: [[TRAP69]]:
216+
// CHECK-O0-NEXT: br i1 [[TMP39]], label [[CONT70:%.*]], label [[TRAP69:%.*]], {{!annotation ![0-9]+}}
217+
// CHECK-O0: trap69:
213218
// CHECK-O0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR4]], {{!annotation ![0-9]+}}
214219
// CHECK-O0-NEXT: unreachable, {{!annotation ![0-9]+}}
215-
// CHECK-O0: [[CONT70]]:
220+
// CHECK-O0: cont70:
216221
// CHECK-O0-NEXT: [[TMP40:%.*]] = icmp uge ptr [[ARRAYIDX64]], [[WIDE_PTR_LB68]], {{!annotation ![0-9]+}}
217-
// CHECK-O0-NEXT: br i1 [[TMP40]], label %[[CONT72:.*]], label %[[TRAP71:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
218-
// CHECK-O0: [[TRAP71]]:
222+
// CHECK-O0-NEXT: br i1 [[TMP40]], label [[CONT72:%.*]], label [[TRAP71:%.*]], {{!annotation ![0-9]+}}
223+
// CHECK-O0: trap71:
219224
// CHECK-O0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR4]], {{!annotation ![0-9]+}}
220225
// CHECK-O0-NEXT: unreachable, {{!annotation ![0-9]+}}
221-
// CHECK-O0: [[CONT72]]:
226+
// CHECK-O0: cont72:
222227
// CHECK-O0-NEXT: [[TMP41:%.*]] = load i32, ptr [[ARRAYIDX64]], align 4
223-
// CHECK-O0-NEXT: [[L75:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 2
228+
// CHECK-O0-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align 8 [[AGG_TEMP74]], ptr align 8 [[S]], i64 24, i1 false)
229+
// CHECK-O0-NEXT: [[L75:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[AGG_TEMP74]], i32 0, i32 2
224230
// CHECK-O0-NEXT: [[TMP42:%.*]] = load i32, ptr [[L75]], align 8
225-
// CHECK-O0-NEXT: [[BP76:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[S]], i32 0, i32 0
231+
// CHECK-O0-NEXT: [[BP76:%.*]] = getelementptr inbounds nuw [[STRUCT_S]], ptr [[AGG_TEMP74]], i32 0, i32 0
226232
// CHECK-O0-NEXT: [[TMP43:%.*]] = load ptr, ptr [[BP76]], align 8
227233
// CHECK-O0-NEXT: [[IDX_EXT77:%.*]] = sext i32 [[TMP42]] to i64
228234
// CHECK-O0-NEXT: [[ADD_PTR78:%.*]] = getelementptr inbounds i32, ptr [[TMP43]], i64 [[IDX_EXT77]]
@@ -240,17 +246,17 @@ struct S {
240246
// CHECK-O0-NEXT: [[WIDE_PTR_LB_ADDR84:%.*]] = getelementptr inbounds nuw %"__bounds_safety::wide_ptr.bidi_indexable", ptr [[AGG_TEMP73]], i32 0, i32 2
241247
// CHECK-O0-NEXT: [[WIDE_PTR_LB85:%.*]] = load ptr, ptr [[WIDE_PTR_LB_ADDR84]], align 8
242248
// CHECK-O0-NEXT: [[TMP47:%.*]] = icmp ult ptr [[ARRAYIDX81]], [[WIDE_PTR_UB83]], {{!annotation ![0-9]+}}
243-
// CHECK-O0-NEXT: br i1 [[TMP47]], label %[[CONT87:.*]], label %[[TRAP86:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
244-
// CHECK-O0: [[TRAP86]]:
249+
// CHECK-O0-NEXT: br i1 [[TMP47]], label [[CONT87:%.*]], label [[TRAP86:%.*]], {{!annotation ![0-9]+}}
250+
// CHECK-O0: trap86:
245251
// CHECK-O0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR4]], {{!annotation ![0-9]+}}
246252
// CHECK-O0-NEXT: unreachable, {{!annotation ![0-9]+}}
247-
// CHECK-O0: [[CONT87]]:
253+
// CHECK-O0: cont87:
248254
// CHECK-O0-NEXT: [[TMP48:%.*]] = icmp uge ptr [[ARRAYIDX81]], [[WIDE_PTR_LB85]], {{!annotation ![0-9]+}}
249-
// CHECK-O0-NEXT: br i1 [[TMP48]], label %[[CONT89:.*]], label %[[TRAP88:.*]], {{!prof ![0-9]+}}, {{!annotation ![0-9]+}}
250-
// CHECK-O0: [[TRAP88]]:
255+
// CHECK-O0-NEXT: br i1 [[TMP48]], label [[CONT89:%.*]], label [[TRAP88:%.*]], {{!annotation ![0-9]+}}
256+
// CHECK-O0: trap88:
251257
// CHECK-O0-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR4]], {{!annotation ![0-9]+}}
252258
// CHECK-O0-NEXT: unreachable, {{!annotation ![0-9]+}}
253-
// CHECK-O0: [[CONT89]]:
259+
// CHECK-O0: cont89:
254260
// CHECK-O0-NEXT: [[TMP49:%.*]] = load i32, ptr [[ARRAYIDX81]], align 4
255261
// CHECK-O0-NEXT: [[ADD90:%.*]] = add nsw i32 [[TMP41]], [[TMP49]]
256262
// CHECK-O0-NEXT: ret i32 [[ADD90]]

clang/test/BoundsSafety-legacy-checks/CodeGen/count-dependent-assignment-checks/dep-count-init-list-basic-O2.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,11 @@ void TestAccessFail() {
102102
// CHECK-NEXT: [[TMP0:%.*]] = icmp ult ptr [[ARRAYIDX]], [[UPPER]], {{!annotation ![0-9]+}}
103103
// CHECK-NEXT: [[TMP1:%.*]] = icmp uge ptr [[ARRAYIDX]], [[ARR]], {{!annotation ![0-9]+}}
104104
// CHECK-NEXT: [[OR_COND:%.*]] = and i1 [[TMP0]], [[TMP1]], {{!annotation ![0-9]+}}
105-
// CHECK-NEXT: br i1 [[OR_COND]], label %[[CONT47:.*]], label [[TRAP:%.*]], {{!annotation ![0-9]+}}
105+
// CHECK-NEXT: br i1 [[OR_COND]], label [[CONT47:%.*]], label [[TRAP:%.*]], {{!annotation ![0-9]+}}
106106
// CHECK: trap:
107107
// CHECK-NEXT: call void @llvm.ubsantrap(i8 25) #[[ATTR5]], {{!annotation ![0-9]+}}
108108
// CHECK-NEXT: unreachable, {{!annotation ![0-9]+}}
109-
// CHECK: [[CONT47]]:
109+
// CHECK: cont47:
110110
// CHECK-NEXT: call void @llvm.lifetime.end.p0(i64 36, ptr nonnull [[ARR]]) #[[ATTR6]]
111111
// CHECK-NEXT: ret void
112112
//

0 commit comments

Comments
 (0)