summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-10-17 15:26:34 +0000
committerHaojian Wu <hokein@google.com>2016-10-17 15:26:34 +0000
commitac97fc3902c446bef023c91c3bd4beb2635ecb0d (patch)
tree4295948e3434a72ec3b01983c2e51ffdb6583fa0
parentc0ef9e43168213a8496e170340afabc8d6d16e0f (diff)
downloadbcm5719-llvm-ac97fc3902c446bef023c91c3bd4beb2635ecb0d.tar.gz
bcm5719-llvm-ac97fc3902c446bef023c91c3bd4beb2635ecb0d.zip
[clang-move] Fix generating illegal header guard.
The filepath might contain some characters (i.e. '@') which are not illegal in c identifiers. This patch changes all non-alphanumeric characters to '_'. llvm-svn: 284391
-rw-r--r--clang-tools-extra/clang-move/ClangMove.cpp8
1 files changed, 4 insertions, 4 deletions
diff --git a/clang-tools-extra/clang-move/ClangMove.cpp b/clang-tools-extra/clang-move/ClangMove.cpp
index c8365f07f86..268d31dc4b9 100644
--- a/clang-tools-extra/clang-move/ClangMove.cpp
+++ b/clang-tools-extra/clang-move/ClangMove.cpp
@@ -233,10 +233,10 @@ createInsertedReplacements(const std::vector<std::string> &Includes,
std::string NewCode;
std::string GuardName(FileName);
if (IsHeader) {
- std::replace(GuardName.begin(), GuardName.end(), '/', '_');
- std::replace(GuardName.begin(), GuardName.end(), '.', '_');
- std::replace(GuardName.begin(), GuardName.end(), '-', '_');
-
+ for (size_t i = 0; i < GuardName.size(); ++i) {
+ if (!isAlphanumeric(GuardName[i]))
+ GuardName[i] = '_';
+ }
GuardName = StringRef(GuardName).upper();
NewCode += "#ifndef " + GuardName + "\n";
NewCode += "#define " + GuardName + "\n";
OpenPOWER on IntegriCloud