brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.5 KiB · c4ce661 Raw
106 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify -fms-extensions %s -triple x86_64-pc-win322 3struct __declspec(code_seg("my_one")) FooOne {4  int barC();5};6 7struct FooTwo {8  int __declspec(code_seg("my_three")) barD();9  int barE();10};11int __declspec(code_seg("my_four")) FooOne::barC() { return 10; }12// expected-warning@-1 {{codeseg does not match previous declaration}}13// expected-note@3{{previous attribute is here}}14int __declspec(code_seg("my_five")) FooTwo::barD() { return 20; }15// expected-warning@-1 {{codeseg does not match previous declaration}}16// expected-note@8 {{previous attribute is here}}17int __declspec(code_seg("my_six")) FooTwo::barE() { return 30; }18// expected-warning@-1 {{codeseg does not match previous declaration}}19// expected-note@9 {{previous declaration is here}}20 21// Microsoft docs say:22// If a base-class has a code_seg attribute, derived classes must have the23// same attribute.24struct __declspec(code_seg("my_base")) Base1 {};25struct Base2 {};26 27struct D1 : Base1 {};28//expected-error@-1 {{derived class must specify the same code segment as its base classes}}29// expected-note@24 {{base class 'Base1' specified here}}30struct __declspec(code_seg("my_derived")) D2 : Base1 {};31// expected-error@-1 {{derived class must specify the same code segment as its base classes}}32// expected-note@24 {{base class 'Base1' specified here}}33struct __declspec(code_seg("my_derived")) D3 : Base2 {};34// expected-error@-1 {{derived class must specify the same code segment as its base classes}}35// expected-note@25 {{base class 'Base2' specified here}}36 37template <typename T> struct __declspec(code_seg("my_base")) MB : T { };38template <typename T> struct __declspec(code_seg("my_derived")) MD : T { };39MB<Base1> mb1; // ok40MB<Base2> mb2;41// expected-error@37 {{derived class must specify the same code segment as its base classes}}42// expected-note@-2 {{in instantiation of template class}}43// expected-note@25  {{base class 'Base2' specified here}}44MD<Base1> md1;45// expected-error@38 {{derived class must specify the same code segment as its base classes}}46// expected-note@-2 {{in instantiation of template class}}47// expected-note@24 {{base class 'Base1' specified here}}48MD<Base2> md2;49// expected-error@38 {{derived class must specify the same code segment as its base classes}}50// expected-note@-2 {{in instantiation of template class}}51// expected-note@25 {{base class 'Base2' specified here}}52 53// Virtual overrides must have the same code_seg.54struct __declspec(code_seg("my_one")) Base3 {55  virtual int barA() { return 1; }56  virtual int __declspec(code_seg("my_two")) barB() { return 2; }57};58struct __declspec(code_seg("my_one")) Derived3 : Base3 {59  int barA() { return 4; } // ok60  int barB() { return 6; }61  // expected-error@-1 {{overriding virtual function must specify the same code segment as its overridden function}}62  // expected-note@56 {{previous declaration is here}}63};64 65struct Base4 {66  virtual int __declspec(code_seg("my_one")) barA() {return 1;}67  virtual int barB() { return 2;}68};69struct Derived4 : Base4 {70  virtual int barA() {return 1;}71  // expected-error@-1 {{overriding virtual function must specify the same code segment as its overridden function}}72  // expected-note@66 {{previous declaration is here}}73  virtual int __declspec(code_seg("my_two")) barB() {return 1;}74  // expected-error@-1 {{overriding virtual function must specify the same code segment as its overridden function}}75  // expected-note@67 {{previous declaration is here}}76};77 78// MS gives an error when different code segments are used but a warning when a duplicate is used79 80// Function81int __declspec(code_seg("foo")) __declspec(code_seg("foo")) bar1() { return 1; }82// expected-warning@-1 {{duplicate code segment specifiers}}83int __declspec(code_seg("foo")) __declspec(code_seg("bar")) bar2() { return 1; }84// expected-error@-1 {{conflicting code segment specifiers}}85 86// Class87struct __declspec(code_seg("foo")) __declspec(code_seg("foo")) Foo {88  // expected-warning@-1 {{duplicate code segment specifiers}}89  int bar3() {return 0;}90};91struct __declspec(code_seg("foo")) __declspec(code_seg("bar")) FooSix {92  // expected-error@-1 {{conflicting code segment specifiers}}93  int bar3() {return 0;}94};95 96//Class Members97struct FooThree {98  int __declspec(code_seg("foo")) __declspec(code_seg("foo")) bar1() { return 1; }99  // expected-warning@-1 {{duplicate code segment specifiers}}100  int __declspec(code_seg("foo")) __declspec(code_seg("bar")) bar2() { return 1; }101  // expected-error@-1 {{conflicting code segment specifiers}}102  int bar8();103  int bar9() { return 9; }104};105 106