#include "ubsan_monitor.h"
using namespace __ubsan;
UndefinedBehaviorReport::UndefinedBehaviorReport(const char *IssueKind,
Location &Loc,
InternalScopedString &Msg)
: IssueKind(IssueKind), Loc(Loc) {
RegisterUndefinedBehaviorReport(this);
if (Msg.length())
Buffer.Append(Msg.data());
__ubsan_on_report();
}
static UndefinedBehaviorReport *CurrentUBR;
void __ubsan::RegisterUndefinedBehaviorReport(UndefinedBehaviorReport *UBR) {
CurrentUBR = UBR;
}
SANITIZER_WEAK_DEFAULT_IMPL
void __ubsan::__ubsan_on_report(void) {}
void __ubsan::__ubsan_get_current_report_data(const char **OutIssueKind,
const char **OutMessage,
const char **OutFilename,
unsigned *OutLine,
unsigned *OutCol,
char **OutMemoryAddr) {
if (!OutIssueKind || !OutMessage || !OutFilename || !OutLine || !OutCol ||
!OutMemoryAddr)
UNREACHABLE("Invalid arguments passed to __ubsan_get_current_report_data");
InternalScopedString &Buf = CurrentUBR->Buffer;
char FirstChar = *Buf.data();
if (FirstChar >= 'a' && FirstChar <= 'z')
*Buf.data() += 'A' - 'a';
*OutIssueKind = CurrentUBR->IssueKind;
*OutMessage = Buf.data();
if (!CurrentUBR->Loc.isSourceLocation()) {
*OutFilename = "<unknown>";
*OutLine = *OutCol = 0;
} else {
SourceLocation SL = CurrentUBR->Loc.getSourceLocation();
*OutFilename = SL.getFilename();
*OutLine = SL.getLine();
*OutCol = SL.getColumn();
}
if (CurrentUBR->Loc.isMemoryLocation())
*OutMemoryAddr = (char *)CurrentUBR->Loc.getMemoryLocation();
else
*OutMemoryAddr = nullptr;
}