[PATCH] Fix hardcoded path seperator in two code locations
Reid Kleckner
rnk at google.com
Fri May 9 13:43:55 PDT 2014
================
Comment at: lib/Support/Path.cpp:573
@@ +572,3 @@
+static const char preferred_separator_string[] = { preferred_separator, '\0' };
+static const StringRef preferred_separator_StringRef(preferred_separator_string);
+
----------------
We don't need this global data. It will probably require a dynamic initializer, which is lame. Clang is smart enough to optimize out strlen if you just return preferred_separator directly:
$ cat t.cpp
extern "C" int strlen(const char *s);
struct StringRef {
const char *p;
size_t len;
StringRef(const char *s) : p(s), len(strlen(s)) {}
};
static const char preferred_sep[] = { '/', '\0' };
StringRef getPrefSep() {
return StringRef(preferred_sep);
}
$ clang -c t.cpp -O2 -S -o - --target=x86_64-linux -fPIC | grep '^\s[^\.]'
leaq _ZL13preferred_sep(%rip), %rax
movl $1, %edx
retq
http://reviews.llvm.org/D3687
More information about the llvm-commits
mailing list