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 // Tests that callbacks are inserted for conditionals when
10 // -dfsan-conditional-callbacks is specified.
13 #include <sanitizer/dfsan_interface.h>
18 // Compile this code without DFSan to avoid recursive instrumentation.
20 extern dfsan_label LabelI
;
21 extern dfsan_label LabelJ
;
22 extern dfsan_label LabelIJ
;
24 void my_dfsan_conditional_callback(dfsan_label Label
, dfsan_origin Origin
) {
35 assert(Label
== LabelI
);
38 assert(Label
== LabelJ
);
41 assert(Label
== LabelIJ
);
47 fprintf(stderr
, "Label %u used as condition\n", Label
);
51 // Compile this code with DFSan and -dfsan-conditional-callbacks to insert the
58 extern void my_dfsan_conditional_callback(dfsan_label Label
,
61 int main(int Argc
, char *Argv
[]) {
64 dfsan_set_conditional_callback(my_dfsan_conditional_callback
);
67 // Make these not look like constants, otherwise the branch we're expecting
68 // may be optimized out.
69 int DataI
= (Argv
[0][0] != 0) ? 1 : 0;
70 int DataJ
= (Argv
[1][0] != 0) ? 2 : 0;
72 dfsan_set_label(LabelI
, &DataI
, sizeof(DataI
));
74 dfsan_set_label(LabelJ
, &DataJ
, sizeof(DataJ
));
75 LabelIJ
= dfsan_union(LabelI
, LabelJ
);
77 assert(dfsan_get_label(DataI
) == LabelI
);
79 // CHECK: Label 1 used as condition
84 fprintf(stderr
, "Result is %d\n", result
);
85 assert(dfsan_get_label(DataJ
) == LabelJ
);
87 // CHECK: Label 2 used as condition
99 int tainted_cond
= ((DataI
* DataJ
) != 1);
100 fprintf(stderr
, "Result is %d\n", result
);
101 assert(dfsan_get_label(tainted_cond
) == LabelIJ
);
103 // CHECK: Label 3 used as condition
104 result
= tainted_cond
? result
+ 420000 : 9;
106 fprintf(stderr
, "Result is %d\n", result
);
107 assert(result
== 424242);
111 #endif // #ifdef CALLBACKS