Gael Lorieul
Gael Lorieul

Reputation: 3246

How to terminate clang-instrumented program when clang-sanitizer finds an error?

Say I have the following program:

#include <iostream>

float foo(float f)
    { return (f / 0); }

int main(void) {
    foo(1.0f);
    std::cout << "hello" << std::endl;
}

If I invoke clang++ -fsanitize=undefined main.cpp && ./a.out then it will output:

main.cpp:4:32: runtime error: division by zero
hello

Is there a way to terminate a.out as soon as an error is detected? I.e. in such a way that it displays:

main.cpp:4:32: runtime error: division by zero

without displaying hello on the following line? (because it will have terminated before)

Upvotes: 4

Views: 233

Answers (1)

Holt
Holt

Reputation: 37661

You need to use the -fno-sanitize-recover command line argument:

clang++ -fsanitize=undefined -fno-sanitize-recover=undefined main.cpp

Upvotes: 5

Related Questions