[Mesa-dev] [PATCH 7/6] glsl/glcpp: Add testing of illegal characters in macro replacement lists

Carl Worth cworth at cworth.org
Thu Aug 7 15:20:39 PDT 2014


The desired behavior here is that there is no error for an illegal character
appearing in the replacement list of a macro definition.

However, any expansion of such a macro, causing the illegal character to
appear in the preprocessed source, should emit an error.

These two tests exercise both of the cases, ensuring that the error is not
emitted until the macro is actually expanded.
---
 .../142-illegal-characters-in-macro-definition.c   | 17 ++++++++++++
 ...legal-characters-in-macro-definition.c.expected | 17 ++++++++++++
 .../tests/143-illegal-characters-in-macro-use.c    | 24 +++++++++++++++++
 .../143-illegal-characters-in-macro-use.c.expected | 31 ++++++++++++++++++++++
 4 files changed, 89 insertions(+)
 create mode 100644 src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c
 create mode 100644 src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c.expected
 create mode 100644 src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c
 create mode 100644 src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c.expected

diff --git a/src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c b/src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c
new file mode 100644
index 0000000..a58cdcc
--- /dev/null
+++ b/src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c
@@ -0,0 +1,17 @@
+/* Our reading of the C++ specification, (as deferred to by the GLSL
+ * specification), suggests that all characters are legal as part of a macro
+ * replacement list, but actually using such a macro with an illegal character
+ * should emit an error.
+ */
+
+/* So no errors here for just defining things with illegal characters. */
+#define DOUBLE_QUOTE "
+#define DOLLAR $
+#define APOSTROPHE '
+#define AT_SIGN @
+#define BACK_TICK `
+#define HASH #
+#define BACK_SLASH_NOT_AT_END \...
+
+/* See the following test which ensures that using any of the above macros
+ * will generate an error. */
diff --git a/src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c.expected b/src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c.expected
new file mode 100644
index 0000000..46c7ab9
--- /dev/null
+++ b/src/glsl/glcpp/tests/142-illegal-characters-in-macro-definition.c.expected
@@ -0,0 +1,17 @@
+ 
+
+
+
+
+
+ 
+
+
+
+
+
+
+
+
+ 
+
diff --git a/src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c b/src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c
new file mode 100644
index 0000000..b3b1d37
--- /dev/null
+++ b/src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c
@@ -0,0 +1,24 @@
+/* Our reading of the C++ specification, (as deferred to by the GLSL
+ * specification), suggests that all characters are legal as part of a macro
+ * replacement list, but actually using such a macro with an illegal character
+ * should emit an error.
+ */
+
+/* So no errors here for just defining things with illegal characters.
+ * (See the previous test which ensures there are no errors here.) */
+#define DOUBLE_QUOTE "
+#define DOLLAR $
+#define APOSTROPHE '
+#define AT_SIGN @
+#define BACK_TICK `
+#define HASH #
+#define BACK_SLASH_NOT_AT_END \...
+
+/* But each of these should cause an error. */
+DOUBLE_QUOTE
+DOLLAR
+APOSTROPHE
+AT_SIGN
+BACK_TICK
+HASH
+BACK_SLASH_NOT_AT_END
diff --git a/src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c.expected b/src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c.expected
new file mode 100644
index 0000000..6b948d6
--- /dev/null
+++ b/src/glsl/glcpp/tests/143-illegal-characters-in-macro-use.c.expected
@@ -0,0 +1,31 @@
+0:9(22): preprocessor error: Illegal character '"'
+0:10(16): preprocessor error: Illegal character '$'
+0:11(20): preprocessor error: Illegal character '''
+0:12(17): preprocessor error: Illegal character '@'
+0:13(19): preprocessor error: Illegal character '`'
+0:14(14): preprocessor error: Illegal character '#'
+0:15(31): preprocessor error: Illegal character '\'
+ 
+
+
+
+
+
+ 
+
+
+
+
+
+
+
+
+
+ 
+
+
+
+
+
+
+...
-- 
2.0.0



More information about the mesa-dev mailing list