llvm-project/clang/test/Sema/attr-disable-tail-calls.c
Aaron Ballman 4be8a26951 Use tablegen to diagnose mutually exclusive attributes
Currently, when one or more attributes are mutually exclusive, the
developer adding the attribute has to manually emit diagnostics. In
practice, this is highly error prone, especially for declaration
attributes, because such checking is not trivial. Redeclarations
require you to write a "merge" function to diagnose mutually exclusive
attributes and most attributes get this wrong.

This patch introduces a table-generated way to specify that a group of
two or more attributes are mutually exclusive:

def : MutualExclusions<[Attr1, Attr2, Attr3]>;

This works for both statement and declaration attributes (but not type
attributes) and the checking is done either from the common attribute
diagnostic checking code or from within mergeDeclAttribute() when
merging redeclarations.
2021-04-02 16:34:42 -04:00

20 lines
1.2 KiB
C

// RUN: %clang_cc1 -fsyntax-only -verify %s
void __attribute__((disable_tail_calls,naked)) foo1(int a) { // expected-error {{'naked' and 'disable_tail_calls' attributes are not compatible}} expected-note {{conflicting attribute is here}}
__asm__("");
}
void __attribute__((naked,disable_tail_calls)) foo2(int a) { // expected-error {{'disable_tail_calls' and 'naked' attributes are not compatible}} expected-note {{conflicting attribute is here}}
__asm__("");
}
int g0 __attribute__((disable_tail_calls)); // expected-warning {{'disable_tail_calls' attribute only applies to functions and Objective-C methods}}
int foo3(int a) __attribute__((disable_tail_calls("abc"))); // expected-error {{'disable_tail_calls' attribute takes no arguments}}
__attribute__((naked)) void foo4(void); // expected-note {{conflicting attribute is here}}
__attribute__((disable_tail_calls)) void foo4(void); // expected-error {{'disable_tail_calls' and 'naked' attributes are not compatible}}
__attribute__((disable_tail_calls)) void foo5(void); // expected-note {{conflicting attribute is here}}
__attribute__((naked)) void foo5(void); // expected-error {{'naked' and 'disable_tail_calls' attributes are not compatible}}