Skip to content

GCC PR109267: g++ -Og generates empty functions with incorrect FDE; the output doesn't handle exceptions when linked with ld.lld #61434

Open
@FlorianChevassu

Description

@FlorianChevassu

Consider the following simple example:

lib.cpp

#include "lib.h"
#include <stdexcept>
void test(const T_value& entry_value) {
    boost::apply_visitor([](const auto& value) { test(value); },
                         entry_value);
}
void test(const Obj_1& ) {
    throw std::runtime_error("Obj_1");
}
void test(const Obj_2& ) {
    throw std::runtime_error("Obj_2");
}

lib.h

#pragma once

#include <string>
#include <boost/variant.hpp>

struct Obj_1 {
    std::string oid;
};
struct Obj_2 {
    std::string oid;
};

using T_value = boost::make_recursive_variant<
        Obj_1,
        Obj_2>::type;
void test(const T_value&);
void test(const Obj_2&);
void test(const Obj_1&);

main.cpp

#include "lib.h"
#include <stdexcept>

int main() {
    try {
        test(Obj_2{"foo"});
    } catch (const std::runtime_error& e) {
    }
    try {
        test(Obj_1{"foo"});
    } catch (const std::runtime_error& e) {
    }
} 

When building the code using g++ and linking with lld, the exception thrown by the call to test(Obj_1{"foo"}); is never caught, and the program terminates.

Please note that the program executes successfully with the following configurations:

  • compile with g++ and link with ld,
  • compile with clang++ and link with lld.
  • if we add a dummy function implementation at the top of lib.cpp

The versions of the software used are the following:

  • LLVM: 15.0.7 (installed with bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)")
  • GCC 12.2.0

A docker image with all the dependencies reproducing the issue is available in the example.

Please let me know if you need more information, or if the issue should be on the GCC side.

Best regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidResolved as invalid, i.e. not a buglldlld:ELF

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions