summaryrefslogtreecommitdiffstats
path: root/clang/test/Preprocessor
diff options
context:
space:
mode:
authorAndy Gibbs <andyg1001@hotmail.co.uk>2016-04-05 08:36:47 +0000
committerAndy Gibbs <andyg1001@hotmail.co.uk>2016-04-05 08:36:47 +0000
commit50b6ceff1f0648084e0d6edc3038d35892de14ba (patch)
tree6f6bfb14d4f1560dd752c24a4792948148986d9e /clang/test/Preprocessor
parent535afd808dc645530d53bf5f8ccf9d6f08f330e6 (diff)
downloadbcm5719-llvm-50b6ceff1f0648084e0d6edc3038d35892de14ba.tar.gz
bcm5719-llvm-50b6ceff1f0648084e0d6edc3038d35892de14ba.zip
Consolidate and improve the handling of built-in feature-like macros
Summary: The parsing logic has been separated out from the macro implementation logic, leading to a number of improvements: * Gracefully handle unexpected/invalid tokens, too few, too many and nested parameters * Provide consistent behaviour between all built-in feature-like macros * Simplify the implementation of macro logic * Fix __is_identifier to correctly return '0' for non-identifiers Reviewers: doug.gregor, rsmith Subscribers: rsmith, cfe-commits Differential Revision: http://reviews.llvm.org/D17149 llvm-svn: 265381
Diffstat (limited to 'clang/test/Preprocessor')
-rw-r--r--clang/test/Preprocessor/feature_tests.c46
-rw-r--r--clang/test/Preprocessor/invalid-__has_warning1.c2
-rw-r--r--clang/test/Preprocessor/invalid-__has_warning2.c2
-rw-r--r--clang/test/Preprocessor/warning_tests.c7
4 files changed, 49 insertions, 8 deletions
diff --git a/clang/test/Preprocessor/feature_tests.c b/clang/test/Preprocessor/feature_tests.c
index fbde6a65476..52a1f17cdd4 100644
--- a/clang/test/Preprocessor/feature_tests.c
+++ b/clang/test/Preprocessor/feature_tests.c
@@ -55,8 +55,50 @@
#endif
#ifdef VERIFY
-// expected-error@+2 {{builtin feature check macro requires a parenthesized identifier}}
-// expected-error@+1 {{expected value in expression}}
+// expected-error@+1 {{builtin feature check macro requires a parenthesized identifier}}
#if __has_feature('x')
#endif
+
+// The following are not identifiers:
+_Static_assert(!__is_identifier("string"), "oops");
+_Static_assert(!__is_identifier('c'), "oops");
+_Static_assert(!__is_identifier(123), "oops");
+_Static_assert(!__is_identifier(int), "oops");
+
+// The following are:
+_Static_assert(__is_identifier(abc /* comment */), "oops");
+_Static_assert(__is_identifier /* comment */ (xyz), "oops");
+
+// expected-error@+1 {{too few arguments}}
+#if __is_identifier()
+#endif
+
+// expected-error@+1 {{too many arguments}}
+#if __is_identifier(,())
+#endif
+
+// expected-error@+1 {{missing ')' after 'abc'}}
+#if __is_identifier(abc xyz) // expected-note {{to match this '('}}
+#endif
+
+// expected-error@+1 {{missing ')' after 'abc'}}
+#if __is_identifier(abc()) // expected-note {{to match this '('}}
+#endif
+
+// expected-error@+1 {{missing ')' after '.'}}
+#if __is_identifier(.abc) // expected-note {{to match this '('}}
+#endif
+
+// expected-error@+1 {{nested parentheses not permitted in '__is_identifier'}}
+#if __is_identifier((abc))
+#endif
+
+// expected-error@+1 {{missing '(' after '__is_identifier'}} expected-error@+1 {{expected value}}
+#if __is_identifier
+#endif
+
+// expected-error@+1 {{unterminated}} expected-error@+1 {{expected value}}
+#if __is_identifier(
+#endif
+
#endif
diff --git a/clang/test/Preprocessor/invalid-__has_warning1.c b/clang/test/Preprocessor/invalid-__has_warning1.c
index b6a0b2e8ee3..5e4f12f5699 100644
--- a/clang/test/Preprocessor/invalid-__has_warning1.c
+++ b/clang/test/Preprocessor/invalid-__has_warning1.c
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -verify %s
// These must be the last lines in this test.
-// expected-error@+1{{expected string literal}} expected-error@+1 2{{expected}}
+// expected-error@+1{{unterminated}} expected-error@+1 2{{expected}}
int i = __has_warning(
diff --git a/clang/test/Preprocessor/invalid-__has_warning2.c b/clang/test/Preprocessor/invalid-__has_warning2.c
index 8aba530c875..f54ff479931 100644
--- a/clang/test/Preprocessor/invalid-__has_warning2.c
+++ b/clang/test/Preprocessor/invalid-__has_warning2.c
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -verify %s
// These must be the last lines in this test.
-// expected-error@+1{{expected string literal}} expected-error@+1{{expected}}
+// expected-error@+1{{too few arguments}}
int i = __has_warning();
diff --git a/clang/test/Preprocessor/warning_tests.c b/clang/test/Preprocessor/warning_tests.c
index c0c22ef2d71..1f2e884a588 100644
--- a/clang/test/Preprocessor/warning_tests.c
+++ b/clang/test/Preprocessor/warning_tests.c
@@ -12,7 +12,7 @@
#endif
// expected-error@+2 {{expected string literal in '__has_warning'}}
-// expected-error@+1 {{expected value in expression}}
+// expected-error@+1 {{missing ')'}} expected-note@+1 {{match}}
#if __has_warning(-Wfoo)
#endif
@@ -22,8 +22,7 @@
#warning Not a valid warning flag
#endif
-// expected-error@+2 {{builtin warning check macro requires a parenthesized string}}
-// expected-error@+1 {{invalid token}}
+// expected-error@+1 {{missing '(' after '__has_warning'}}
#if __has_warning "not valid"
#endif
@@ -33,7 +32,7 @@
#define MY_ALIAS "-Wparentheses"
-// expected-error@+1 2{{expected}}
+// expected-error@+1 {{expected}}
#if __has_warning(MY_ALIAS)
#error Alias expansion not allowed
#endif
OpenPOWER on IntegriCloud