diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -893,6 +893,9 @@ if (D && D->hasAttr()) Fn->addFnAttr("cfi-canonical-jump-table"); + if (D && D->hasAttr()) + Fn->addFnAttr(llvm::Attribute::NoProfile); + if (getLangOpts().OpenCL) { // Add metadata for a kernel function. if (const FunctionDecl *FD = dyn_cast_or_null(D)) diff --git a/clang/test/CodeGen/fprofile-instrument.c b/clang/test/CodeGen/fprofile-instrument.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/fprofile-instrument.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fprofile-instrument=llvm -disable-llvm-passes \ +// RUN: -emit-llvm -o - %s | FileCheck %s +int g(int); + +int __attribute__((no_instrument_function)) no_instr(int a) { +// CHECK: define {{.*}} i32 @no_instr(i32 %a) [[ATTR:#[0-9]+]] + int sum = 0; + for (int i = 0; i < a; i++) + sum += g(i); + return sum; +} + +int instr(int a) { +// CHECK: define {{.*}} i32 @instr(i32 %a) [[ATTR2:#[0-9]+]] + int sum = 0; + for (int i = 0; i < a; i++) + sum += g(i); + return sum; +} +// CHECK: attributes [[ATTR]] = {{.*}} noprofile +// CHECK-NOT: attributes [[ATTR2]] = {{.*}} noprofile