summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2022-12-01 17:27:59 -0800
committerGitHub <noreply@github.com>2022-12-02 01:27:59 +0000
commit197b6da7afe6ec317011800abf9453402e6beaa5 (patch)
tree564ae447dc2af116be8948703da85e8d9198f7c4
parentf70bc4d6634c5a0b1aa88f3c073b783e83bb5712 (diff)
downloadbinaryen-197b6da7afe6ec317011800abf9453402e6beaa5.tar.gz
binaryen-197b6da7afe6ec317011800abf9453402e6beaa5.tar.bz2
binaryen-197b6da7afe6ec317011800abf9453402e6beaa5.zip
Use C++17's [[maybe_unused]]. NFC (#5309)
-rw-r--r--src/cfg/cfg-traversal.h3
-rw-r--r--src/compiler-support.h10
-rw-r--r--src/ir/ExpressionAnalyzer.cpp10
-rw-r--r--src/ir/ExpressionManipulator.cpp6
-rw-r--r--src/ir/branch-utils.h8
-rw-r--r--src/ir/iteration.h4
-rw-r--r--src/ir/memory-utils.h3
-rw-r--r--src/ir/possible-contents.cpp9
-rw-r--r--src/ir/properties.h4
-rw-r--r--src/ir/type-updating.cpp4
-rw-r--r--src/passes/CoalesceLocals.cpp3
-rw-r--r--src/passes/Inlining.cpp3
-rw-r--r--src/passes/Poppify.cpp15
-rw-r--r--src/support/threads.cpp3
-rw-r--r--src/support/threads.h4
-rw-r--r--src/tools/wasm-reduce.cpp1
-rw-r--r--src/tools/wasm-shell.cpp6
-rw-r--r--src/tools/wasm2c-wrapper.h3
-rw-r--r--src/wasm-binary.h12
-rw-r--r--src/wasm-interpreter.h3
-rw-r--r--src/wasm-traversal.h3
-rw-r--r--src/wasm/wasm-binary.cpp3
22 files changed, 35 insertions, 85 deletions
diff --git a/src/cfg/cfg-traversal.h b/src/cfg/cfg-traversal.h
index 3a15143fe..344c6b8ba 100644
--- a/src/cfg/cfg-traversal.h
+++ b/src/cfg/cfg-traversal.h
@@ -268,7 +268,7 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
}
// If this delegates to an outer try, we skip catches between this try
// and the target try.
- bool found = false;
+ [[maybe_unused]] bool found = false;
for (int j = i - 1; j >= 0; j--) {
if (self->unwindExprStack[j]->template cast<Try>()->name ==
tryy->delegateTarget) {
@@ -277,7 +277,6 @@ struct CFGWalker : public ControlFlowWalker<SubType, VisitorType> {
break;
}
}
- WASM_UNUSED(found);
assert(found);
continue;
}
diff --git a/src/compiler-support.h b/src/compiler-support.h
index eddb2d7f0..a34859190 100644
--- a/src/compiler-support.h
+++ b/src/compiler-support.h
@@ -31,14 +31,4 @@
#define WASM_BUILTIN_UNREACHABLE __assume(false)
#endif
-// The code might contain TODOs or stubs that read some values but do nothing
-// with them. The compiler might fail with [-Werror,-Wunused-variable].
-// The WASM_UNUSED(varible) is a wrapper that helps to suppress the error.
-#define WASM_UNUSED(expr) \
- do { \
- if (sizeof expr) { \
- (void)0; \
- } \
- } while (0)
-
#endif // wasm_compiler_support_h
diff --git a/src/ir/ExpressionAnalyzer.cpp b/src/ir/ExpressionAnalyzer.cpp
index 924040e12..62ad3ed3e 100644
--- a/src/ir/ExpressionAnalyzer.cpp
+++ b/src/ir/ExpressionAnalyzer.cpp
@@ -163,10 +163,8 @@ bool ExpressionAnalyzer::flexibleEqual(Expression* left,
// Create cast versions of it for later operations.
#define DELEGATE_START(id) \
- auto* castLeft = left->cast<id>(); \
- WASM_UNUSED(castLeft); \
- auto* castRight = right->cast<id>(); \
- WASM_UNUSED(castRight);
+ [[maybe_unused]] auto* castLeft = left->cast<id>(); \
+ [[maybe_unused]] auto* castRight = right->cast<id>();
// Handle each type of field, comparing it appropriately.
#define DELEGATE_FIELD_CHILD(id, field) \
@@ -304,9 +302,7 @@ struct Hasher {
#define DELEGATE_ID curr->_id
// Create cast versions of it for later operations.
-#define DELEGATE_START(id) \
- auto* cast = curr->cast<id>(); \
- WASM_UNUSED(cast);
+#define DELEGATE_START(id) [[maybe_unused]] auto* cast = curr->cast<id>();
// Handle each type of field, comparing it appropriately.
#define DELEGATE_GET_FIELD(id, field) cast->field
diff --git a/src/ir/ExpressionManipulator.cpp b/src/ir/ExpressionManipulator.cpp
index 20856808e..9232dddf2 100644
--- a/src/ir/ExpressionManipulator.cpp
+++ b/src/ir/ExpressionManipulator.cpp
@@ -55,10 +55,8 @@ flexibleCopy(Expression* original, Module& wasm, CustomCopier custom) {
// for later operations.
#define DELEGATE_START(id) \
copy = wasm.allocator.alloc<id>(); \
- auto* castOriginal = original->cast<id>(); \
- WASM_UNUSED(castOriginal); \
- auto* castCopy = copy->cast<id>(); \
- WASM_UNUSED(castCopy);
+ [[maybe_unused]] auto* castOriginal = original->cast<id>(); \
+ [[maybe_unused]] auto* castCopy = copy->cast<id>();
// Handle each type of field, copying it appropriately.
#define DELEGATE_FIELD_CHILD(id, field) \
diff --git a/src/ir/branch-utils.h b/src/ir/branch-utils.h
index 82a563498..d433a421e 100644
--- a/src/ir/branch-utils.h
+++ b/src/ir/branch-utils.h
@@ -44,9 +44,7 @@ inline bool isBranchReachable(Expression* expr) {
template<typename T> void operateOnScopeNameUses(Expression* expr, T func) {
#define DELEGATE_ID expr->_id
-#define DELEGATE_START(id) \
- auto* cast = expr->cast<id>(); \
- WASM_UNUSED(cast);
+#define DELEGATE_START(id) [[maybe_unused]] auto* cast = expr->cast<id>();
#define DELEGATE_GET_FIELD(id, field) cast->field
@@ -110,9 +108,7 @@ void operateOnScopeNameUsesAndSentValues(Expression* expr, T func) {
template<typename T> void operateOnScopeNameDefs(Expression* expr, T func) {
#define DELEGATE_ID expr->_id
-#define DELEGATE_START(id) \
- auto* cast = expr->cast<id>(); \
- WASM_UNUSED(cast);
+#define DELEGATE_START(id) [[maybe_unused]] auto* cast = expr->cast<id>();
#define DELEGATE_FIELD_SCOPE_NAME_DEF(id, field) func(cast->field)
diff --git a/src/ir/iteration.h b/src/ir/iteration.h
index a2c9ceef6..8da03a555 100644
--- a/src/ir/iteration.h
+++ b/src/ir/iteration.h
@@ -84,9 +84,7 @@ public:
#define DELEGATE_ID parent->_id
-#define DELEGATE_START(id) \
- auto* cast = parent->cast<id>(); \
- WASM_UNUSED(cast);
+#define DELEGATE_START(id) [[maybe_unused]] auto* cast = parent->cast<id>();
#define DELEGATE_GET_FIELD(id, field) cast->field
diff --git a/src/ir/memory-utils.h b/src/ir/memory-utils.h
index 9bdd00258..f31c55a7d 100644
--- a/src/ir/memory-utils.h
+++ b/src/ir/memory-utils.h
@@ -92,8 +92,7 @@ inline bool ensureLimitedSegments(Module& module) {
// we'll merge constant segments if we must
if (numConstant + numDynamic >= WebLimitations::MaxDataSegments) {
numConstant = WebLimitations::MaxDataSegments - numDynamic - 1;
- auto num = numConstant + numDynamic;
- WASM_UNUSED(num);
+ [[maybe_unused]] auto num = numConstant + numDynamic;
assert(num == WebLimitations::MaxDataSegments - 1);
}
diff --git a/src/ir/possible-contents.cpp b/src/ir/possible-contents.cpp
index 7ed6bfde6..52b05057f 100644
--- a/src/ir/possible-contents.cpp
+++ b/src/ir/possible-contents.cpp
@@ -1765,8 +1765,7 @@ void Flower::flowAfterUpdate(LocationIndex locationIndex) {
// This is indeed one of the special cases where it is the child of a
// parent, and we need to do some special handling because of that child-
// parent connection.
- auto* child = exprLoc->expr;
- WASM_UNUSED(child);
+ [[maybe_unused]] auto* child = exprLoc->expr;
auto parentIndex = iter->second;
auto* parent = std::get<ExpressionLocation>(getLocation(parentIndex)).expr;
@@ -2107,11 +2106,9 @@ void Flower::dump(Location location) {
} else if (auto* loc = std::get_if<BreakTargetLocation>(&location)) {
std::cout << " branchloc " << loc->func->name << " : " << loc->target
<< " tupleIndex " << loc->tupleIndex << '\n';
- } else if (auto* loc = std::get_if<SignatureParamLocation>(&location)) {
- WASM_UNUSED(loc);
+ } else if (std::get_if<SignatureParamLocation>(&location)) {
std::cout << " sigparamloc " << '\n';
- } else if (auto* loc = std::get_if<SignatureResultLocation>(&location)) {
- WASM_UNUSED(loc);
+ } else if (std::get_if<SignatureResultLocation>(&location)) {
std::cout << " sigresultloc " << '\n';
} else if (auto* loc = std::get_if<NullLocation>(&location)) {
std::cout << " Nullloc " << loc->type << '\n';
diff --git a/src/ir/properties.h b/src/ir/properties.h
index bd0487d8f..2214eecaf 100644
--- a/src/ir/properties.h
+++ b/src/ir/properties.h
@@ -339,9 +339,7 @@ inline Index getNumChildren(Expression* curr) {
#define DELEGATE_ID curr->_id
-#define DELEGATE_START(id) \
- auto* cast = curr->cast<id>(); \
- WASM_UNUSED(cast);
+#define DELEGATE_START(id) [[maybe_unused]] auto* cast = curr->cast<id>();
#define DELEGATE_GET_FIELD(id, field) cast->field
diff --git a/src/ir/type-updating.cpp b/src/ir/type-updating.cpp
index 3eb29e43c..47931baad 100644
--- a/src/ir/type-updating.cpp
+++ b/src/ir/type-updating.cpp
@@ -186,9 +186,7 @@ void GlobalTypeRewriter::mapTypes(const TypeMap& oldToNewTypes) {
#define DELEGATE_ID curr->_id
-#define DELEGATE_START(id) \
- auto* cast = curr->cast<id>(); \
- WASM_UNUSED(cast);
+#define DELEGATE_START(id) [[maybe_unused]] auto* cast = curr->cast<id>();
#define DELEGATE_GET_FIELD(id, field) cast->field
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp
index 062449e95..ce36b3c69 100644
--- a/src/passes/CoalesceLocals.cpp
+++ b/src/passes/CoalesceLocals.cpp
@@ -236,9 +236,8 @@ void CoalesceLocals::calculateInterferences() {
auto index = action.index;
if (action.isGet()) {
if (endsLiveRange[i]) {
- bool erased = live.erase(action.index);
+ [[maybe_unused]] bool erased = live.erase(action.index);
assert(erased);
- WASM_UNUSED(erased);
}
continue;
}
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp
index 25993c7ec..c542d1018 100644
--- a/src/passes/Inlining.cpp
+++ b/src/passes/Inlining.cpp
@@ -506,8 +506,7 @@ struct FunctionSplitter {
// perform the splitting (if that has not already been done before).
Function* getInlineableSplitFunction(Function* func) {
Function* inlineable = nullptr;
- auto success = maybeSplit(func, &inlineable);
- WASM_UNUSED(success);
+ [[maybe_unused]] auto success = maybeSplit(func, &inlineable);
assert(success && inlineable);
return inlineable;
}
diff --git a/src/passes/Poppify.cpp b/src/passes/Poppify.cpp
index e47b13568..a7f3e5ccc 100644
--- a/src/passes/Poppify.cpp
+++ b/src/passes/Poppify.cpp
@@ -243,16 +243,14 @@ void Poppifier::emit(Expression* curr) {
};
void Poppifier::emitIfElse(If* curr) {
- auto& scope = scopeStack.back();
- WASM_UNUSED(scope);
+ [[maybe_unused]] auto& scope = scopeStack.back();
assert(scope.kind == Scope::If);
patchScope(curr->ifTrue);
scopeStack.emplace_back(Scope::Else);
}
void Poppifier::emitCatch(Try* curr, Index i) {
- auto& scope = scopeStack.back();
- WASM_UNUSED(scope);
+ [[maybe_unused]] auto& scope = scopeStack.back();
if (i == 0) {
assert(scope.kind == Scope::Try);
patchScope(curr->body);
@@ -264,8 +262,7 @@ void Poppifier::emitCatch(Try* curr, Index i) {
}
void Poppifier::emitCatchAll(Try* curr) {
- auto& scope = scopeStack.back();
- WASM_UNUSED(scope);
+ [[maybe_unused]] auto& scope = scopeStack.back();
if (curr->catchBodies.size() == 1) {
assert(scope.kind == Scope::Try);
patchScope(curr->body);
@@ -277,8 +274,7 @@ void Poppifier::emitCatchAll(Try* curr) {
}
void Poppifier::emitDelegate(Try* curr) {
- auto& scope = scopeStack.back();
- WASM_UNUSED(scope);
+ [[maybe_unused]] auto& scope = scopeStack.back();
assert(scope.kind == Scope::Try);
patchScope(curr->body);
scopeStack.back().instrs.push_back(curr);
@@ -310,8 +306,7 @@ void Poppifier::emitScopeEnd(Expression* curr) {
}
void Poppifier::emitFunctionEnd() {
- auto& scope = scopeStack.back();
- WASM_UNUSED(scope);
+ [[maybe_unused]] auto& scope = scopeStack.back();
assert(scope.kind == Scope::Func);
patchScope(func->body);
}
diff --git a/src/support/threads.cpp b/src/support/threads.cpp
index ab9de4175..bd026b69c 100644
--- a/src/support/threads.cpp
+++ b/src/support/threads.cpp
@@ -216,8 +216,7 @@ void ThreadPool::notifyThreadIsReady() {
void ThreadPool::resetThreadsAreReady() {
DEBUG_POOL("reset threads are ready\n";)
- auto old = ready.exchange(0);
- WASM_UNUSED(old);
+ [[maybe_unused]] auto old = ready.exchange(0);
assert(old == threads.size());
}
diff --git a/src/support/threads.h b/src/support/threads.h
index 8a04f78bd..ca13abf4e 100644
--- a/src/support/threads.h
+++ b/src/support/threads.h
@@ -22,6 +22,7 @@
#define wasm_support_threads_h
#include <atomic>
+#include <cassert>
#include <condition_variable>
#include <functional>
#include <memory>
@@ -125,8 +126,7 @@ public:
OnlyOnce() { created.store(0); }
void verify() {
- auto before = created.fetch_add(1);
- WASM_UNUSED(before);
+ [[maybe_unused]] auto before = created.fetch_add(1);
assert(before == 0);
}
};
diff --git a/src/tools/wasm-reduce.cpp b/src/tools/wasm-reduce.cpp
index d92e0a93c..078eca648 100644
--- a/src/tools/wasm-reduce.cpp
+++ b/src/tools/wasm-reduce.cpp
@@ -935,7 +935,6 @@ struct Reducer
// process things here, we may replace the module, so we should never again
// refer to curr.
assert(curr == module.get());
- WASM_UNUSED(curr);
curr = nullptr;
// Reduction of entire functions at a time is very effective, and we do it
diff --git a/src/tools/wasm-shell.cpp b/src/tools/wasm-shell.cpp
index 61b35e6db..70f52a038 100644
--- a/src/tools/wasm-shell.cpp
+++ b/src/tools/wasm-shell.cpp
@@ -193,7 +193,7 @@ protected:
}
void parseAssertTrap(Element& s) {
- bool trapped = false;
+ [[maybe_unused]] bool trapped = false;
auto& inner = *s[1];
if (inner[0]->str() == MODULE) {
return parseModuleAssertion(s);
@@ -207,7 +207,6 @@ protected:
std::cout << "[exception thrown: " << e << "]" << std::endl;
trapped = true;
}
- WASM_UNUSED(trapped);
assert(trapped);
}
@@ -218,7 +217,7 @@ protected:
expected = getLiteralsFromConstExpression(
builders[lastModule]->parseExpression(*s[2]));
}
- bool trapped = false;
+ [[maybe_unused]] bool trapped = false;
try {
actual = parseOperation(*s[1]);
} catch (const TrapException&) {
@@ -227,7 +226,6 @@ protected:
std::cout << "[exception thrown: " << e << "]" << std::endl;
trapped = true;
}
- WASM_UNUSED(trapped);
assert(!trapped);
std::cerr << "seen " << actual << ", expected " << expected << '\n';
if (expected != actual) {
diff --git a/src/tools/wasm2c-wrapper.h b/src/tools/wasm2c-wrapper.h
index f44fc5ca0..984a9b53a 100644
--- a/src/tools/wasm2c-wrapper.h
+++ b/src/tools/wasm2c-wrapper.h
@@ -203,8 +203,7 @@ int main(int argc, char** argv) {
// Emit the parameters (all 0s, like the other wrappers).
bool first = true;
- for (const auto& param : func->getParams()) {
- WASM_UNUSED(param);
+ for ([[maybe_unused]] const auto& param : func->getParams()) {
if (!first) {
ret += ", ";
}
diff --git a/src/wasm-binary.h b/src/wasm-binary.h
index cc291f163..1ca136f07 100644
--- a/src/wasm-binary.h
+++ b/src/wasm-binary.h
@@ -203,8 +203,7 @@ public:
return *this;
}
BufferWithRandomAccess& operator<<(U32LEB x) {
- size_t before = -1;
- WASM_UNUSED(before);
+ [[maybe_unused]] size_t before = -1;
BYN_DEBUG(before = size(); std::cerr << "writeU32LEB: " << x.value
<< " (at " << before << ")"
<< std::endl;);
@@ -215,8 +214,7 @@ public:
return *this;
}
BufferWithRandomAccess& operator<<(U64LEB x) {
- size_t before = -1;
- WASM_UNUSED(before);
+ [[maybe_unused]] size_t before = -1;
BYN_DEBUG(before = size(); std::cerr << "writeU64LEB: " << x.value
<< " (at " << before << ")"
<< std::endl;);
@@ -227,8 +225,7 @@ public:
return *this;
}
BufferWithRandomAccess& operator<<(S32LEB x) {
- size_t before = -1;
- WASM_UNUSED(before);
+ [[maybe_unused]] size_t before = -1;
BYN_DEBUG(before = size(); std::cerr << "writeS32LEB: " << x.value
<< " (at " << before << ")"
<< std::endl;);
@@ -239,8 +236,7 @@ public:
return *this;
}
BufferWithRandomAccess& operator<<(S64LEB x) {
- size_t before = -1;
- WASM_UNUSED(before);
+ [[maybe_unused]] size_t before = -1;
BYN_DEBUG(before = size(); std::cerr << "writeS64LEB: " << x.value
<< " (at " << before << ")"
<< std::endl;);
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index fec572470..e06d550b1 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -3515,8 +3515,7 @@ public:
auto heapType = curr->type.getHeapType();
const auto& element = heapType.getArray().element;
- auto elemType = heapType.getArray().element.type;
- WASM_UNUSED(elemType);
+ [[maybe_unused]] auto elemType = heapType.getArray().element.type;
Literals contents;
diff --git a/src/wasm-traversal.h b/src/wasm-traversal.h
index 9573bc21a..32225fd3f 100644
--- a/src/wasm-traversal.h
+++ b/src/wasm-traversal.h
@@ -352,8 +352,7 @@ struct PostWalker : public Walker<SubType, VisitorType> {
#define DELEGATE_START(id) \
self->pushTask(SubType::doVisit##id, currp); \
- auto* cast = curr->cast<id>(); \
- WASM_UNUSED(cast);
+ [[maybe_unused]] auto* cast = curr->cast<id>();
#define DELEGATE_GET_FIELD(id, field) cast->field
diff --git a/src/wasm/wasm-binary.cpp b/src/wasm/wasm-binary.cpp
index c2a7dfff3..d7a424695 100644
--- a/src/wasm/wasm-binary.cpp
+++ b/src/wasm/wasm-binary.cpp
@@ -3176,8 +3176,7 @@ void WasmBinaryBuilder::readElementSegments() {
if (isDeclarative) {
// Declared segments are needed in wasm text and binary, but not in
// Binaryen IR; skip over the segment
- auto type = getU32LEB();
- WASM_UNUSED(type);
+ [[maybe_unused]] auto type = getU32LEB();
auto num = getU32LEB();
for (Index i = 0; i < num; i++) {
getU32LEB();