// RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -O2 < %s | FileCheck -allow-deprecated-dag-overlap %s
// RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -Os < %s | FileCheck -allow-deprecated-dag-overlap %s
// RUN: %clang_cc1 -I %S/Inputs -x c++ -std=c++11 -triple x86_64-unknown-linux -emit-llvm -Oz < %s | FileCheck -allow-deprecated-dag-overlap %s
// This is a macro definition and therefore its text is not present after
// preprocessing. The pragma has no effect here.
// This is a declaration and therefore it is not decorated with `optnone`.
extern int ;
// CHECK-DAG: @_Z3fooii{{.*}} [[ATTRFOO:#[0-9]+]]
// This is a definition and therefore it will be decorated with `optnone`.
int
// CHECK-DAG: @_Z3barii{{.*}} [[ATTRBAR:#[0-9]+]]
// The function "int created (int param)" created by the macro invocation
// is also decorated with the `optnone` attribute because it is within a
// region of code affected by the functionality (not because of the position
// of the macro definition).
// CHECK-DAG: @_Z7createdi{{.*}} [[ATTRCREATED:#[0-9]+]]
;
// The definition of the method instead is decorated with `optnone`.
int
// CHECK-DAG: @_ZN7MyClass6methodEi{{.*}} [[ATTRMETHOD:#[0-9]+]]
// A template declaration will not be decorated with `optnone`.
T ;
// The template definition will be decorated with the attribute `optnone`.
T
// This function definition will not be decorated with `optnone` because the
// attribute would conflict with `always_inline`.
int
// CHECK-DAG: @_Z3bazi{{.*}} [[ATTRBAZ:#[0-9]+]]
// This function definition will not be decorated with `optnone` because the
// attribute would conflict with `minsize`.
int
// CHECK-DAG: @_Z3baxi{{.*}} [[ATTRBAX:#[0-9]+]]
// The function "int wombat(int param)" created by the macro is not
// decorated with `optnone`, because the pragma applies its effects only
// after preprocessing. The position of the macro definition is not
// relevant.
// CHECK-DAG: @_Z6wombati{{.*}} [[ATTRWOMBAT:#[0-9]+]]
// This instantiation of the "twice" template function with a "float" type
// will not have an `optnone` attribute because the template declaration was
// not affected by the pragma.
float
// CHECK-DAG: @_Z9containerf{{.*}} [[ATTRCONTAINER:#[0-9]+]]
// CHECK-DAG: @_Z5twiceIfET_S0_{{.*}} [[ATTRTWICE:#[0-9]+]]
// This instantiation of the "thrice" template function with a "float" type
// will have an `optnone` attribute because the template definition was
// affected by the pragma.
float
// CHECK-DAG: @_Z10container2f{{.*}} [[ATTRCONTAINER2:#[0-9]+]]
// CHECK-DAG: @_Z6thriceIfET_S0_{{.*}} [[ATTRTHRICEFLOAT:#[0-9]+]]
// A template specialization is a new definition and it will not be
// decorated with an `optnone` attribute because it is now outside of the
// affected region.
int
int
// CHECK-DAG: @_Z10container3i{{.*}} [[ATTRCONTAINER3:#[0-9]+]]
// CHECK-DAG: @_Z6thriceIiET_S0_{{.*}} [[ATTRTHRICEINT:#[0-9]+]]
// Test that we can re-open and re-close an "off" region after the first one,
// and that this works as expected.
int
// CHECK-DAG: @_Z15another_optnonei{{.*}} [[ATTRANOTHEROPTNONE:#[0-9]+]]
int
// CHECK-DAG: @_Z14another_normali{{.*}} [[ATTRANOTHERNORMAL:#[0-9]+]]
// Test that we can re-open an "off" region by including a header with the
// pragma and that this works as expected (i.e. the off region "falls through"
// the end of the header into this file).
int
// CHECK-DAG: @_Z19yet_another_optnonei{{.*}} [[ATTRYETANOTHEROPTNONE:#[0-9]+]]
int
// CHECK-DAG: @_Z18yet_another_normali{{.*}} [[ATTRYETANOTHERNORMAL:#[0-9]+]]
// Check for both noinline and optnone on each function that should have them.
// CHECK-DAG: attributes [[ATTRBAR]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
// CHECK-DAG: attributes [[ATTRCREATED]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
// CHECK-DAG: attributes [[ATTRMETHOD]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
// CHECK-DAG: attributes [[ATTRTHRICEFLOAT]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
// CHECK-DAG: attributes [[ATTRANOTHEROPTNONE]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
// CHECK-DAG: attributes [[ATTRYETANOTHEROPTNONE]] = { {{.*}}noinline{{.*}}optnone{{.*}} }
// Check that the other functions do NOT have optnone.
// CHECK-NOT: attributes [[ATTRFOO]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRBAZ]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRBAX]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRWOMBAT]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRCONTAINER]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRTWICE]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRCONTAINER2]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRCONTAINER3]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRTHRICEINT]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRANOTHERNORMAL]] = { {{.*}}optnone{{.*}} }
// CHECK-NOT: attributes [[ATTRYETANOTHERNORMAL]] = { {{.*}}optnone{{.*}} }