[jit] Require function names to be valid C identifiers for now
David Malcolm
dmalcolm@redhat.com
Wed Jan 1 00:00:00 GMT 2014
(Looks like the comma in the Subject stopped this getting through;
resending with suitably edited Subject)
Committed to branch dmalcolm/jit:
gcc/jit/
* libgccjit.c (IS_ASCII_ALPHA): New macro.
(IS_ASCII_DIGIT): New macro.
(IS_ASCII_ALNUM): New macro.
(gcc_jit_context_new_function): Require that function names be valid
C identifiers for now, to avoid later problems in the assembler.
---
gcc/jit/libgccjit.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/gcc/jit/libgccjit.c b/gcc/jit/libgccjit.c
index 3c2d962..bca60bd 100644
--- a/gcc/jit/libgccjit.c
+++ b/gcc/jit/libgccjit.c
@@ -8,6 +8,19 @@
#include "libgccjit.h"
#include "internal-api.h"
+#define IS_ASCII_ALPHA(CHAR) \
+ ( \
+ ((CHAR) >= 'a' && (CHAR) <='z') \
+ || \
+ ((CHAR) >= 'A' && (CHAR) <= 'Z') \
+ )
+
+#define IS_ASCII_DIGIT(CHAR) \
+ ((CHAR) >= '0' && (CHAR) <='9')
+
+#define IS_ASCII_ALNUM(CHAR) \
+ (IS_ASCII_ALPHA (CHAR) || IS_ASCII_DIGIT (CHAR))
+
struct gcc_jit_context : public gcc::jit::recording::context
{
gcc_jit_context (gcc_jit_context *parent_ctxt) :
@@ -395,6 +408,27 @@ gcc_jit_context_new_function (gcc_jit_context *ctxt,
RETURN_NULL_IF_FAIL (ctxt, NULL, "NULL context");
RETURN_NULL_IF_FAIL (return_type, ctxt, "NULL return_type");
RETURN_NULL_IF_FAIL (name, ctxt, "NULL name");
+ /* The assembler can only handle certain names, so for now, enforce
+ C's rules for identiers upon the name.
+ Eventually we'll need some way to interact with e.g. C++ name mangling. */
+ {
+ /* Leading char: */
+ char ch = *name;
+ RETURN_NULL_IF_FAIL_PRINTF2 (
+ IS_ASCII_ALPHA (ch) || ch == '_',
+ ctxt,
+ "name \"%s\" contains invalid character: '%c'",
+ name, ch);
+ /* Subsequent chars: */
+ for (const char *ptr = name + 1; (ch = *ptr); ptr++)
+ {
+ RETURN_NULL_IF_FAIL_PRINTF2 (
+ IS_ASCII_ALNUM (ch) || ch == '_',
+ ctxt,
+ "name \"%s\" contains invalid character: '%c'",
+ name, ch);
+ }
+ }
RETURN_NULL_IF_FAIL ((num_params == 0) || params, ctxt, "NULL params");
for (int i = 0; i < num_params; i++)
if (!params[i])
--
1.7.11.7
More information about the Jit
mailing list