Skip to content

Commit cbf6e93

Browse files
[clang codegen] Delete unnecessary GEP cleanup code. (#90303)
There's some code in AggExprEmitter::VisitCXXParenListOrInitListExpr to try to do early cleanup for GEPs for fields that aren't accessed. But it's unlikely to actually save significant compile-time, and it's subtly wrong in cases where EmitLValueForFieldInitialization() doesn't create a GEP. So just delete the code. Fixes #88077. Fixes #89547.
1 parent c250aeb commit cbf6e93

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,25 +1789,15 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
17891789
// Push a destructor if necessary.
17901790
// FIXME: if we have an array of structures, all explicitly
17911791
// initialized, we can end up pushing a linear number of cleanups.
1792-
bool pushedCleanup = false;
17931792
if (QualType::DestructionKind dtorKind
17941793
= field->getType().isDestructedType()) {
17951794
assert(LV.isSimple());
17961795
if (dtorKind) {
17971796
CGF.pushDestroyAndDeferDeactivation(NormalAndEHCleanup, LV.getAddress(),
17981797
field->getType(),
17991798
CGF.getDestroyer(dtorKind), false);
1800-
pushedCleanup = true;
18011799
}
18021800
}
1803-
1804-
// If the GEP didn't get used because of a dead zero init or something
1805-
// else, clean it up for -O0 builds and general tidiness.
1806-
if (!pushedCleanup && LV.isSimple())
1807-
if (llvm::GetElementPtrInst *GEP =
1808-
dyn_cast<llvm::GetElementPtrInst>(LV.emitRawPointer(CGF)))
1809-
if (GEP->use_empty())
1810-
GEP->eraseFromParent();
18111801
}
18121802
}
18131803

clang/test/CodeGenCXX/no-unique-address.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,28 @@ struct HasZeroSizedFieldWithNonTrivialInit {
101101
HasZeroSizedFieldWithNonTrivialInit testHasZeroSizedFieldWithNonTrivialInit = {.a = 1};
102102
// CHECK-LABEL: define {{.*}}cxx_global_var_init
103103
// CHECK: call {{.*}}@_ZN14NonTrivialInitC1Ev({{.*}}@testHasZeroSizedFieldWithNonTrivialInit
104+
105+
void *operator new(unsigned long, void *);
106+
template <class Ty>
107+
struct _box {
108+
[[no_unique_address]] Ty _value;
109+
};
110+
// Make sure this doesn't crash.
111+
// CHECK-LABEL: define {{.*}}placement_new_struct
112+
void placement_new_struct() {
113+
struct set_value_t {};
114+
115+
// GH88077
116+
struct _tuple : _box<set_value_t>, _box<int> {};
117+
118+
int _storage[1];
119+
new (_storage) _tuple{};
120+
121+
// GH89547
122+
struct _tuple2 {
123+
_box<set_value_t> a;
124+
};
125+
126+
int _storage2[1];
127+
new (_storage2) _tuple2{};
128+
}

0 commit comments

Comments
 (0)