1fb50dd34SRichard Smith // RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-linux-gnu %s
2fb50dd34SRichard Smith
3fb50dd34SRichard Smith int x __attribute__((section(
4fb50dd34SRichard Smith 42))); // expected-error {{'section' attribute requires a string}}
5fb50dd34SRichard Smith
6fb50dd34SRichard Smith
7fb50dd34SRichard Smith // PR6007
test()8fb50dd34SRichard Smith void test() {
9fb50dd34SRichard Smith __attribute__((section("NEAR,x"))) int n1; // expected-error {{'section' attribute only applies to functions, global variables, Objective-C methods, and Objective-C properties}}
10fb50dd34SRichard Smith __attribute__((section("NEAR,x"))) static int n2; // ok.
11fb50dd34SRichard Smith }
12fb50dd34SRichard Smith
13fb50dd34SRichard Smith // pr9356
14fb50dd34SRichard Smith void __attribute__((section("foo"))) test2(); // expected-note {{previous attribute is here}}
test2()15fb50dd34SRichard Smith void __attribute__((section("bar"))) test2() {} // expected-warning {{section does not match previous declaration}}
16fb50dd34SRichard Smith
17fb50dd34SRichard Smith enum __attribute__((section("NEAR,x"))) e { one }; // expected-error {{'section' attribute only applies to}}
18fb50dd34SRichard Smith
19fb50dd34SRichard Smith extern int a; // expected-note {{previous declaration is here}}
20fb50dd34SRichard Smith int *b = &a;
21fb50dd34SRichard Smith extern int a __attribute__((section("foo,zed"))); // expected-warning {{section attribute is specified on redeclared variable}}
22fb50dd34SRichard Smith
23fb50dd34SRichard Smith // Not a warning.
24fb50dd34SRichard Smith extern int c;
25fb50dd34SRichard Smith int c __attribute__((section("foo,zed")));
26fb50dd34SRichard Smith
27fb50dd34SRichard Smith // Also OK.
28fb50dd34SRichard Smith struct r_debug {};
29fb50dd34SRichard Smith extern struct r_debug _r_debug;
30fb50dd34SRichard Smith struct r_debug _r_debug __attribute__((nocommon, section(".r_debug,bar")));
31fb50dd34SRichard Smith
32fb50dd34SRichard Smith namespace override {
33fb50dd34SRichard Smith struct A {
foverride::A34fb50dd34SRichard Smith __attribute__((section("foo"))) virtual void f(){};
35fb50dd34SRichard Smith };
36fb50dd34SRichard Smith struct B : A {
foverride::B37fb50dd34SRichard Smith void f() {} // ok
38fb50dd34SRichard Smith };
39fb50dd34SRichard Smith struct C : A {
40fb50dd34SRichard Smith __attribute__((section("bar"))) void f(); // expected-note {{previous}}
41fb50dd34SRichard Smith };
42fb50dd34SRichard Smith __attribute__((section("baz"))) // expected-warning {{section does not match}}
f()43fb50dd34SRichard Smith void C::f() {}
44fb50dd34SRichard Smith }
45*f5006629STomas Matheson
46*f5006629STomas Matheson // Check for section type conflicts between global variables and function templates
template_fn1()47*f5006629STomas Matheson template <typename> __attribute__((section("template_fn1"))) void template_fn1() {} // expected-note {{declared here}}
48*f5006629STomas Matheson const int const_global_var __attribute__((section("template_fn1"))) = 42; // expected-error {{'const_global_var' causes a section type conflict with 'template_fn1'}}
49*f5006629STomas Matheson int mut_global_var __attribute__((section("template_fn2"))) = 42; // expected-note {{declared here}}
template_fn2()50*f5006629STomas Matheson template <typename> __attribute__((section("template_fn2"))) void template_fn2() {} // expected-error {{'template_fn2' causes a section type conflict with 'mut_global_var'}}
51