Skip to content

Commit 9ca513a

Browse files
authored
asm2wasm warning improvement (#1463)
* limit the amount of asm2wasm warnings on arguments added/removed in flexible argument handling (e.g. in Python there can be many thousands of such warnings, flooding the output...) * also lock, because those warnings can come from multiple threads
1 parent 073d370 commit 9ca513a

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/asm2wasm.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,21 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
12301230
}
12311231

12321232
void notifyAboutWrongOperands(std::string why, Function* calledFunc) {
1233+
// use a mutex as this may be shown from multiple threads
1234+
static std::mutex mutex;
1235+
std::unique_lock<std::mutex> lock(mutex);
1236+
static const int MAX_SHOWN = 20;
1237+
static std::unique_ptr<std::atomic<int>> numShown;
1238+
if (!numShown) {
1239+
numShown = make_unique<std::atomic<int>>();
1240+
numShown->store(0);
1241+
}
1242+
if (numShown->load() >= MAX_SHOWN) return;
12331243
std::cerr << why << " in call from " << getFunction()->name << " to " << calledFunc->name << " (this is likely due to undefined behavior in C, like defining a function one way and calling it in another, which is important to fix)\n";
1244+
(*numShown)++;
1245+
if (numShown->load() >= MAX_SHOWN) {
1246+
std::cerr << "(" << numShown->load() << " such warnings shown; not showing any more)\n";
1247+
}
12341248
}
12351249

12361250
void visitCall(Call* curr) {

0 commit comments

Comments
 (0)