Skip to content

Commit

Permalink
Preserve cold attribute for function decls
Browse files Browse the repository at this point in the history
Differential Revision: http://reviews.llvm.org/D34133

llvm-svn: 305325
  • Loading branch information
david-xl committed Jun 13, 2017
1 parent 0096d78 commit 4ec3606
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions clang/lib/CodeGen/CGCall.cpp
Expand Up @@ -1795,6 +1795,8 @@ void CodeGenModule::ConstructAttributeList(
FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
if (TargetDecl->hasAttr<NoReturnAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
if (TargetDecl->hasAttr<ColdAttr>())
FuncAttrs.addAttribute(llvm::Attribute::Cold);
if (TargetDecl->hasAttr<NoDuplicateAttr>())
FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
if (TargetDecl->hasAttr<ConvergentAttr>())
Expand Down
10 changes: 10 additions & 0 deletions clang/test/CodeGen/attributes.c
Expand Up @@ -56,6 +56,13 @@ void t4() {}
void t7() __attribute__((noreturn, nothrow));
void t7() { while (1) {} }

// CHECK: define void @t72() [[COLDDEF:#[0-9]+]] {
void t71(void) __attribute__((cold));
void t72() __attribute__((cold));
void t72() { t71(); }
// CHECK: call void @t71() [[COLDSITE:#[0-9]+]]
// CHECK: declare void @t71() [[COLDDECL:#[0-9]+]]

// CHECK: define void @t10() [[NUW]] section "SECT" {
void t10(void) __attribute__((section("SECT")));
void t10(void) {}
Expand Down Expand Up @@ -92,3 +99,6 @@ void __attribute__((section(".bar"))) t22(void) {}

// CHECK: attributes [[NUW]] = { noinline nounwind{{.*}} }
// CHECK: attributes [[NR]] = { noinline noreturn nounwind{{.*}} }
// CHECK: attributes [[COLDDEF]] = { cold {{.*}}}
// CHECK: attributes [[COLDDECL]] = { cold {{.*}}}
// CHECK: attributes [[COLDSITE]] = { cold {{.*}}}

0 comments on commit 4ec3606

Please sign in to comment.