[mlir] Add workaround for false positive in -Wfree-nonheap-object

Restore 499571ea83
reverted by 0082764605.

A compiler slightly older than
"[clang][Sema] removes -Wfree-nonheap-object reference param false positive"
may report the false positive.
We need to retain the workaround a bit longer so that such compilers
can be used to compile MLIR in a warning-free way.
This commit is contained in:
Fangrui Song 2021-07-21 16:16:20 -07:00
parent db7efcab7d
commit bcf6f641ac
1 changed files with 8 additions and 3 deletions

View File

@ -237,7 +237,9 @@ detail::OperandStorage::~OperandStorage() {
if (isDynamicStorage()) {
TrailingOperandStorage &storage = getDynamicStorage();
storage.~TrailingOperandStorage();
free(&storage);
// Work around -Wfree-nonheap-object false positive fixed by D102728.
auto *mem = &storage;
free(mem);
} else {
getInlineStorage().~TrailingOperandStorage();
}
@ -371,8 +373,11 @@ MutableArrayRef<OpOperand> detail::OperandStorage::resize(Operation *owner,
new (&newOperands[numOperands]) OpOperand(owner);
// If the current storage is also dynamic, free it.
if (isDynamicStorage())
free(&storage);
if (isDynamicStorage()) {
// Work around -Wfree-nonheap-object false positive fixed by D102728.
auto *mem = &storage;
free(mem);
}
// Update the storage representation to use the new dynamic storage.
dynamicStorage.setPointerAndInt(newStorage, true);