Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2607,6 +2607,15 @@ void CodeGenModule::ConstructAttributeList(StringRef Name,
if (shouldDisableTailCalls())
FuncAttrs.addAttribute("disable-tail-calls", "true");

// These functions require the returns_twice attribute for correct codegen,
// but the attribute may not be added if -fno-builtin is specified. We
// explicitly add that attribute here.
static const llvm::StringSet<> ReturnsTwiceFn{
"_setjmpex", "setjmp", "_setjmp", "vfork",
"sigsetjmp", "__sigsetjmp", "savectx", "getcontext"};
if (ReturnsTwiceFn.contains(Name))
FuncAttrs.addAttribute(llvm::Attribute::ReturnsTwice);

// CPU/feature overrides. addDefaultFunctionDefinitionAttributes
// handles these separately to set them based on the global defaults.
GetCPUAndFeaturesAttributes(CalleeInfo.getCalleeDecl(), FuncAttrs);
Expand Down
5 changes: 4 additions & 1 deletion clang/test/CodeGen/2003-08-20-vfork-bug.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// RUN: %clang_cc1 -emit-llvm %s -o /dev/null
// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -fno-builtin -o - | FileCheck %s

// CHECK: ; Function Attrs: returns_twice
// CHECK-NEXT: declare {{.*}} @vfork(
extern int vfork(void);
void test() {
vfork();
Expand Down
15 changes: 15 additions & 0 deletions clang/test/CodeGen/setjmp.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s
// RUN: %clang_cc1 -x c %s -triple x86_64-linux-gnu -emit-llvm -fno-builtin -o - | FileCheck %s
// RUN: %clang_cc1 -x c++ %s -triple x86_64-linux-gnu -emit-llvm -o - | FileCheck %s

#ifdef __cplusplus
extern "C" {
#endif

struct __jmp_buf_tag { int n; };
struct __ucontext_t_tag { int n; };
int setjmp(struct __jmp_buf_tag*);
int sigsetjmp(struct __jmp_buf_tag*, int);
int _setjmp(struct __jmp_buf_tag*);
int __sigsetjmp(struct __jmp_buf_tag*, int);
int _setjmpex(struct __jmp_buf_tag* env);
int getcontext(struct __ucontext_t_tag*);

typedef struct __jmp_buf_tag jmp_buf[1];
typedef struct __jmp_buf_tag sigjmp_buf[1];
typedef struct __ucontext_t_tag ucontext_t[1];

#ifdef __cplusplus
}
#endif

void f(void) {
jmp_buf jb;
ucontext_t ut;
// CHECK: call {{.*}}@setjmp(
setjmp(jb);
// CHECK: call {{.*}}@sigsetjmp(
Expand All @@ -28,6 +34,10 @@ void f(void) {
_setjmp(jb);
// CHECK: call {{.*}}@__sigsetjmp(
__sigsetjmp(jb, 0);
// CHECK: call {{.*}}@_setjmpex(
_setjmpex(jb);
// CHECK: call {{.*}}@getcontext(
getcontext(ut);
}

// CHECK: ; Function Attrs: returns_twice
Expand All @@ -42,3 +52,8 @@ void f(void) {
// CHECK: ; Function Attrs: returns_twice
// CHECK-NEXT: declare {{.*}} @__sigsetjmp(

// CHECK: ; Function Attrs: returns_twice
// CHECK-NEXT: declare {{.*}} @_setjmpex(

// CHECK: ; Function Attrs: returns_twice
// CHECK-NEXT: declare {{.*}} @getcontext(