1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
3 typedef void(fatal_fun
)() __attribute__((__noreturn__
));
5 void fatal_decl() __attribute__((__noreturn__
));
9 /// This code calls a [[noreturn]] function pointer, which used to be handled
10 /// inconsistently between AST builder and CSA.
11 /// In the result, CSA produces a path where this function returns non-0.
12 int return_zero_or_abort_by_fnptr() {
13 if (rng()) fatal_fptr();
17 /// This function calls a [[noreturn]] function.
18 /// If it does return, it always returns 0.
19 int return_zero_or_abort_by_direct_fun() {
20 if (rng()) fatal_decl();
24 /// Trigger a division by zero issue depending on the return value
25 /// of the called functions.
28 // The following if branches must never be taken.
29 if (return_zero_or_abort_by_fnptr())
30 return 1 / x
; // no-warning: Dead code.
31 if (return_zero_or_abort_by_direct_fun())
32 return 1 / x
; // no-warning: Dead code.
34 // Make sure the warning is still reported when viable.
35 return 1 / x
; // expected-warning {{Division by zero}}