[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 117264. choikwa added a comment. Addressing Hal's feedback https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c test/CodeGenCXX/instrument-functions.cpp Index: test/CodeGenCXX/instrument-functions.cpp === --- test/CodeGenCXX/instrument-functions.cpp +++ test/CodeGenCXX/instrument-functions.cpp @@ -1,10 +1,28 @@ // RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC + // CHECK: @_Z5test1i +// NOINSTR: @_Z5test1i +// NOFILE: @_Z5test1i +// NOFUNC: @_Z5test1i int test1(int x) { // CHECK: __cyg_profile_func_enter // CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } @@ -17,6 +35,26 @@ return x; } +// CHECK: @_Z5test3i +// NOINSTR: @_Z5test3i +// NOFILE: @_Z5test3i +// NOFUNC: @_Z5test3i +int test3(int x){ +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + // This test case previously crashed code generation. It exists solely // to test -finstrument-function does not crash codegen for this trivial // case. Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC // CHECK: @test1 +// NOINSTR: @test1 +// NOFILE: @test1 +// NOFUNC: @test1 int test1(int x) { -// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg -// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } // CHECK: @test2 +// NOINSTR: @test2 +// NOFILE: @test2 +// NOFUNC: @test2 int test2(int) __attribute__((no_instrument_function)); int test2(int x) { // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + +// CHECK: @test3 +// NOINSTR: @test3 +// NOFILE: @test3 +// NOFUNC: @test3 +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret return x; } Index: lib/Frontend/Co
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 117267. choikwa added a comment. - - Address formating feedback, remove redundant inline https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c test/CodeGenCXX/instrument-functions.cpp Index: test/CodeGenCXX/instrument-functions.cpp === --- test/CodeGenCXX/instrument-functions.cpp +++ test/CodeGenCXX/instrument-functions.cpp @@ -1,10 +1,29 @@ // RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3 | FileCheck %s --check-prefix=NOFUNC2 + // CHECK: @_Z5test1i +// NOINSTR: @_Z5test1i +// NOFILE: @_Z5test1i +// NOFUNC: @_Z5test1i int test1(int x) { // CHECK: __cyg_profile_func_enter // CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } @@ -17,6 +36,30 @@ return x; } +// CHECK: @_Z5test3i +// NOINSTR: @_Z5test3i +// NOFILE: @_Z5test3i +// NOFUNC: @_Z5test3i +// NOFUNC2: @_Z5test3i +int test3(int x){ +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret +// NOFUNC2: __cyg_profile_func_enter +// NOFUNC2: __cyg_profile_func_exit +// NOFUNC2: ret + return x; +} + // This test case previously crashed code generation. It exists solely // to test -finstrument-function does not crash codegen for this trivial // case. Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC // CHECK: @test1 +// NOINSTR: @test1 +// NOFILE: @test1 +// NOFUNC: @test1 int test1(int x) { -// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg -// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } // CHECK: @test2 +// NOINSTR: @test2 +// NOFILE: @test2 +// NOFUNC: @test2 int test2(int) __attribute__((no_instrument_function)); int test2(int x) { // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + +// CHECK: @test3 +// NOINSTR: @test3 +// NOFILE: @test3 +// NOFUNC: @test3 +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_fun
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 117268. choikwa added a comment. - add comment to CPP test to explain usage https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c test/CodeGenCXX/instrument-functions.cpp Index: test/CodeGenCXX/instrument-functions.cpp === --- test/CodeGenCXX/instrument-functions.cpp +++ test/CodeGenCXX/instrument-functions.cpp @@ -1,10 +1,32 @@ // RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC + +// Below would see if mangled name partially matches. exclude-function-list matches demangled names, thus we expect to see instrument calls in test3. +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3 | FileCheck %s --check-prefix=NOFUNC2 + + // CHECK: @_Z5test1i +// NOINSTR: @_Z5test1i +// NOFILE: @_Z5test1i +// NOFUNC: @_Z5test1i int test1(int x) { // CHECK: __cyg_profile_func_enter // CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } @@ -17,6 +39,30 @@ return x; } +// CHECK: @_Z5test3i +// NOINSTR: @_Z5test3i +// NOFILE: @_Z5test3i +// NOFUNC: @_Z5test3i +// NOFUNC2: @_Z5test3i +int test3(int x){ +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret +// NOFUNC2: __cyg_profile_func_enter +// NOFUNC2: __cyg_profile_func_exit +// NOFUNC2: ret + return x; +} + // This test case previously crashed code generation. It exists solely // to test -finstrument-function does not crash codegen for this trivial // case. Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC // CHECK: @test1 +// NOINSTR: @test1 +// NOFILE: @test1 +// NOFUNC: @test1 int test1(int x) { -// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg -// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } // CHECK: @test2 +// NOINSTR: @test2 +// NOFILE: @test2 +// NOFUNC: @test2 int test2(int) __attribute__((no_instrument_function)); int test2(int x) { // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + +// CHECK: @test3 +// NOINSTR: @test3 +// NOFILE: @test3 +// NOFUNC: @test
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 117269. choikwa added a comment. - add more CPP tests: func overload, template special https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c test/CodeGenCXX/instrument-functions.cpp Index: test/CodeGenCXX/instrument-functions.cpp === --- test/CodeGenCXX/instrument-functions.cpp +++ test/CodeGenCXX/instrument-functions.cpp @@ -1,10 +1,32 @@ // RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC + +// Below would see if mangled name partially matches. exclude-function-list matches demangled names, thus we expect to see instrument calls in test3. +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3 | FileCheck %s --check-prefix=NOFUNC2 + + // CHECK: @_Z5test1i +// NOINSTR: @_Z5test1i +// NOFILE: @_Z5test1i +// NOFUNC: @_Z5test1i int test1(int x) { // CHECK: __cyg_profile_func_enter // CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } @@ -17,6 +39,82 @@ return x; } +// CHECK: @_Z5test3i +// NOINSTR: @_Z5test3i +// NOFILE: @_Z5test3i +// NOFUNC: @_Z5test3i +// NOFUNC2: @_Z5test3i +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret +// NOFUNC2: __cyg_profile_func_enter +// NOFUNC2: __cyg_profile_func_exit +// NOFUNC2: ret + return x; +} + +// Check function overload +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=OVERLOAD +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3v | FileCheck %s --check-prefix=OVERLOAD1 + +// OVERLOAD: @_Z5test3v +// OVERLOAD1: @_Z5test3v +int test3() { +// OVERLOAD-NOT: __cyg_profile_func_enter +// OVERLOAD-NOT: __cyg_profile_func_exit +// OVERLOAD: ret +// OVERLOAD1: __cyg_profile_func_enter +// OVERLOAD1: __cyg_profile_func_exit +// OVERLOAD1: ret + return 1; +} + +template +T test4(T a) { + return a; +} + +// Check function with template specialization +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test4 | FileCheck %s --check-prefix=TPL +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test4Ii | FileCheck %s --check-prefix=TPL1 +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test4Is | FileCheck %s --check-prefix=TPL2 + +// TPL: @_Z5test4IiET_S0_ +// TPL1: @_Z5test4IiET_S0_ +template<> +int test4(int a) { +// TPL-NOT: __cyg_profile_func_enter +// TPL-NOT: __cyg_profile_func_exit +// TPL: ret +// TPL1: __cyg_profile_func_enter +// TPL1: __cyg_profile_func_exit +// TPL1: ret + return a; +} + +// TPL: @_Z5test4IsET_S0_ +// TPL2: @_Z5test4IsET_S0_ +template<> +short test4(short a) { +// TPL-NOT: __cyg_profile_func_enter +// TPL-NOT: __cyg_profile_func_exit +// TPL: ret +// TPL2: __cyg_profile_func_enter +// TPL2: __cyg_profile_func_exit +// TPL2: ret + return a; +} + // This test case previously crashed code generation. It exists solely // to test -finstrument-function does not crash codegen for this trivial // case. Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions |
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa added a comment. In https://reviews.llvm.org/D37624#885290, @hfinkel wrote: > In https://reviews.llvm.org/D37624#885288, @choikwa wrote: > > > - add comment to CPP test to explain usage > > > Thanks. Please also add some tests showing matching overloaded functions, > functions with template parameters, etc. > > Do we need to strip whitespace before trying to match the demangled names? Some cursory testing with g++ shows that only the 'test5' of 'test5(float, int, int*)' is matched. 'test5(' or 'test5 (' is not matched. It seems weird that arguments are not matched. Comment at: test/CodeGenCXX/instrument-functions.cpp:8 +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3 | FileCheck %s --check-prefix=NOFUNC2 + hfinkel wrote: > I'm a bit confused about this test. Are you trying to match against the > mangled names, or the demangled names, or both? It's matching demangled names, so Z5test3 would not match and insert instrumentation calls to test3(int). Since this wasn't clear, I will add comment in the test. https://reviews.llvm.org/D37624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa added a comment. In https://reviews.llvm.org/D37624#885308, @hfinkel wrote: > In https://reviews.llvm.org/D37624#885295, @choikwa wrote: > > > In https://reviews.llvm.org/D37624#885290, @hfinkel wrote: > > > > > In https://reviews.llvm.org/D37624#885288, @choikwa wrote: > > > > > > > - add comment to CPP test to explain usage > > > > > > > > > Thanks. Please also add some tests showing matching overloaded functions, > > > functions with template parameters, etc. > > > > > > Do we need to strip whitespace before trying to match the demangled names? > > > > > > Some cursory testing with g++ shows that only the 'test5' of 'test5(float, > > int, int*)' is matched. 'test5(' or 'test5 (' is not matched. It seems > > weird that arguments are not matched. > > > > g++ man page shows > > > > "The function name to be matched is its user-visible name, such as > > "vector blah(const vector &)", not the internal mangled name" > > > > but it doesn't seem to be including parameters. > > > Interesting. Can you tell what GCC is doing w.r.t. namespace names, class > names, etc. and template parameters? > > > Also uncovered a bug where sub argument list containing comma needs to be > > surrounded by single quote, but clang seems to ignores single quote. > > I'll try to dig around ArgList implementation to see if it can return > > argument surrounded by single-quote as a whole. Given A::B::C(T a), only 'C' is meaningful in g++'s matcher. Adding anything else escapes the match [ 'B::C', 'C(' ]. https://reviews.llvm.org/D37624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa added a comment. > Can you get more information on what GCC actually implemented and why? It's > not clear to me that ignoring the namespaces is the most-useful way to do > this. I don't want to emulate GCC bugs, but maybe there's a good reason why > their implementation works this way. This is what I found, https://gcc.gnu.org/ml/gcc-patches/2015-12/msg00473.html Diff shows it doesn't seem to specially treat single quotes. +case OPT_finstrument_functions_include_function_list_: + add_comma_separated_to_vector + (&opts->x_flag_instrument_functions_include_functions, arg); + break; https://reviews.llvm.org/D37624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 120252. choikwa added a comment. rebase to trunk https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c test/CodeGenCXX/instrument-functions.cpp Index: test/CodeGenCXX/instrument-functions.cpp === --- test/CodeGenCXX/instrument-functions.cpp +++ test/CodeGenCXX/instrument-functions.cpp @@ -1,10 +1,32 @@ // RUN: %clang_cc1 -S -emit-llvm -triple %itanium_abi_triple -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC + +// Below would see if mangled name partially matches. exclude-function-list matches demangled names, thus we expect to see instrument calls in test3. +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3 | FileCheck %s --check-prefix=NOFUNC2 + + // CHECK: @_Z5test1i +// NOINSTR: @_Z5test1i +// NOFILE: @_Z5test1i +// NOFUNC: @_Z5test1i int test1(int x) { // CHECK: __cyg_profile_func_enter // CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } @@ -17,6 +39,93 @@ return x; } +// CHECK: @_Z5test3i +// NOINSTR: @_Z5test3i +// NOFILE: @_Z5test3i +// NOFUNC: @_Z5test3i +// NOFUNC2: @_Z5test3i +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret +// NOFUNC2: __cyg_profile_func_enter +// NOFUNC2: __cyg_profile_func_exit +// NOFUNC2: ret + return x; +} + +// Check function overload +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=OVERLOAD +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test3v | FileCheck %s --check-prefix=OVERLOAD1 + +// OVERLOAD: @_Z5test3v +// OVERLOAD1: @_Z5test3v +int test3() { +// OVERLOAD-NOT: __cyg_profile_func_enter +// OVERLOAD-NOT: __cyg_profile_func_exit +// OVERLOAD: ret +// OVERLOAD1: __cyg_profile_func_enter +// OVERLOAD1: __cyg_profile_func_exit +// OVERLOAD1: ret + return 1; +} + +template +T test4(T a) { + return a; +} + +// Check function with template specialization +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test4 | FileCheck %s --check-prefix=TPL +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test4Ii | FileCheck %s --check-prefix=TPL1 +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=Z5test4Is | FileCheck %s --check-prefix=TPL2 + +// TPL: @_Z5test4IiET_S0_ +// TPL1: @_Z5test4IiET_S0_ +template<> +int test4(int a) { +// TPL-NOT: __cyg_profile_func_enter +// TPL-NOT: __cyg_profile_func_exit +// TPL: ret +// TPL1: __cyg_profile_func_enter +// TPL1: __cyg_profile_func_exit +// TPL1: ret + return a; +} + +// TPL: @_Z5test4IsET_S0_ +// TPL2: @_Z5test4IsET_S0_ +template<> +short test4(short a) { +// TPL-NOT: __cyg_profile_func_enter +// TPL-NOT: __cyg_profile_func_exit +// TPL: ret +// TPL2: __cyg_profile_func_enter +// TPL2: __cyg_profile_func_exit +// TPL2: ret + return a; +} + +// Check whitespace +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list='int test5 (float f, int a, int *p)' | FileCheck %s --check-prefix=WSTEST +// WSTEST: @_Z5test5fiPi +int test5 (float f, int a, int *p) { +// WSTEST-NOT: __cyg_profile_func_enter +// WSTEST-NOT: __cyg_profile_func_exit +// WSTEST-NOT: ret + *p = (int)f + a; + return *p; +} + // This test case previously crashed code generation. It exists solely // to test -finstrum
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa created this revision. Builds on previous Differential https://reviews.llvm.org/D2219 Changes include: - Using unordered_map with SourceLocation.ID (raw encoding) as key - Demangle only if !isExternC. Used dyn_cast((Decl*)CurFuncDecl) for this - Modified an existing C testcase to test for options. https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC // CHECK: @test1 +// NOINSTR: @test1 +// NOFILE: @test1 +// NOFUNC: @test1 int test1(int x) { -// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg -// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } // CHECK: @test2 +// NOINSTR: @test2 +// NOFILE: @test2 +// NOFUNC: @test2 int test2(int) __attribute__((no_instrument_function)); int test2(int x) { // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + +// CHECK: @test3 +// NOINSTR: @test3 +// NOFILE: @test3 +// NOFUNC: @test3 +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret return x; } Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -771,6 +771,12 @@ Opts.PreserveVec3Type = Args.hasArg(OPT_fpreserve_vec3_type); Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); + if (Opts.InstrumentFunctions) { +Opts.InstrumentFunctionExclusionsFunctions += Args.getAllArgValues(OPT_finstrument_functions_exclude_function_list); +Opts.InstrumentFunctionExclusionsPathSegments += Args.getAllArgValues(OPT_finstrument_functions_exclude_file_list); + } Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument); Opts.XRayInstructionThreshold = getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags); Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3519,7 +3519,14 @@ options::OPT_fno_unique_section_names, true)) CmdArgs.push_back("-fno-unique-section-names"); - Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); + if (Args.hasArg(options::OPT_finstrument_functions, + options::OPT_fno_instrument_functions, false)) { +Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); +Args.AddAllArgs(CmdArgs, +options::OPT_finstrument_functions_exclude_file_list); +Args.AddAllArgs(CmdArgs, +options::OPT_finstrument_functions_exclude_function_list); + } addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs); Index: lib/CodeGen/CodeGenFunction.h === --- lib/CodeGen/CodeGenFunction.h +++ lib/CodeGen/CodeGenFunction.h @@ -1762,7 +1762,7 @@ /// Shoul
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 114380. choikwa added a comment. addressed code review. made doc consistent with functionality. https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC // CHECK: @test1 +// NOINSTR: @test1 +// NOFILE: @test1 +// NOFUNC: @test1 int test1(int x) { -// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg -// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } // CHECK: @test2 +// NOINSTR: @test2 +// NOFILE: @test2 +// NOFUNC: @test2 int test2(int) __attribute__((no_instrument_function)); int test2(int x) { // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + +// CHECK: @test3 +// NOINSTR: @test3 +// NOFILE: @test3 +// NOFUNC: @test3 +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret return x; } Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -771,6 +771,12 @@ Opts.PreserveVec3Type = Args.hasArg(OPT_fpreserve_vec3_type); Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); + if (Opts.InstrumentFunctions) { +Opts.InstrumentFunctionExclusionsFunctions += Args.getAllArgValues(OPT_finstrument_functions_exclude_function_list); +Opts.InstrumentFunctionExclusionsPathSegments += Args.getAllArgValues(OPT_finstrument_functions_exclude_file_list); + } Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument); Opts.XRayInstructionThreshold = getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags); Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3519,7 +3519,14 @@ options::OPT_fno_unique_section_names, true)) CmdArgs.push_back("-fno-unique-section-names"); - Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); + if (Args.hasArg(options::OPT_finstrument_functions, + options::OPT_fno_instrument_functions, false)) { +Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); +Args.AddAllArgs(CmdArgs, +options::OPT_finstrument_functions_exclude_file_list); +Args.AddAllArgs(CmdArgs, +options::OPT_finstrument_functions_exclude_function_list); + } addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs); Index: lib/CodeGen/CodeGenFunction.h === --- lib/CodeGen/CodeGenFunction.h +++ lib/CodeGen/CodeGenFunction.h @@ -1762,7 +1762,7 @@ /// ShouldInstrumentFunction - Return true if the current function should be /// instrumented with __cyg_profile_func_* calls - bool ShouldInstrumentFunction(); + bool ShouldInstru
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa added a comment. Forgot to hang Cache to CodeGenModule, will do that shortly https://reviews.llvm.org/D37624 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D37624: add support for -fno-instrument-functions and -finstrument-functions-exclude-{file, function}-list= to match gcc options.
choikwa updated this revision to Diff 114388. choikwa added a comment. renamed and moved Cache to SourceLocToFileNameMap in CodeGenModule https://reviews.llvm.org/D37624 Files: docs/ClangCommandLineReference.rst include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CodeGenFunction.cpp lib/CodeGen/CodeGenFunction.h lib/CodeGen/CodeGenModule.cpp lib/CodeGen/CodeGenModule.h lib/Driver/ToolChains/Clang.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGen/instrument-functions.c Index: test/CodeGen/instrument-functions.c === --- test/CodeGen/instrument-functions.c +++ test/CodeGen/instrument-functions.c @@ -1,18 +1,66 @@ -// RUN: %clang_cc1 -S -debug-info-kind=standalone -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions | FileCheck %s +// RUN: %clang -S -emit-llvm -o - %s -fno-instrument-functions | FileCheck %s --check-prefix=NOINSTR + +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-file-list=instrument | FileCheck %s --check-prefix=NOFILE +// RUN: %clang -S -emit-llvm -o - %s -finstrument-functions -finstrument-functions-exclude-function-list=test3 | FileCheck %s --check-prefix=NOFUNC // CHECK: @test1 +// NOINSTR: @test1 +// NOFILE: @test1 +// NOFUNC: @test1 int test1(int x) { -// CHECK: call void @__cyg_profile_func_enter({{.*}}, !dbg -// CHECK: call void @__cyg_profile_func_exit({{.*}}, !dbg +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC: __cyg_profile_func_enter +// NOFUNC: __cyg_profile_func_exit +// NOFUNC: ret return x; } // CHECK: @test2 +// NOINSTR: @test2 +// NOFILE: @test2 +// NOFUNC: @test2 int test2(int) __attribute__((no_instrument_function)); int test2(int x) { // CHECK-NOT: __cyg_profile_func_enter // CHECK-NOT: __cyg_profile_func_exit // CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret + return x; +} + +// CHECK: @test3 +// NOINSTR: @test3 +// NOFILE: @test3 +// NOFUNC: @test3 +int test3(int x) { +// CHECK: __cyg_profile_func_enter +// CHECK: __cyg_profile_func_exit +// CHECK: ret +// NOINSTR-NOT: __cyg_profile_func_enter +// NOINSTR-NOT: __cyg_profile_func_exit +// NOINSTR: ret +// NOFILE-NOT: __cyg_profile_func_enter +// NOFILE-NOT: __cyg_profile_func_exit +// NOFILE: ret +// NOFUNC-NOT: __cyg_profile_func_enter +// NOFUNC-NOT: __cyg_profile_func_exit +// NOFUNC: ret return x; } Index: lib/Frontend/CompilerInvocation.cpp === --- lib/Frontend/CompilerInvocation.cpp +++ lib/Frontend/CompilerInvocation.cpp @@ -771,6 +771,12 @@ Opts.PreserveVec3Type = Args.hasArg(OPT_fpreserve_vec3_type); Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions); + if (Opts.InstrumentFunctions) { +Opts.InstrumentFunctionExclusionsFunctions += Args.getAllArgValues(OPT_finstrument_functions_exclude_function_list); +Opts.InstrumentFunctionExclusionsPathSegments += Args.getAllArgValues(OPT_finstrument_functions_exclude_file_list); + } Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument); Opts.XRayInstructionThreshold = getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags); Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -3519,7 +3519,14 @@ options::OPT_fno_unique_section_names, true)) CmdArgs.push_back("-fno-unique-section-names"); - Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); + if (Args.hasArg(options::OPT_finstrument_functions, + options::OPT_fno_instrument_functions, false)) { +Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions); +Args.AddAllArgs(CmdArgs, +options::OPT_finstrument_functions_exclude_file_list); +Args.AddAllArgs(CmdArgs, +options::OPT_finstrument_functions_exclude_function_list); + } addPGOAndCoverageFlags(C, D, Output, Args, CmdArgs); Index: lib/CodeGen/CodeGenModule.h === --- lib/CodeGen/CodeGenModule.h +++ lib/CodeGen/CodeGenModule.h @@ -499,6 +499,9 @@ /// MDNodes. llvm::DenseMap MetadataIdMap; + /// Mapping from SourceLocation to PresumedLoc FileName + llvm::DenseMap Sour