1// RUN: %clang %S/Inputs/returns-unexpectedly.c -O3 -c -o %t.ru.o
2// RUN: %clangxx -fsanitize=unreachable -O3 -o %t %s %t.ru.o
3// RUN: not %run %t builtin 2>&1 | FileCheck %s -check-prefix=BUILTIN
4// RUN: not %run %t noreturn-callee-marked 2>&1 | FileCheck %s -check-prefix=NORETURN1
5// RUN: not %run %t noreturn-caller-marked 2>&1 | FileCheck %s -check-prefix=NORETURN2
6
7#include <string.h>
8
9void __attribute__((noreturn)) callee_marked_noreturn() {
10 // NORETURN1: unreachable.cpp:[[@LINE+1]]:1: runtime error: execution reached an unreachable program point
11}
12
13extern "C" void __attribute__((noreturn)) returns_unexpectedly();
14
15int main(int, char **argv) {
16 if (strcmp(s1: argv[1], s2: "builtin") == 0)
17 // BUILTIN: unreachable.cpp:[[@LINE+1]]:5: runtime error: execution reached an unreachable program point
18 __builtin_unreachable();
19 else if (strcmp(s1: argv[1], s2: "noreturn-callee-marked") == 0)
20 callee_marked_noreturn();
21 else if (strcmp(s1: argv[1], s2: "noreturn-caller-marked") == 0)
22 // NORETURN2: unreachable.cpp:[[@LINE+1]]:5: runtime error: execution reached an unreachable program point
23 returns_unexpectedly();
24 return 0;
25}
26

source code of compiler-rt/test/ubsan/TestCases/Misc/unreachable.cpp