llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.77k stars 11.9k forks source link

Clang fails to add uwtable to some functions #19587

Open llvmbot opened 10 years ago

llvmbot commented 10 years ago
Bugzilla Link 19213
Version unspecified
OS All
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@DougGregor

Extended Description

When compiling

int f1();
int i = f1();

clang fails to add uwtable to _GLOBAL__I_a. This means that when building without exceptions, we don't add an entry for it in .eh_table, which violates the ABI.

GCC produces one:

    .type   _GLOBAL__sub_I_i, @function
_GLOBAL__sub_I_i:
.LFB1:
    .cfi_startproc
....
dwblaikie commented 10 years ago

Most of Clang's codegen uses CodeGenModule::SetLLVMFunctionAttributesForDefinition which (correctly?) sets UWTable based on CodeGenOpts.UnwindTables.

Global ctors/dtors use CGDeclCXX.cpp:CreateGlobalInitOrDestructFunction which doesn't handle UWTable (and looks like it doesn't adequately check for nounwind - it just checks LangOpts.Exceptions, whereas CodeGenModule uses CodeGenModule.cpp:hasUnwindExceptions, which checks LangOpts.Exceptions, LangOpts.CXXEcxeptions, and LangOpts.ObjCExceptions)

We should probably factor out the common parts of SetLLVMFunctionAttributesForDefinition (the ones that don't actually rely on the Clang AST Decl object) and reuse them from CreateGlobalInitOrDetsructFunction.