--- /dev/null
+/* { dg-do run } */
+/* { dg-options "-fsanitize=unsigned-integer-overflow,signed-integer-overflow" } */
+/* { dg-set-target-env-var UBSAN_OPTIONS "suppressions_isan=$srcdir/c-c++-common/isan/isan.supp" } */
+
+__attribute__((noinline, noclone))
+void foo ()
+{
+ volatile unsigned int x = __UINT32_MAX__;
+ volatile unsigned int y = x + 1;
+}
+
+__attribute__((noinline, noclone))
+void bar ()
+{
+ volatile int a = __INT_MAX__;
+ volatile int b = a + 1;
+
+ volatile unsigned int x = __UINT32_MAX__;
+ volatile unsigned int y = x + 1;
+}
+
+__attribute__((noinline, noclone))
+void xyz ()
+{
+ foo ();
+ bar ();
+}
+
+int main ()
+{
+ foo ();
+ bar ();
+ xyz ();
+
+ for (int i = 0; i < 2; i++)
+ {
+ foo ();
+ bar ();
+ xyz ();
+ }
+
+ return 0;
+}
+
+/* { dg-output "suppressions.c:9:31: runtime error: unsigned integer overflow: 4294967295 \\+ 1 cannot be represented in type 'unsigned int'\[^\n\r]*(\n|\r\n|\r)" } */
+/* { dg-output "\[^\n\r]*suppressions.c:16:22: runtime error: signed integer overflow: 2147483647 \\+ 1 cannot be represented in type 'int'" } */
}
ALIGNED(64) static char suppression_placeholder[sizeof(SuppressionContext)];
+ALIGNED(64) static char suppression_placeholder_isan[sizeof(SuppressionContext)];
+static bool isan_use_file_suppressions;
+static bool isan_use_function_suppressions;
static SuppressionContext *suppression_ctx = nullptr;
+static SuppressionContext *suppression_ctx_isan = nullptr;
static const char kVptrCheck[] = "vptr_check";
+static const char kFunctionCheck[] = "function";
+static const char kFileCheck[] = "file";
static const char *kSuppressionTypes[] = {
#define UBSAN_CHECK(Name, SummaryKind, FSanitizeFlagName) FSanitizeFlagName,
#include "ubsan_checks.inc"
#undef UBSAN_CHECK
kVptrCheck,
};
+static const char *kSuppressionTypesISan[] = { kFunctionCheck, kFileCheck };
void __ubsan::InitializeSuppressions() {
CHECK_EQ(nullptr, suppression_ctx);
suppression_ctx = new (suppression_placeholder) // NOLINT
SuppressionContext(kSuppressionTypes, ARRAY_SIZE(kSuppressionTypes));
suppression_ctx->ParseFromFile(flags()->suppressions);
+ CHECK_EQ(nullptr, suppression_ctx_isan);
+ suppression_ctx_isan = new (suppression_placeholder_isan) // NOLINT
+ SuppressionContext(kSuppressionTypesISan, ARRAY_SIZE(kSuppressionTypesISan));
+ suppression_ctx_isan->ParseFromFile(flags()->suppressions_isan);
+ isan_use_file_suppressions =
+ suppression_ctx_isan->HasSuppressionType(kFileCheck);
+ isan_use_function_suppressions =
+ suppression_ctx_isan->HasSuppressionType(kFunctionCheck);
}
bool __ubsan::IsVptrCheckSuppressed(const char *TypeName) {
suppression_ctx->Match(AI.file, SuppType, &s);
}
+bool __ubsan::IsISanFileCheckSuppressed(SourceLocation *SLoc) {
+ InitAsStandaloneIfNecessary();
+ if (LIKELY(!isan_use_file_suppressions))
+ return false;
+ CHECK(suppression_ctx_isan);
+ Suppression *s;
+ const char *file_name = SLoc->getFilename();
+ if (file_name && suppression_ctx_isan->Match(file_name, kFileCheck, &s))
+ return true;
+ return false;
+}
+
+bool __ubsan::IsISanFunctionCheckSuppressed(ReportOptions *Opts) {
+ InitAsStandaloneIfNecessary();
+ if (LIKELY(!isan_use_function_suppressions))
+ return false;
+ CHECK(suppression_ctx_isan);
+ SymbolizedStack *frames = Symbolizer::GetOrInit()->SymbolizePC(Opts->pc);
+ Suppression *s;
+ for (SymbolizedStack *cur = frames; cur; cur = cur->next) {
+ const char *function_name = cur->info.function;
+ if (!function_name)
+ continue;
+ if (suppression_ctx_isan->Match(function_name, kFunctionCheck, &s)) {
+ frames->ClearAll();
+ return true;
+ }
+ }
+ frames->ClearAll();
+ return false;
+}
+
#endif // CAN_SANITIZE_UB
"Crash the program after printing the first error report")
UBSAN_FLAG(bool, print_stacktrace, false,
"Include full stacktrace into an error report")
-UBSAN_FLAG(const char *, suppressions, "", "Suppressions file name.")
+UBSAN_FLAG(const char *, suppressions, "", "UBSan suppressions file name.")
+UBSAN_FLAG(const char *, suppressions_isan, "", "ISan suppressions file name.")
UBSAN_FLAG(bool, report_error_type, false,
"Print specific error type instead of 'undefined-behavior' in summary.")