aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2014-02-19 13:11:51 -0800
committerAlon Zakai <alonzakai@gmail.com>2014-02-19 13:12:28 -0800
commit16eb1c619ee8fc7913eb9e3fec6d0117bd71a180 (patch)
tree27a9a7aa12860f2e7d2f4ebb1547625de874e689 /lib
parentd4d4469b33ba23ee8801e75429f1d5c2ffc3e39c (diff)
tolerate arbitrary illegal chars in global names, lower all of them to _
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/JSBackend/JSBackend.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/Target/JSBackend/JSBackend.cpp b/lib/Target/JSBackend/JSBackend.cpp
index 1620d3e10e..5680d52b94 100644
--- a/lib/Target/JSBackend/JSBackend.cpp
+++ b/lib/Target/JSBackend/JSBackend.cpp
@@ -413,14 +413,14 @@ static inline char halfCharToHex(unsigned char half) {
static inline void sanitizeGlobal(std::string& str) {
// functions and globals should already be in C-style format,
- // in addition to . for llvm intrinsics. There is a risk of
- // collisions with . and _, but this should not happen in
- // practice.
+ // in addition to . for llvm intrinsics and possibly $ and so forth.
+ // There is a risk of collisions here, we just lower all these
+ // invalid characters to _, but this should not happen in practice.
+ // TODO: in debug mode, check for such collisions.
size_t OriginalSize = str.size();
for (size_t i = 1; i < OriginalSize; ++i) {
unsigned char c = str[i];
- if (c == '.') str[i] = '_';
- assert(isalnum(c) || c == '_' || c == '.');
+ if (!isalnum(c) && c != '_') str[i] = '_';
}
}
@@ -1765,7 +1765,9 @@ void JSWriter::printFunction(const Function *F) {
// Emit the function
- Out << "function _" << F->getName() << "(";
+ std::string Name = F->getName();
+ sanitizeGlobal(Name);
+ Out << "function _" << Name << "(";
for (Function::const_arg_iterator AI = F->arg_begin(), AE = F->arg_end();
AI != AE; ++AI) {
if (AI != F->arg_begin()) Out << ",";