1 // RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -c %s -o %t-callbacks.o
2 // RUN: %clang_dfsan -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-conditional-callbacks %s %t-callbacks.o -o %t
3 // RUN: %run %t FooBarBaz 2>&1 | FileCheck %s
5 // RUN: %clang_dfsan -fno-sanitize=dataflow -O2 -fPIE -DCALLBACKS -DORIGINS -c %s -o %t-callbacks-orig.o
6 // RUN: %clang_dfsan -fsanitize-ignorelist=%S/Inputs/flags_abilist.txt -O2 -mllvm -dfsan-conditional-callbacks -mllvm -dfsan-track-origins=1 -DORIGINS %s %t-callbacks-orig.o -o %t-orig
7 // RUN: %run %t-orig FooBarBaz 2>&1 | FileCheck %s
9 // REQUIRES: x86_64-target-arch
11 // Tests that callbacks are inserted for conditionals when
12 // -dfsan-conditional-callbacks is specified.
15 #include <sanitizer/dfsan_interface.h>
20 // Compile this code without DFSan to avoid recursive instrumentation.
22 extern dfsan_label LabelI
;
23 extern dfsan_label LabelJ
;
24 extern dfsan_label LabelIJ
;
26 void my_dfsan_conditional_callback(dfsan_label Label
, dfsan_origin Origin
) {
37 assert(Label
== LabelI
);
40 assert(Label
== LabelJ
);
43 assert(Label
== LabelIJ
);
49 fprintf(stderr
, "Label %u used as condition\n", Label
);
53 // Compile this code with DFSan and -dfsan-conditional-callbacks to insert the
60 extern void my_dfsan_conditional_callback(dfsan_label Label
,
63 int main(int Argc
, char *Argv
[]) {
66 dfsan_set_conditional_callback(my_dfsan_conditional_callback
);
69 // Make these not look like constants, otherwise the branch we're expecting
70 // may be optimized out.
71 int DataI
= (Argv
[0][0] != 0) ? 1 : 0;
72 int DataJ
= (Argv
[1][0] != 0) ? 2 : 0;
74 dfsan_set_label(LabelI
, &DataI
, sizeof(DataI
));
76 dfsan_set_label(LabelJ
, &DataJ
, sizeof(DataJ
));
77 LabelIJ
= dfsan_union(LabelI
, LabelJ
);
79 assert(dfsan_get_label(DataI
) == LabelI
);
81 // CHECK: Label 1 used as condition
86 assert(dfsan_get_label(DataJ
) == LabelJ
);
88 // CHECK: Label 2 used as condition
100 int tainted_cond
= ((DataI
* DataJ
) != 1);
101 assert(dfsan_get_label(tainted_cond
) == LabelIJ
);
103 // CHECK: Label 3 used as condition
104 result
= tainted_cond
? result
+ 420000 : 9;
106 assert(result
== 424242);
110 #endif // #ifdef CALLBACKS