Files
clang-p2996/bolt/test/lsda-section-name.cpp
Maksim Panchenko 445f6f1373 [BOLT][TEST] Remove LTO flag from a test (#72896)
The LTO flag is not needed for the test to work properly. However, it
may not build on a system where compiler and linker versions don't match
one another. Remove the LTO flag.
2023-11-20 10:24:34 -08:00

48 lines
1.3 KiB
C++

// This test check that LSDA section named by .gcc_except_table.main is
// disassembled by BOLT.
// RUN: %clang++ %cxxflags -O3 -no-pie -c %s -o %t.o
// RUN: %clang++ %cxxflags -no-pie -fuse-ld=lld %t.o -o %t.exe \
// RUN: -Wl,-q -Wl,--script=%S/Inputs/lsda.ldscript
// RUN: llvm-readelf -SW %t.exe | FileCheck %s
// RUN: llvm-bolt %t.exe -o %t.bolt
// CHECK: .gcc_except_table.main
#include <iostream>
class MyException : public std::exception {
public:
const char *what() const throw() {
return "Custom Exception: an error occurred!";
}
};
int divide(int a, int b) {
if (b == 0) {
throw MyException();
}
return a / b;
}
int main() {
try {
int result = divide(10, 2); // normal case
std::cout << "Result: " << result << std::endl;
result = divide(5, 0); // will cause exception
std::cout << "Result: " << result << std::endl;
// this line will not execute
} catch (const MyException &e) {
// catch custom exception
std::cerr << "Caught exception: " << e.what() << std::endl;
} catch (const std::exception &e) {
// catch other C++ exceptions
std::cerr << "Caught exception: " << e.what() << std::endl;
} catch (...) {
// catch all other exceptions
std::cerr << "Caught unknown exception" << std::endl;
}
return 0;
}