brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.9 KiB · b8db6d3 Raw
195 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-linux-gnu  -fsyntax-only -verify -fexceptions -fcxx-exceptions %s -std=c++142void __attribute__((target("default"))) invalid_features(void);3//expected-error@+2 {{function declaration is missing 'target' attribute in a multiversioned function}}4//expected-warning@+1 {{unsupported 'hello_world' in the 'target' attribute string; 'target' attribute ignored}}5void __attribute__((target("hello_world"))) invalid_features(void);6//expected-error@+1 {{function multiversioning doesn't support feature 'no-sse4.2'}}7void __attribute__((target("no-sse4.2"))) invalid_features(void);8 9void __attribute__((target("sse4.2"))) no_default(void);10void __attribute__((target("arch=sandybridge")))  no_default(void);11 12void use1(void){13  // expected-error@+1 {{no matching function for call to 'no_default'}}14  no_default();15}16constexpr int __attribute__((target("sse4.2"))) foo(void) { return 0; }17constexpr int __attribute__((target("arch=sandybridge"))) foo(void);18//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}19int __attribute__((target("arch=ivybridge"))) foo(void) {return 1;}20constexpr int __attribute__((target("default"))) foo(void) { return 2; }21 22int __attribute__((target("sse4.2"))) foo2(void) { return 0; }23//expected-error@+1 {{multiversioned function declaration has a different constexpr specification}}24constexpr int __attribute__((target("arch=sandybridge"))) foo2(void);25int __attribute__((target("arch=ivybridge"))) foo2(void) {return 1;}26int __attribute__((target("default"))) foo2(void) { return 2; }27 28static int __attribute__((target("sse4.2"))) bar(void) { return 0; }29static int __attribute__((target("arch=sandybridge"))) bar(void);30//expected-error@+1 {{multiversioned function declaration has a different linkage}}31int __attribute__((target("arch=ivybridge"))) bar(void) {return 1;}32static int __attribute__((target("default"))) bar(void) { return 2; }33 34int __attribute__((target("sse4.2"))) bar2(void) { return 0; }35//expected-error@+1 {{multiversioned function declaration has a different linkage}}36static int __attribute__((target("arch=sandybridge"))) bar2(void);37int __attribute__((target("arch=ivybridge"))) bar2(void) {return 1;}38int __attribute__((target("default"))) bar2(void) { return 2; }39 40 41// no diagnostic, since this doesn't change the linkage.42int __attribute__((target("sse4.2"))) bar3(void) { return 0; }43extern int __attribute__((target("arch=sandybridge"))) bar2(void);44 45namespace {46int __attribute__((target("sse4.2"))) bar4(void) { return 0; }47static int __attribute__((target("arch=sandybridge"))) bar4(void);48}49 50inline int __attribute__((target("sse4.2"))) baz(void) { return 0; }51inline int __attribute__((target("arch=sandybridge"))) baz(void);52//expected-error@+1 {{multiversioned function declaration has a different inline specification}}53int __attribute__((target("arch=ivybridge"))) baz(void) {return 1;}54inline int __attribute__((target("default"))) baz(void) { return 2; }55 56int __attribute__((target("sse4.2"))) baz2(void) { return 0; }57//expected-error@+1 {{multiversioned function declaration has a different inline specification}}58inline int __attribute__((target("arch=sandybridge"))) baz2(void);59int __attribute__((target("arch=ivybridge"))) baz2(void) {return 1;}60int __attribute__((target("default"))) baz2(void) { return 2; }61 62float __attribute__((target("sse4.2"))) bock(void) { return 0; }63//expected-error@+1 {{multiversioned function declaration has a different return type}}64int __attribute__((target("arch=sandybridge"))) bock(void);65//expected-error@+1 {{multiversioned function declaration has a different return type}}66int __attribute__((target("arch=ivybridge"))) bock(void) {return 1;}67//expected-error@+1 {{multiversioned function declaration has a different return type}}68int __attribute__((target("default"))) bock(void) { return 2; }69 70int __attribute__((target("sse4.2"))) bock2(void) { return 0; }71//expected-error@+1 {{multiversioned function declaration has a different return type}}72float __attribute__((target("arch=sandybridge"))) bock2(void);73int __attribute__((target("arch=ivybridge"))) bock2(void) {return 1;}74int __attribute__((target("default"))) bock2(void) { return 2; }75 76auto __attribute__((target("sse4.2"))) bock3(void) -> int { return 0; }77//expected-error@+1 {{multiversioned function declaration has a different return type}}78auto __attribute__((target("arch=sandybridge"))) bock3(void) -> short { return (short)0;}79 80int __attribute__((target("sse4.2"))) bock4(void) noexcept(false) { return 0; }81//expected-error@+2 {{exception specification in declaration does not match previous declaration}}82//expected-note@-2 {{previous declaration is here}}83int __attribute__((target("arch=sandybridge"))) bock4(void) noexcept(true) { return 1;}84 85// FIXME: Add support for templates and virtual functions!86template<typename T>87int __attribute__((target("sse4.2"))) foo(T) { return 0; }88// expected-error@+2 {{multiversioned functions do not yet support function templates}}89template<typename T>90int __attribute__((target("arch=sandybridge"))) foo(T);91 92// expected-error@+2 {{multiversioned functions do not yet support function templates}}93template<typename T>94int __attribute__((target("default"))) foo(T) { return 2; }95 96struct S {97  template<typename T>98  int __attribute__((target("sse4.2"))) foo(T) { return 0; }99  // expected-error@+2 {{multiversioned functions do not yet support function templates}}100  template<typename T>101  int __attribute__((target("arch=sandybridge"))) foo(T);102 103  // expected-error@+2 {{multiversioned functions do not yet support function templates}}104  template<typename T>105  int __attribute__((target("default"))) foo(T) { return 2; }106 107  // expected-error@+1 {{multiversioned functions do not yet support virtual functions}}108  virtual void __attribute__((target("default"))) virt();109};110 111extern "C" {112int __attribute__((target("sse4.2"))) diff_mangle(void) { return 0; }113}114//expected-error@+1 {{multiversioned function declaration has a different language linkage}}115int __attribute__((target("arch=sandybridge"))) diff_mangle(void) { return 0; }116 117// expected-error@+1 {{multiversioned functions do not yet support deduced return types}}118auto __attribute__((target("default"))) deduced_return(void) { return 0; }119 120auto __attribute__((target("default"))) trailing_return(void)-> int { return 0; }121 122__attribute__((target("default"))) void DiffDecl();123namespace N {124using ::DiffDecl;125// expected-error@+3 {{declaration conflicts with target of using declaration already in scope}}126// expected-note@-4 {{target of using declaration}}127// expected-note@-3 {{using declaration}}128__attribute__((target("arch=sandybridge"))) void DiffDecl();129} // namespace N130 131struct SpecialFuncs {132  // expected-error@+1 {{multiversioned functions do not yet support constructors}}133  __attribute__((target("default"))) SpecialFuncs();134  // expected-error@+1 {{multiversioned functions do not yet support destructors}}135  __attribute__((target("default"))) ~SpecialFuncs();136 137  // expected-error@+1 {{multiversioned functions do not yet support defaulted functions}}138  SpecialFuncs& __attribute__((target("default"))) operator=(const SpecialFuncs&) = default;139  // expected-error@+1 {{multiversioned functions do not yet support deleted functions}}140  SpecialFuncs& __attribute__((target("default"))) operator=(SpecialFuncs&&) = delete;141};142 143class Secret {144  int i = 0;145  __attribute__((target("default")))146  friend int SecretAccessor(Secret &s);147  __attribute__((target("arch=sandybridge")))148  friend int SecretAccessor(Secret &s);149};150 151__attribute__((target("default")))152int SecretAccessor(Secret &s) {153  return s.i;154}155 156__attribute__((target("arch=sandybridge")))157int SecretAccessor(Secret &s) {158  return s.i + 2;159}160 161__attribute__((target("arch=ivybridge")))162int SecretAccessor(Secret &s) {163  //expected-error@+2{{'i' is a private member of 'Secret'}}164  //expected-note@-20{{implicitly declared private here}}165  return s.i + 3;166}167 168constexpr int __attribute__((target("sse4.2"))) constexpr_foo(void) {169  return 0;170}171constexpr int __attribute__((target("arch=sandybridge"))) constexpr_foo(void);172constexpr int __attribute__((target("arch=ivybridge"))) constexpr_foo(void) {173  return 1;174}175constexpr int __attribute__((target("default"))) constexpr_foo(void) {176  return 2;177}178 179void constexpr_test() {180  static_assert(foo() == 2, "Should call 'default' in a constexpr context");181}182 183struct BadOutOfLine { // #defined-here184  int __attribute__((target("sse4.2"))) foo(int);185  int __attribute__((target("default"))) foo(int);186};187 188int __attribute__((target("sse4.2"))) BadOutOfLine::foo(int) { return 0; }189int __attribute__((target("default"))) BadOutOfLine::foo(int) { return 1; }190// expected-error@+4 {{out-of-line definition of 'foo' does not match any declaration in 'BadOutOfLine'}}191// expected-note@#defined-here {{defined here}}192// expected-note@-4 {{member declaration nearly matches}}193// expected-note@-4 {{member declaration nearly matches}}194int __attribute__((target("arch=atom"))) BadOutOfLine::foo(int) { return 1; }195