brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · e91d0ac Raw
48 lines · cpp
1// This test check that LSDA section named by .gcc_except_table.main is2// disassembled by BOLT.3 4// RUN: %clangxx %cxxflags -O3 -no-pie -c %s -o %t.o5// RUN: %clangxx %cxxflags -O3 -no-pie -fuse-ld=lld %t.o -o %t6// RUN: llvm-objcopy --rename-section .gcc_except_table=.gcc_except_table.main %t7// RUN: llvm-readelf -SW %t | FileCheck %s8// RUN: llvm-bolt %t -o %t.bolt9 10// CHECK: .gcc_except_table.main11 12#include <iostream>13 14class MyException : public std::exception {15public:16  const char *what() const throw() {17    return "Custom Exception: an error occurred!";18  }19};20 21int divide(int a, int b) {22  if (b == 0) {23    throw MyException();24  }25  return a / b;26}27 28int main() {29  try {30    int result = divide(10, 2); // normal case31    std::cout << "Result: " << result << std::endl;32    result = divide(5, 0); // will cause exception33    std::cout << "Result: " << result << std::endl;34    // this line will not execute35  } catch (const MyException &e) {36    // catch custom exception37    std::cerr << "Caught exception: " << e.what() << std::endl;38  } catch (const std::exception &e) {39    // catch other C++ exceptions40    std::cerr << "Caught exception: " << e.what() << std::endl;41  } catch (...) {42    // catch all other exceptions43    std::cerr << "Caught unknown exception" << std::endl;44  }45 46  return 0;47}48