diff options
author | zerny@chromium.org <zerny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-11 14:36:20 +0000 |
---|---|---|
committer | zerny@chromium.org <zerny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-11 14:36:20 +0000 |
commit | 1bcf88118f9f2095e00d47ce36e717ff50c16040 (patch) | |
tree | ae6d408298cdf4809ae135e3c93e644fa8076b6b /tools/clang | |
parent | 9329dc699d0118286468d50f3c49e416548e2f41 (diff) | |
download | chromium_src-1bcf88118f9f2095e00d47ce36e717ff50c16040.zip chromium_src-1bcf88118f9f2095e00d47ce36e717ff50c16040.tar.gz chromium_src-1bcf88118f9f2095e00d47ce36e717ff50c16040.tar.bz2 |
Add configuration code for the GC types and transition types.
The interpretation of transition types is governed by the plugin flag: oilpan-enabled.
This change also adds blink_gc_plugin to the default chrome tools in update.sh.
BUG=334149
Review URL: https://codereview.chromium.org/156243006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@250403 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/clang')
-rw-r--r-- | tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp | 13 | ||||
-rw-r--r-- | tools/clang/blink_gc_plugin/Config.h | 101 | ||||
-rwxr-xr-x | tools/clang/scripts/blink_gc_plugin_flags.sh | 7 | ||||
-rwxr-xr-x | tools/clang/scripts/update.sh | 2 |
4 files changed, 119 insertions, 4 deletions
diff --git a/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp b/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp index 7b248bc..300e90e 100644 --- a/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp +++ b/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp @@ -8,6 +8,8 @@ // Checks that are implemented: // [currently none] +#include "Config.h" + #include "clang/AST/AST.h" #include "clang/AST/ASTConsumer.h" #include "clang/Frontend/CompilerInstance.h" @@ -54,8 +56,13 @@ class BlinkGCPluginAction : public PluginASTAction { bool parsed = true; for (size_t i = 0; i < args.size() && parsed; ++i) { - parsed = false; - llvm::errs() << "Unknown blink-gc-plugin argument: " << args[i] << "\n"; + if (args[i] == "enable-oilpan") { + // TODO: Remove this once all transition types are eliminated. + Config::set_oilpan_enabled(true); + } else { + parsed = false; + llvm::errs() << "Unknown blink-gc-plugin argument: " << args[i] << "\n"; + } } return parsed; @@ -67,5 +74,7 @@ class BlinkGCPluginAction : public PluginASTAction { } // namespace +bool Config::oilpan_enabled_ = false; + static FrontendPluginRegistry::Add<BlinkGCPluginAction> X("blink-gc-plugin", "Check Blink GC invariants"); diff --git a/tools/clang/blink_gc_plugin/Config.h b/tools/clang/blink_gc_plugin/Config.h new file mode 100644 index 0000000..9dde0db --- /dev/null +++ b/tools/clang/blink_gc_plugin/Config.h @@ -0,0 +1,101 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This file defines the names used by GC infrastructure. + +#ifndef TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ +#define TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ + +#include "clang/AST/AST.h" + +const char kNewOperatorName[] = "operator new"; +const char kTraceName[] = "trace"; +const char kTraceAfterDispatchName[] = "traceAfterDispatch"; +const char kRegisterWeakMembersName[] = "registerWeakMembers"; +const char kHeapAllocatorName[] = "HeapAllocator"; + +class Config { + public: + + static bool IsMemberHandle(const std::string name) { + return name == "Member" + || name == "WeakMember" + || (oilpan_enabled() && EndsWith(name, "WillBeMember")); + } + + static bool IsPersistentHandle(const std::string name) { + return name == "Persistent" + || (oilpan_enabled() && EndsWith(name, "WillBePersistent")); + } + + static bool IsRefPtr(const std::string name) { + return name == "RefPtr" + || (!oilpan_enabled() && StartsWith(name, "RefPtrWillBe")); + } + + static bool IsOwnPtr(const std::string name) { + return name == "OwnPtr" + || (!oilpan_enabled() && StartsWith(name, "OwnPtrWillBe")); + } + + static bool IsWTFCollection(const std::string name) { + return name == "Vector" + || name == "HashSet" + || name == "HashMap" + || name == "HashCountedSet" + || name == "ListHashSet" + || name == "Deque"; + } + + static bool IsGCCollection(const std::string name) { + return name == "HeapVector" + || name == "HeapHashMap" + || name == "HeapHashSet"; + } + + static bool IsGCFinalizedBase(const std::string name) { + return name == "GarbageCollectedFinalized" + || name == "RefCountedGarbageCollected" + || (oilpan_enabled() + && (EndsWith(name, "WillBeGarbageCollectedFinalized") || + EndsWith(name, "WillBeRefCountedGarbageCollected"))); + } + + static bool IsGCBase(const std::string name) { + return name == "GarbageCollected" + || IsGCFinalizedBase(name) + || (oilpan_enabled() && EndsWith(name, "WillBeGarbageCollected")); + } + + static bool IsTraceMethod(clang::CXXMethodDecl* method, + bool* isTraceAfterDispatch = 0) { + const std::string name = method->getNameAsString(); + if (name == kTraceName || name == kTraceAfterDispatchName) { + if (isTraceAfterDispatch) + *isTraceAfterDispatch = (name == kTraceAfterDispatchName); + return true; + } + return false; + } + + static bool StartsWith(const std::string str, const std::string prefix) { + if (prefix.size() > str.size()) + return false; + return str.compare(0, prefix.size(), prefix) == 0; + } + + static bool EndsWith(const std::string str, const std::string suffix) { + if (suffix.size() > str.size()) + return false; + return str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; + } + + static void set_oilpan_enabled(bool enabled) { oilpan_enabled_ = enabled; } + static bool oilpan_enabled() { return oilpan_enabled_; } + + private: + static bool oilpan_enabled_; +}; + +#endif // TOOLS_BLINK_GC_PLUGIN_CONFIG_H_ diff --git a/tools/clang/scripts/blink_gc_plugin_flags.sh b/tools/clang/scripts/blink_gc_plugin_flags.sh index aaf4410..8e79037 100755 --- a/tools/clang/scripts/blink_gc_plugin_flags.sh +++ b/tools/clang/scripts/blink_gc_plugin_flags.sh @@ -14,5 +14,10 @@ else LIBSUFFIX=so fi +FLAGS="" +if [[ "$1" = "enable-oilpan=1" ]]; then + FLAGS="$FLAGS -Xclang -plugin-arg-blink-gc-plugin -Xclang enable-oilpan" +fi + echo -Xclang -load -Xclang $CLANG_LIB_PATH/libBlinkGCPlugin.$LIBSUFFIX \ - -Xclang -add-plugin -Xclang blink-gc-plugin + -Xclang -add-plugin -Xclang blink-gc-plugin $FLAGS diff --git a/tools/clang/scripts/update.sh b/tools/clang/scripts/update.sh index 3a2a106..6e7a2a4 100755 --- a/tools/clang/scripts/update.sh +++ b/tools/clang/scripts/update.sh @@ -42,7 +42,7 @@ mac_only= run_tests= bootstrap= with_android=yes -chrome_tools="plugins" +chrome_tools="plugins blink_gc_plugin" gcc_toolchain= if [[ "${OS}" = "Darwin" ]]; then |