37 lines · c
1// RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s2 3typedef void(fatal_fun)() __attribute__((__noreturn__));4fatal_fun* fatal_fptr;5void fatal_decl() __attribute__((__noreturn__));6 7int rng();8 9/// This code calls a [[noreturn]] function pointer, which used to be handled10/// inconsistently between AST builder and CSA.11/// In the result, CSA produces a path where this function returns non-0.12int return_zero_or_abort_by_fnptr() {13 if (rng()) fatal_fptr();14 return 0;15}16 17/// This function calls a [[noreturn]] function.18/// If it does return, it always returns 0.19int return_zero_or_abort_by_direct_fun() {20 if (rng()) fatal_decl();21 return 0;22}23 24/// Trigger a division by zero issue depending on the return value25/// of the called functions.26int caller() {27 int x = 0;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.33 34 // Make sure the warning is still reported when viable.35 return 1 / x; // expected-warning {{Division by zero}}36}37