2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -verify -fsyntax-only -triple x86_64-apple-darwin9 %s
2009-08-11 03:03:04 +08:00
int x __attribute__ ( ( section (
2013-07-30 09:31:03 +08:00
42 ) ) ) ; // expected-error {{'section' attribute requires a string}}
2009-08-11 03:03:04 +08:00
// rdar://4341926
int y __attribute__ ( ( section (
" sadf " ) ) ) ; // expected-error {{mach-o section specifier requires a segment and section separated by a comma}}
2010-01-13 04:58:53 +08:00
// PR6007
void test ( ) {
2017-11-27 04:01:12 +08:00
__attribute__ ( ( section ( " NEAR,x " ) ) ) int n1 ; // expected-error {{'section' attribute only applies to functions, global variables, Objective-C methods, and Objective-C properties}}
2010-01-13 04:58:53 +08:00
__attribute__ ( ( section ( " NEAR,x " ) ) ) static int n2 ; // ok.
2010-04-08 06:58:06 +08:00
}
2012-05-13 10:42:42 +08:00
// pr9356
void __attribute__ ( ( section ( " foo,zed " ) ) ) test2 ( void ) ; // expected-note {{previous attribute is here}}
void __attribute__ ( ( section ( " bar,zed " ) ) ) test2 ( void ) { } // expected-warning {{section does not match previous declaration}}
2013-12-12 09:34:39 +08:00
2017-11-27 04:01:12 +08:00
enum __attribute__ ( ( section ( " NEAR,x " ) ) ) e { one } ; // expected-error {{'section' attribute only applies to}}
2017-09-27 07:42:34 +08:00
extern int a ; // expected-note {{previous declaration is here}}
int * b = & a ;
extern int a __attribute__ ( ( section ( " foo,zed " ) ) ) ; // expected-warning {{section attribute is specified on redeclared variable}}
2017-10-05 06:16:24 +08:00
// Not a warning.
int c ;
2020-12-18 00:42:32 +08:00
int c __attribute__ ( ( section ( " seg1,sec1 " ) ) ) ;
2017-10-05 06:16:24 +08:00
// Also OK.
struct r_debug { } ;
extern struct r_debug _r_debug ;
struct r_debug _r_debug __attribute__ ( ( nocommon , section ( " .r_debug,bar " ) ) ) ;
2020-12-18 00:42:32 +08:00
// Section type conflicts between functions and variables
void test3 ( void ) __attribute__ ( ( section ( " seg3,sec3 " ) ) ) ; // expected-note {{declared here}}
void test3 ( void ) { }
const int const_global_var __attribute__ ( ( section ( " seg3,sec3 " ) ) ) = 10 ; // expected-error {{'const_global_var' causes a section type conflict with 'test3'}}
void test4 ( void ) __attribute__ ( ( section ( " seg4,sec4 " ) ) ) ; // expected-note {{declared here}}
void test4 ( void ) { }
int mut_global_var __attribute__ ( ( section ( " seg4,sec4 " ) ) ) = 10 ; // expected-error {{'mut_global_var' causes a section type conflict with 'test4'}}
const int global_seg5sec5 __attribute__ ( ( section ( " seg5,sec5 " ) ) ) = 10 ; // expected-note {{declared here}}
void test5 ( void ) __attribute__ ( ( section ( " seg5,sec5 " ) ) ) ; // expected-error {{'test5' causes a section type conflict with 'global_seg5sec5'}}
void test5 ( void ) { }
void test6 ( void ) ;
const int global_seg6sec6 __attribute__ ( ( section ( " seg6,sec6 " ) ) ) = 10 ; // expected-note {{declared here}}
void test6 ( void ) __attribute__ ( ( section ( " seg6,sec6 " ) ) ) ; // expected-error {{'test6' causes a section type conflict with 'global_seg6sec6'}}
void test6 ( void ) { }