Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions clang/lib/CodeGen/CGExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,25 +1789,15 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
// Push a destructor if necessary.
// FIXME: if we have an array of structures, all explicitly
// initialized, we can end up pushing a linear number of cleanups.
bool pushedCleanup = false;
if (QualType::DestructionKind dtorKind
= field->getType().isDestructedType()) {
assert(LV.isSimple());
if (dtorKind) {
CGF.pushDestroyAndDeferDeactivation(NormalAndEHCleanup, LV.getAddress(),
field->getType(),
CGF.getDestroyer(dtorKind), false);
pushedCleanup = true;
}
}

// If the GEP didn't get used because of a dead zero init or something
// else, clean it up for -O0 builds and general tidiness.
if (!pushedCleanup && LV.isSimple())
if (llvm::GetElementPtrInst *GEP =
dyn_cast<llvm::GetElementPtrInst>(LV.emitRawPointer(CGF)))
if (GEP->use_empty())
GEP->eraseFromParent();
}
}

Expand Down
25 changes: 25 additions & 0 deletions clang/test/CodeGenCXX/no-unique-address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,28 @@ struct HasZeroSizedFieldWithNonTrivialInit {
HasZeroSizedFieldWithNonTrivialInit testHasZeroSizedFieldWithNonTrivialInit = {.a = 1};
// CHECK-LABEL: define {{.*}}cxx_global_var_init
// CHECK: call {{.*}}@_ZN14NonTrivialInitC1Ev({{.*}}@testHasZeroSizedFieldWithNonTrivialInit

void *operator new(unsigned long, void *);
template <class Ty>
struct _box {
[[no_unique_address]] Ty _value;
};
// Make sure this doesn't crash.
// CHECK-LABEL: define {{.*}}placement_new_struct
void placement_new_struct() {
struct set_value_t {};

// GH88077
struct _tuple : _box<set_value_t>, _box<int> {};

int _storage[1];
new (_storage) _tuple{};

// GH89547
struct _tuple2 {
_box<set_value_t> a;
};

int _storage2[1];
new (_storage2) _tuple2{};
}