[AMDGPU][AsmParser][NFC] Get rid of custom default operand handlers.
[llvm-project.git] / clang / test / Analysis / no-return.c
blob872604ebd71d4231d1aa467b1693696c5ee97911
1 // RUN: %clang_analyze_cc1 -analyzer-checker=core -verify %s
3 typedef void(fatal_fun)() __attribute__((__noreturn__));
4 fatal_fun* fatal_fptr;
5 void fatal_decl() __attribute__((__noreturn__));
7 int rng();
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();
14 return 0;
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();
21 return 0;
24 /// Trigger a division by zero issue depending on the return value
25 /// of the called functions.
26 int 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.
34 // Make sure the warning is still reported when viable.
35 return 1 / x; // expected-warning {{Division by zero}}