reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
// RUN: %clang_cc1 < %s -triple %itanium_abi_triple -fms-extensions -O2 -disable-llvm-passes -emit-llvm -x c++ | FileCheck %s

// Test attribute 'optnone' on methods:
//  -- member functions;
//  -- static member functions.

// Verify that all methods of struct A are associated to the same attribute set.
// The attribute set shall contain attributes 'noinline' and 'optnone'.

struct A {
  // Definition of an optnone static method.
  __attribute__((optnone))
  static int static_optnone_method(int a) {
    return a + a;
  }
  // CHECK: @_ZN1A21static_optnone_methodEi({{.*}}) [[OPTNONE:#[0-9]+]]

  // Definition of an optnone normal method.
  __attribute__((optnone))
  int optnone_method(int a) {
    return a + a + a + a;
  }
  // CHECK: @_ZN1A14optnone_methodEi({{.*}}) [[OPTNONE]]

  // Declaration of an optnone method with out-of-line definition
  // that doesn't say optnone.
  __attribute__((optnone))
  int optnone_decl_method(int a);

  // Methods declared without attribute optnone; the definitions will
  // have attribute optnone, and we verify optnone wins.
  __forceinline static int static_forceinline_method(int a);
  __attribute__((always_inline)) int alwaysinline_method(int a);
  __attribute__((noinline)) int noinline_method(int a);
  __attribute__((minsize)) int minsize_method(int a);
};

void foo() {
  A a;
  A::static_optnone_method(4);
  a.optnone_method(14);
  a.optnone_decl_method(12);
  A::static_forceinline_method(5);
  a.alwaysinline_method(5);
  a.noinline_method(6);
  a.minsize_method(7);
}

// No attribute here, should still be on the definition.
int A::optnone_decl_method(int a) {
  return a;
}
// CHECK: @_ZN1A19optnone_decl_methodEi({{.*}}) [[OPTNONE]]

// optnone implies noinline; therefore attribute noinline is added to
// the set of function attributes.
// forceinline is instead translated as 'always_inline'.
// However 'noinline' wins over 'always_inline' and therefore
// the resulting attributes for this method are: noinline + optnone
__attribute__((optnone))
int A::static_forceinline_method(int a) {
  return a + a + a + a;
}
// CHECK: @_ZN1A25static_forceinline_methodEi({{.*}}) [[OPTNONE]]

__attribute__((optnone))
int A::alwaysinline_method(int a) {
  return a + a + a + a;
}
// CHECK: @_ZN1A19alwaysinline_methodEi({{.*}}) [[OPTNONE]]

// 'noinline' + 'noinline and optnone' = 'noinline and optnone'
__attribute__((optnone))
int A::noinline_method(int a) {
  return a + a + a + a;
}
// CHECK: @_ZN1A15noinline_methodEi({{.*}}) [[OPTNONE]]

// 'optnone' wins over 'minsize'
__attribute__((optnone))
int A::minsize_method(int a) {
  return a + a + a + a;
}
// CHECK: @_ZN1A14minsize_methodEi({{.*}}) [[OPTNONE]]


// Test attribute 'optnone' on methods:
//  -- pure virtual functions
//  -- base virtual and derived virtual
//  -- base virtual but not derived virtual
//  -- optnone methods redefined in override

// A method defined in override doesn't inherit the function attributes of the
// superclass method.

struct B {
  virtual int pure_virtual(int a) = 0;
  __attribute__((optnone))
  virtual int pure_virtual_with_optnone(int a) = 0;

  virtual int base(int a) {
    return a + a + a + a;
  }

  __attribute__((optnone))
  virtual int optnone_base(int a) {
    return a + a + a + a;
  }

  __attribute__((optnone))
  virtual int only_base_virtual(int a) {
    return a + a;
  }
};

struct C : public B {
  __attribute__((optnone))
  virtual int pure_virtual(int a) {
    return a + a + a + a;
  }

  virtual int pure_virtual_with_optnone(int a) {
    return a + a + a + a;
  }

  __attribute__((optnone))
  virtual int base(int a) {
    return a + a;
  }

  virtual int optnone_base(int a) {
    return a + a;
  }

  int only_base_virtual(int a) {
    return a + a + a + a;
  }
};

int bar() {
  C c;
  int result;
  result = c.pure_virtual(3);
  result += c.pure_virtual_with_optnone(2);
  result += c.base(5);
  result += c.optnone_base(7);
  result += c.only_base_virtual(9);
  return result;
}

// CHECK: @_ZN1C12pure_virtualEi({{.*}}) {{.*}} [[OPTNONE]]
// CHECK: @_ZN1C25pure_virtual_with_optnoneEi({{.*}}) {{.*}} [[NORMAL:#[0-9]+]]
// CHECK: @_ZN1C4baseEi({{.*}}) {{.*}} [[OPTNONE]]
// CHECK: @_ZN1C12optnone_baseEi({{.*}}) {{.*}} [[NORMAL]]
// CHECK: @_ZN1C17only_base_virtualEi({{.*}}) {{.*}} [[NORMAL]]
// CHECK: @_ZN1B4baseEi({{.*}}) {{.*}} [[NORMAL]]
// CHECK: @_ZN1B12optnone_baseEi({{.*}}) {{.*}} [[OPTNONE]]
// CHECK: @_ZN1B17only_base_virtualEi({{.*}}) {{.*}} [[OPTNONE]]


// CHECK: attributes [[NORMAL]] =
// CHECK-NOT: noinline
// CHECK-NOT: optnone
// CHECK: attributes [[OPTNONE]] = {{.*}} noinline {{.*}} optnone