CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
97 lines
2.5 KiB
C
97 lines
2.5 KiB
C
// RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -c %s -o %t-callbacks.o
|
|
// RUN: %clang_dfsan -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-conditional-callbacks %s %t-callbacks.o -o %t
|
|
// RUN: %run %t FooBarBaz 2>&1 | FileCheck %s
|
|
|
|
#include <assert.h>
|
|
#include <sanitizer/dfsan_interface.h>
|
|
#include <signal.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef CALLBACKS
|
|
// Compile this code without DFSan to avoid recursive instrumentation.
|
|
|
|
void my_dfsan_conditional_callback(dfsan_label Label, dfsan_origin Origin) {
|
|
assert(Label != 0);
|
|
assert(Origin == 0);
|
|
|
|
static int Count = 0;
|
|
switch (Count++) {
|
|
case 0:
|
|
assert(Label == 1);
|
|
break;
|
|
case 1:
|
|
assert(Label == 4);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
fprintf(stderr, "Label %u used as condition\n", Label);
|
|
}
|
|
|
|
#else
|
|
// Compile this code with DFSan and -dfsan-conditional-callbacks to insert the
|
|
// callbacks.
|
|
|
|
extern void my_dfsan_conditional_callback(dfsan_label Label,
|
|
dfsan_origin Origin);
|
|
|
|
volatile int x = 0;
|
|
volatile int y = 1;
|
|
volatile int z = 0;
|
|
|
|
void SignalHandler(int signo) {
|
|
assert(dfsan_get_label(x) == 0);
|
|
assert(dfsan_get_label(y) != 0);
|
|
assert(dfsan_get_label(z) != 0);
|
|
// Running the conditional callback from a signal handler is risky,
|
|
// because the code must be written with signal handler context in mind.
|
|
// Instead dfsan_get_labels_in_signal_conditional() will indicate labels
|
|
// used in conditions inside signal handlers.
|
|
// CHECK-NOT: Label 8 used as condition
|
|
if (z != 0) {
|
|
x = y;
|
|
}
|
|
}
|
|
|
|
int main(int Argc, char *Argv[]) {
|
|
assert(Argc >= 1);
|
|
int unknown = (Argv[0][0] != 0) ? 1 : 0;
|
|
dfsan_set_label(1, &unknown, sizeof(unknown));
|
|
|
|
dfsan_set_conditional_callback(my_dfsan_conditional_callback);
|
|
|
|
// CHECK: Label 1 used as condition
|
|
if (unknown) {
|
|
z = 42;
|
|
}
|
|
|
|
assert(dfsan_get_labels_in_signal_conditional() == 0);
|
|
dfsan_set_label(4, (void *)&y, sizeof(y));
|
|
dfsan_set_label(8, (void *)&z, sizeof(z));
|
|
|
|
struct sigaction sa = {};
|
|
sa.sa_handler = SignalHandler;
|
|
int r = sigaction(SIGHUP, &sa, NULL);
|
|
assert(dfsan_get_label(r) == 0);
|
|
|
|
kill(getpid(), SIGHUP);
|
|
signal(SIGHUP, SIG_DFL);
|
|
|
|
assert(dfsan_get_labels_in_signal_conditional() == 8);
|
|
assert(x == 1);
|
|
// CHECK: Label 4 used as condition
|
|
if (x != 0) {
|
|
z = 123;
|
|
}
|
|
// Flush should clear the conditional signals seen.
|
|
dfsan_flush();
|
|
assert(dfsan_get_labels_in_signal_conditional() == 0);
|
|
return 0;
|
|
}
|
|
|
|
#endif // #ifdef CALLBACKS
|