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
// RUN: %clang_cc1 %s -triple %itanium_abi_triple -std=c++11 -disable-O0-optnone -emit-llvm -o - | FileCheck %s

// Test optnone on template instantiations.

//-- Effect of optnone on generic add template function.

template <typename T> T template_normal(T a)
{
  return a + a;
}

template <typename T> __attribute__((optnone)) T template_optnone(T a)
{
  return a + a + a;
}

// This function should cause instantiations of each template, one marked
// with the 'optnone' attribute.
int container(int i)
{
  return template_normal<int>(i) + template_optnone<int>(i);
}

// CHECK: @_Z15template_normalIiET_S0_({{.*}}) [[NORMAL:#[0-9]+]]
// CHECK: @_Z16template_optnoneIiET_S0_({{.*}}) [[OPTNONE:#[0-9]+]]


//-- Effect of optnone on a partial specialization.
//   FIRST TEST: a method becomes marked with optnone in the specialization.

template <typename T, typename U> class template_normal_base {
public:
  T method(T t, U u) 
  {
    return t + static_cast<T>(u);
  }
};

template <typename U> class template_normal_base<int, U>
{
public:
  __attribute__((optnone)) int method (int t, U u)
  {
    return t - static_cast<int>(u);
  }
};

// This function should cause an instantiation of the full template (whose
// method is not marked optnone) and an instantiation of the partially
// specialized template (whose method is marked optnone).
void container2() 
{
  int y = 2;
  float z = 3.0;
  template_normal_base<float, int> class_normal;
  template_normal_base<int, float> class_optnone;
  float r1 = class_normal.method(z, y);
  float r2 = class_optnone.method(y, z);
}

// CHECK: @_ZN20template_normal_baseIfiE6methodEfi({{.*}}) [[NORMAL]]
// CHECK: @_ZN20template_normal_baseIifE6methodEif({{.*}}) [[OPTNONE]]


//-- Effect of optnone on a partial specialization.
//   SECOND TEST: a method loses optnone in the specialization.

template <typename T, typename U> class template_optnone_base {
public:
  __attribute__((optnone)) T method(T t, U u) 
  {
    return t + static_cast<T>(u);
  }
};

template <typename U> class template_optnone_base<int, U>
{
public:
  int method (int t, U u)
  {
    return t - static_cast<int>(u);
  }
};

// This function should cause an instantiation of the full template (whose
// method is marked optnone) and an instantiation of the partially
// specialized template (whose method is not marked optnone).
void container3() 
{
  int y = 2;
  float z = 3.0;
  template_optnone_base<float, int> class_optnone;
  template_optnone_base<int, float> class_normal;
  float r1 = class_optnone.method(z, y);
  float r2 = class_normal.method(y, z);
}

// CHECK: @_ZN21template_optnone_baseIfiE6methodEfi({{.*}}) [[OPTNONE]]
// CHECK: @_ZN21template_optnone_baseIifE6methodEif({{.*}}) [[NORMAL]]


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