ctest_memcheck: Add support for UndefinedBehaviorSanitizer ubsan

UBSan instruments a build and logs messages on any undefined behavior
instances.
This commit is contained in:
Ben Boeckel 2014-10-03 13:46:18 -04:00 committed by Brad King
parent b67ef537d4
commit 816c100ae2
3 changed files with 25 additions and 3 deletions

View File

@ -4,4 +4,4 @@ CTEST_MEMORYCHECK_TYPE
Specify the CTest ``MemoryCheckType`` setting Specify the CTest ``MemoryCheckType`` setting
in a :manual:`ctest(1)` dashboard client script. in a :manual:`ctest(1)` dashboard client script.
Valid values are Valgrind, Purify, BoundsChecker, and ThreadSanitizer, Valid values are Valgrind, Purify, BoundsChecker, and ThreadSanitizer,
and AddressSanitizer. AddressSanitizer, and UndefinedBehaviorSanitizer.

View File

@ -376,6 +376,9 @@ void cmCTestMemCheckHandler::GenerateDartOutput(std::ostream& os)
case cmCTestMemCheckHandler::THREAD_SANITIZER: case cmCTestMemCheckHandler::THREAD_SANITIZER:
os << "ThreadSanitizer"; os << "ThreadSanitizer";
break; break;
case cmCTestMemCheckHandler::UB_SANITIZER:
os << "UndefinedBehaviorSanitizer";
break;
default: default:
os << "Unknown"; os << "Unknown";
} }
@ -552,6 +555,14 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER; this->MemoryTesterStyle = cmCTestMemCheckHandler::THREAD_SANITIZER;
this->LogWithPID = true; // even if we give the log file the pid is added this->LogWithPID = true; // even if we give the log file the pid is added
} }
if ( this->CTest->GetCTestConfiguration("MemoryCheckType")
== "UndefinedBehaviorSanitizer")
{
this->MemoryTester
= this->CTest->GetCTestConfiguration("CMakeCommand").c_str();
this->MemoryTesterStyle = cmCTestMemCheckHandler::UB_SANITIZER;
this->LogWithPID = true; // even if we give the log file the pid is added
}
// Check the MemoryCheckType // Check the MemoryCheckType
if(this->MemoryTesterStyle == cmCTestMemCheckHandler::UNKNOWN) if(this->MemoryTesterStyle == cmCTestMemCheckHandler::UNKNOWN)
{ {
@ -677,6 +688,7 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
// these are almost the same but the env var used is different // these are almost the same but the env var used is different
case cmCTestMemCheckHandler::ADDRESS_SANITIZER: case cmCTestMemCheckHandler::ADDRESS_SANITIZER:
case cmCTestMemCheckHandler::THREAD_SANITIZER: case cmCTestMemCheckHandler::THREAD_SANITIZER:
case cmCTestMemCheckHandler::UB_SANITIZER:
{ {
// To pass arguments to ThreadSanitizer the environment variable // To pass arguments to ThreadSanitizer the environment variable
// TSAN_OPTIONS is used. This is done with the cmake -E env command. // TSAN_OPTIONS is used. This is done with the cmake -E env command.
@ -698,6 +710,10 @@ bool cmCTestMemCheckHandler::InitializeMemoryChecking()
{ {
envVar = "TSAN_OPTIONS"; envVar = "TSAN_OPTIONS";
} }
else if(this->MemoryTesterStyle == cmCTestMemCheckHandler::UB_SANITIZER)
{
envVar = "UBSAN_OPTIONS";
}
std::string outputFile = envVar + "=log_path=\"" std::string outputFile = envVar + "=log_path=\""
+ this->MemoryTesterOutputFile + "\" "; + this->MemoryTesterOutputFile + "\" ";
this->MemoryTesterEnvironmentVariable = outputFile + extraOptions; this->MemoryTesterEnvironmentVariable = outputFile + extraOptions;
@ -735,7 +751,9 @@ ProcessMemCheckOutput(const std::string& str,
else if ( this->MemoryTesterStyle == else if ( this->MemoryTesterStyle ==
cmCTestMemCheckHandler::ADDRESS_SANITIZER || cmCTestMemCheckHandler::ADDRESS_SANITIZER ||
this->MemoryTesterStyle == this->MemoryTesterStyle ==
cmCTestMemCheckHandler::THREAD_SANITIZER) cmCTestMemCheckHandler::THREAD_SANITIZER ||
this->MemoryTesterStyle ==
cmCTestMemCheckHandler::UB_SANITIZER)
{ {
return this->ProcessMemCheckSanitizerOutput(str, log, results); return this->ProcessMemCheckSanitizerOutput(str, log, results);
} }
@ -783,6 +801,9 @@ bool cmCTestMemCheckHandler::ProcessMemCheckSanitizerOutput(
case cmCTestMemCheckHandler::THREAD_SANITIZER: case cmCTestMemCheckHandler::THREAD_SANITIZER:
regex = "WARNING: ThreadSanitizer: (.*) \\(pid=.*\\)"; regex = "WARNING: ThreadSanitizer: (.*) \\(pid=.*\\)";
break; break;
case cmCTestMemCheckHandler::UB_SANITIZER:
regex = "runtime error: (.*)";
break;
default: default:
break; break;
} }

View File

@ -51,7 +51,8 @@ private:
BOUNDS_CHECKER, BOUNDS_CHECKER,
// checkers after here do not use the standard error list // checkers after here do not use the standard error list
ADDRESS_SANITIZER, ADDRESS_SANITIZER,
THREAD_SANITIZER THREAD_SANITIZER,
UB_SANITIZER
}; };
public: public:
enum { // Memory faults enum { // Memory faults