summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorzerny@chromium.org <zerny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-20 10:55:58 +0000
committerzerny@chromium.org <zerny@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-20 10:55:58 +0000
commit8a42946253a3bee0e6b1e04a1ece2153ba505e83 (patch)
tree71708dbb360fe399d02c0695495861db9367a566
parent739f56c7bf03a4676733dbaa784f2c50034f1549 (diff)
downloadchromium_src-8a42946253a3bee0e6b1e04a1ece2153ba505e83.zip
chromium_src-8a42946253a3bee0e6b1e04a1ece2153ba505e83.tar.gz
chromium_src-8a42946253a3bee0e6b1e04a1ece2153ba505e83.tar.bz2
Stub clang plugin to check consistency of the Blink GC infrastructure.
R=ager@chromium.org, thakis@chromium.org BUG=334149 Review URL: https://codereview.chromium.org/133463002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@245897 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp71
-rw-r--r--tools/clang/blink_gc_plugin/Makefile19
-rw-r--r--tools/clang/blink_gc_plugin/OWNERS1
-rw-r--r--tools/clang/blink_gc_plugin/README.chromium2
-rwxr-xr-xtools/clang/blink_gc_plugin/tests/test.sh76
-rwxr-xr-xtools/clang/scripts/blink_gc_plugin_flags.sh18
-rwxr-xr-xtools/clang/scripts/package.sh1
-rwxr-xr-xtools/clang/scripts/update.sh8
8 files changed, 194 insertions, 2 deletions
diff --git a/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp b/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp
new file mode 100644
index 0000000..7b248bc
--- /dev/null
+++ b/tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp
@@ -0,0 +1,71 @@
+// 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 clang plugin checks various invariants of the Blink garbage
+// collection infrastructure.
+//
+// Checks that are implemented:
+// [currently none]
+
+#include "clang/AST/AST.h"
+#include "clang/AST/ASTConsumer.h"
+#include "clang/Frontend/CompilerInstance.h"
+#include "clang/Frontend/FrontendPluginRegistry.h"
+
+using namespace clang;
+using std::string;
+
+namespace {
+
+struct BlinkGCPluginOptions {
+ BlinkGCPluginOptions() {
+ }
+};
+
+// Main class containing checks for various invariants of the Blink
+// garbage collection infrastructure.
+class BlinkGCPluginConsumer : public ASTConsumer {
+ public:
+ BlinkGCPluginConsumer(CompilerInstance& instance,
+ const BlinkGCPluginOptions& options) {
+ }
+
+ virtual void HandleTranslationUnit(ASTContext& context) {
+ // FIXME: implement consistency checks.
+ }
+};
+
+
+class BlinkGCPluginAction : public PluginASTAction {
+ public:
+ BlinkGCPluginAction() {
+ }
+
+ protected:
+ // Overridden from PluginASTAction:
+ virtual ASTConsumer* CreateASTConsumer(CompilerInstance& instance,
+ llvm::StringRef ref) {
+ return new BlinkGCPluginConsumer(instance, options_);
+ }
+
+ virtual bool ParseArgs(const CompilerInstance& instance,
+ const std::vector<string>& args) {
+ 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";
+ }
+
+ return parsed;
+ }
+
+ private:
+ BlinkGCPluginOptions options_;
+};
+
+} // namespace
+
+static FrontendPluginRegistry::Add<BlinkGCPluginAction>
+X("blink-gc-plugin", "Check Blink GC invariants");
diff --git a/tools/clang/blink_gc_plugin/Makefile b/tools/clang/blink_gc_plugin/Makefile
new file mode 100644
index 0000000..ee17a0e
--- /dev/null
+++ b/tools/clang/blink_gc_plugin/Makefile
@@ -0,0 +1,19 @@
+# This file requires the clang build system, at least for now. So to use this
+# Makefile, you should execute the following commands to copy this directory
+# into a clang checkout:
+#
+# cp -R <this directory> third_party/llvm/tools/clang/tools/chrome-plugin
+# cd third_party/llvm/tools/clang/tools/chrome-plugin
+# make
+
+CLANG_LEVEL := ../..
+LIBRARYNAME = BlinkGCPlugin
+
+LINK_LIBS_IN_SHARED = 0
+SHARED_LIBRARY = 1
+
+include $(CLANG_LEVEL)/Makefile
+
+ifeq ($(OS),Darwin)
+ LDFLAGS=-Wl,-undefined,dynamic_lookup
+endif
diff --git a/tools/clang/blink_gc_plugin/OWNERS b/tools/clang/blink_gc_plugin/OWNERS
new file mode 100644
index 0000000..be76ffa
--- /dev/null
+++ b/tools/clang/blink_gc_plugin/OWNERS
@@ -0,0 +1 @@
+zerny@chromium.org
diff --git a/tools/clang/blink_gc_plugin/README.chromium b/tools/clang/blink_gc_plugin/README.chromium
new file mode 100644
index 0000000..294833c
--- /dev/null
+++ b/tools/clang/blink_gc_plugin/README.chromium
@@ -0,0 +1,2 @@
+This clang plugin checks various invariants of the Blink garbage
+collection infrastructure.
diff --git a/tools/clang/blink_gc_plugin/tests/test.sh b/tools/clang/blink_gc_plugin/tests/test.sh
new file mode 100755
index 0000000..6351d32
--- /dev/null
+++ b/tools/clang/blink_gc_plugin/tests/test.sh
@@ -0,0 +1,76 @@
+#!/bin/bash
+#
+# 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.
+#
+# Hacky, primitive testing: This runs the style plugin for a set of input files
+# and compares the output with golden result files.
+
+E_BADARGS=65
+E_FAILEDTEST=1
+
+failed_any_test=
+
+# Prints usage information.
+usage() {
+ echo "Usage: $(basename "${0}")" \
+ "<Path to the llvm build dir, usually Release+Asserts>"
+ echo ""
+ echo " Runs all the libBlinkGCPlugin unit tests"
+ echo ""
+}
+
+# Runs a single test case.
+do_testcase() {
+ local flags=""
+ if [ -e "${3}" ]; then
+ flags="$(cat "${3}")"
+ fi
+ local output="$("${CLANG_DIR}"/bin/clang -c -Wno-c++11-extensions \
+ -Xclang -load -Xclang "${CLANG_DIR}"/lib/libBlinkGCPlugin.${LIB} \
+ -Xclang -add-plugin -Xclang blink-gc-plugin ${flags} ${1} 2>&1)"
+ local diffout="$(echo "${output}" | diff - "${2}")"
+ if [ "${diffout}" = "" ]; then
+ echo "PASS: ${1}"
+ else
+ failed_any_test=yes
+ echo "FAIL: ${1}"
+ echo "Output of compiler:"
+ echo "${output}"
+ echo "Expected output:"
+ cat "${2}"
+ echo
+ fi
+}
+
+# Validate input to the script.
+if [[ -z "${1}" ]]; then
+ usage
+ exit ${E_BADARGS}
+elif [[ ! -d "${1}" ]]; then
+ echo "${1} is not a directory."
+ usage
+ exit ${E_BADARGS}
+else
+ export CLANG_DIR="${PWD}/${1}"
+ echo "Using clang directory ${CLANG_DIR}..."
+
+ # The golden files assume that the cwd is this directory. To make the script
+ # work no matter what the cwd is, explicitly cd to there.
+ cd "$(dirname "${0}")"
+
+ if [ "$(uname -s)" = "Linux" ]; then
+ export LIB=so
+ elif [ "$(uname -s)" = "Darwin" ]; then
+ export LIB=dylib
+ fi
+fi
+
+for input in *.cpp; do
+ do_testcase "${input}" "${input%cpp}txt" "${input%cpp}flags"
+done
+
+if [[ "${failed_any_test}" ]]; then
+ exit ${E_FAILEDTEST}
+fi
diff --git a/tools/clang/scripts/blink_gc_plugin_flags.sh b/tools/clang/scripts/blink_gc_plugin_flags.sh
new file mode 100755
index 0000000..aaf4410
--- /dev/null
+++ b/tools/clang/scripts/blink_gc_plugin_flags.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+# 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 script returns the flags that should be passed to clang.
+
+THIS_ABS_DIR=$(cd $(dirname $0) && echo $PWD)
+CLANG_LIB_PATH=$THIS_ABS_DIR/../../../third_party/llvm-build/Release+Asserts/lib
+
+if uname -s | grep -q Darwin; then
+ LIBSUFFIX=dylib
+else
+ LIBSUFFIX=so
+fi
+
+echo -Xclang -load -Xclang $CLANG_LIB_PATH/libBlinkGCPlugin.$LIBSUFFIX \
+ -Xclang -add-plugin -Xclang blink-gc-plugin
diff --git a/tools/clang/scripts/package.sh b/tools/clang/scripts/package.sh
index 16b3c7b..95f428f 100755
--- a/tools/clang/scripts/package.sh
+++ b/tools/clang/scripts/package.sh
@@ -59,6 +59,7 @@ cp "${LLVM_BIN_DIR}/llvm-symbolizer" $PDIR/bin/
# Copy plugins. Some of the dylibs are pretty big, so copy only the ones we
# care about.
cp "${LLVM_LIB_DIR}/libFindBadConstructs.${SO_EXT}" $PDIR/lib
+cp "${LLVM_LIB_DIR}/libBlinkGCPlugin.${SO_EXT}" $PDIR/lib
# Copy built-in headers (lib/clang/3.2/include).
# libcompiler-rt puts all kinds of libraries there too, but we want only some.
diff --git a/tools/clang/scripts/update.sh b/tools/clang/scripts/update.sh
index 39493f9..a262f63 100755
--- a/tools/clang/scripts/update.sh
+++ b/tools/clang/scripts/update.sh
@@ -311,8 +311,12 @@ done
if [[ -n "$run_tests" ]]; then
# Run a few tests.
- PLUGIN_SRC_DIR="${THIS_DIR}/../plugins"
- "${PLUGIN_SRC_DIR}/tests/test.sh" "${LLVM_BUILD_DIR}/Release+Asserts"
+ for CHROME_TOOL_DIR in ${chrome_tools}; do
+ TOOL_SRC_DIR="${THIS_DIR}/../${CHROME_TOOL_DIR}"
+ if [[ -f "${TOOL_SRC_DIR}/tests/test.sh" ]]; then
+ "${TOOL_SRC_DIR}/tests/test.sh" "${LLVM_BUILD_DIR}/Release+Asserts"
+ fi
+ done
cd "${LLVM_BUILD_DIR}"
make check-all
cd -