[clang-repl] [codegen] Reduce the state in TBAA. NFC for static compilation. (#98138)
[llvm-project.git] / bolt / test / lsda-section-name.cpp
blob929b17f3b63d42d879d85bac0af234a646e547d1
1 // This test check that LSDA section named by .gcc_except_table.main is
2 // disassembled by BOLT.
4 // RUN: %clang++ %cxxflags -O3 -no-pie -c %s -o %t.o
5 // RUN: %clang++ %cxxflags -O3 -no-pie -fuse-ld=lld %t.o -o %t
6 // RUN: llvm-objcopy --rename-section .gcc_except_table=.gcc_except_table.main %t
7 // RUN: llvm-readelf -SW %t | FileCheck %s
8 // RUN: llvm-bolt %t -o %t.bolt
10 // CHECK: .gcc_except_table.main
12 #include <iostream>
14 class MyException : public std::exception {
15 public:
16 const char *what() const throw() {
17 return "Custom Exception: an error occurred!";
21 int divide(int a, int b) {
22 if (b == 0) {
23 throw MyException();
25 return a / b;
28 int main() {
29 try {
30 int result = divide(10, 2); // normal case
31 std::cout << "Result: " << result << std::endl;
32 result = divide(5, 0); // will cause exception
33 std::cout << "Result: " << result << std::endl;
34 // this line will not execute
35 } catch (const MyException &e) {
36 // catch custom exception
37 std::cerr << "Caught exception: " << e.what() << std::endl;
38 } catch (const std::exception &e) {
39 // catch other C++ exceptions
40 std::cerr << "Caught exception: " << e.what() << std::endl;
41 } catch (...) {
42 // catch all other exceptions
43 std::cerr << "Caught unknown exception" << std::endl;
46 return 0;