1f5fe2925b87cf382f2f13983c81679e38067122bRafael Espindola// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -fsyntax-only -verify %s
211e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
311e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// GCC will accept anything as the argument of weakref. Should we
411e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// check for an existing decl?
511e8ce7380856abee188b237c2600272df2ed09dRafael Espindolastatic int a1() __attribute__((weakref ("foo")));
611e8ce7380856abee188b237c2600272df2ed09dRafael Espindolastatic int a2() __attribute__((weakref, alias ("foo")));
711e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
811e8ce7380856abee188b237c2600272df2ed09dRafael Espindolastatic int a3 __attribute__((weakref ("foo")));
911e8ce7380856abee188b237c2600272df2ed09dRafael Espindolastatic int a4 __attribute__((weakref, alias ("foo")));
1011e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
1111e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// gcc rejects, clang accepts
1211e8ce7380856abee188b237c2600272df2ed09dRafael Espindolastatic int a5 __attribute__((alias ("foo"), weakref));
1311e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
1411e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// this is pointless, but accepted by gcc. We reject it.
1511e8ce7380856abee188b237c2600272df2ed09dRafael Espindolastatic int a6 __attribute__((weakref)); //expected-error {{weakref declaration of 'a6' must also have an alias attribute}}
1611e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
1711e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// gcc warns, clang rejects
1811e8ce7380856abee188b237c2600272df2ed09dRafael Espindolavoid f(void) {
1911e8ce7380856abee188b237c2600272df2ed09dRafael Espindola  static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}}
2011e8ce7380856abee188b237c2600272df2ed09dRafael Espindola}
2111e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
2211e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// both gcc and clang reject
2311e8ce7380856abee188b237c2600272df2ed09dRafael Espindolaclass c {
2411e8ce7380856abee188b237c2600272df2ed09dRafael Espindola  static int a __attribute__((weakref ("v2"))); // expected-error {{declaration of 'a' must be in a global context}}
2511e8ce7380856abee188b237c2600272df2ed09dRafael Espindola  static int b() __attribute__((weakref ("f3"))); // expected-error {{declaration of 'b' must be in a global context}}
2611e8ce7380856abee188b237c2600272df2ed09dRafael Espindola};
27332bb2a2e3cd0a5af85758847a8050ae8ceee5f3John McCallint a7() __attribute__((weakref ("f1"))); // expected-error {{weakref declaration must have internal linkage}}
28332bb2a2e3cd0a5af85758847a8050ae8ceee5f3John McCallint a8 __attribute__((weakref ("v1"))); // expected-error {{weakref declaration must have internal linkage}}
2911e8ce7380856abee188b237c2600272df2ed09dRafael Espindola
3011e8ce7380856abee188b237c2600272df2ed09dRafael Espindola// gcc accepts this
31332bb2a2e3cd0a5af85758847a8050ae8ceee5f3John McCallint a9 __attribute__((weakref)); // expected-error {{weakref declaration must have internal linkage}}
32