<!DOCTYPE html>
<html lang="en" class="bg-zinc-900 text-zinc-100">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Clang Plugins - Getting Started - LLVM Project</title>
<script src="/tailwindcss.js"></script>
</head>
<body>
<!-- Header -->
<header class="bg-gradient-to-r from-amber-800 to-amber-700 shadow-xl">
<div class="container mx-auto px-6 py-4 flex items-center justify-between">
<a href="/llvm.org/index.html" class="text-2xl font-bold text-transparent bg-clip-text bg-gradient-to-r from-amber-500 to-amber-300">
LLVM
</a>
<nav class="hidden md:block">
<ul class="flex space-x-8">
<li><a href="/llvm.org/tools.html" class="hover:text-amber-200 transition-colors">Tools</a></li>
<li><a href="/llvm.org/documentation.html" class="hover:text-amber-200 transition-colors font-bold">Docs</a></li>
<li><a href="/llvm.org/community.html" class="hover:text-amber-200 transition-colors">Community</a></li>
</ul>
</nav>
</div>
</header>
<!-- Hero Section -->
<section class="py-20 px-6 bg-gradient-to-b from-zinc-900 to-zinc-800">
<div class="container mx-auto max-w-4xl text-center">
<h1 class="text-5xl font-extrabold text-amber-400 mb-6 tracking-tight">
Clang Plugins: Getting Started
</h1>
<p class="text-zinc-300 text-lg mb-10">
Learn to create and register simple Clang plugins for static analysis and code transformation
</p>
<a href="#tutorial"
class="inline-flex items-center px-8 py-3 bg-amber-600 text-white rounded-lg font-medium shadow-lg hover:bg-amber-500 transition-all transform hover:-translate-y-1">
<svg class="w-5 h-5 mr-2" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 11-2 0v-5h-5a1 1 0 010-2h5V4a1 1 0 012 0z" clip-rule="evenodd"/>
</svg>
Start Tutorial
</a>
</div>
</section>
<!-- Key Concepts -->
<section class="py-20 px-6 bg-gradient-to-b from-zinc-800/50 to-zinc-900/50">
<div class="container mx-auto max-w-6xl">
<h2 class="text-4xl font-bold text-amber-400 mb-14 text-center">Core Concepts</h2>
<div class="grid grid-cols-1 md:grid-cols-3 gap-12">
<div class="rounded-xl bg-zinc-800/70 border border-zinc-700 p-8 shadow-lg hover:shadow-amber-500/10 transition-all">
<div class="mb-6">
<svg class="w-12 h-12 text-amber-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v16h16V4H4z"/>
<line x1="16 8 6" y1="68 8 16"/>
</svg>
</div>
<h3 class="text-xl font-bold text-amber-300 mb-4">Plugin Infrastructure</h3>
<p class="text-zinc-300 mb-6">
Clang plugins extend the compiler with custom analysis and transformation features through its plugin architecture
</p>
<a href="/llvm.org/docs/clang-plugins.html"
class="text-amber-500 hover:text-amber-400 transition-colors inline-flex items-center">
Learn More
<svg class="w-4 h-4 ml-1" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 01-2 0v-5H4a1 1 0 010-2h5V4a1 1 0 011-1z" clip-rule="evenodd"/>
</svg>
</a>
</div>
<div class="rounded-xl bg-zinc-800/70 border border-zinc-700 p-8 shadow-lg hover:shadow-amber-500/10 transition-all">
<div class="mb-6">
<svg class="w-12 h-12 text-amber-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10m0 0a2 2 0 100-4 2 2 0 000 4z M7 16h.01M16 16H9">
</svg>
</div>
<h3 class="text-xl font-bold text-amber-300 mb-4">AST Transformation</h3>
<p class="text-zinc-300 mb-6">
Use Clang's AST to inspect, modify, and generate C/C++ source code during compilation
</p>
<a href="/llvm.org/tools/clang.html"
class="text-amber-500 hover:text-amber-400 transition-colors inline-flex items-center">
AST Deep Dive
<svg class="w-4 h-4 ml-1" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 3a7 7 0 100 14 7 7 0 000-14z" clip-rule="evenodd"/>
</svg>
</a>
</div>
<div class="rounded-xl bg-zinc-800/70 border border-zinc-700 p-8 shadow-lg hover:shadow-amber-500/10 transition-all">
<div class="mb-6">
<svg class="w-12 h-12 text-amber-400" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v4a2 2 0 012 2v-7a2 2 0 01-2-2H9l1-4h2m0-10v8a2 2 0 01-2 2H4a2 2 0 012-2V2h3a2 2 0 012 2v6a2 2 0 00-2 2h-2v-a 2 2 0 004 0V2h-2m0 12h2a1 1 0 001-1 1 1 0 11-2 0 1 1 0 2z"/>
</svg>
</div>
<h3 class="text-xl font-bold text-amber-300 mb-4">Registration</h3>
<p class="text-zinc-300 mb-6">
Link your plugin dynamically during Clang execution using the plugin registration mechanism
</p>
<a href="/llvm.org/docs/clang-plugins-advanced.html"
class="text-amber-500 hover:text-amber-400 transition-colors inline-flex items-center">
Plugin Registration
<svg class="w-4 h-4 ml-1" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 3a1 1 0 011 1v5h5a1 1 0 110 2h-5v5a1 1 0 01-2 0v-5H4a1 1 0 010-2h5V4a1 1 0 011-1z" clip-rule="evenodd"/>
</svg>
</a>
</div>
</div>
</div>
</section>
<!-- Getting Started -->
<section id="tutorial" class="py-20 bg-gradient-to-b from-zinc-900 to-zinc-800">
<div class="container mx-auto max-w-4xl">
<h2 class="text-3xl font-bold text-amber-400 mb-8 text-center">Basic Plugin Example</h2>
<div class="backdrop-blur-sm bg-white/5 rounded-2xl shadow-2xl overflow-hidden">
<div class="p-6 border-b border-zinc-700 bg-gradient-to-r from-amber-900/10 to-amber-800/10">
<h3 class="text-xl font-bold text-amber-400">MyFirstPlugin</h3>
</div>
<div class="p-6">
<pre class="bg-zinc-900/30 text-sm text-zinc-300 p-4 rounded-lg overflow-x-auto">
#include "clang/Plugin/PluginASTAction.h"
#include "clang/Sema/Sema.h"
using namespace clang;
namespace {
class MyPlugin : public PluginASTAction {
std::unique_ptr<ASTConsumer> CreateASTConsumer<TranslationUnit> {
return std::make_unique<ASTConsumer>();
}
bool ParseArgs(const CompilerInstance &CI,const std::vector<std::string> &args) {
// Handle command-line arguments
return true;
}
PluginRegistration<MyPlugin> X("my-plugin", "My first Clang plugin");
};
}
</pre>
</div>
</div>
<div class="mt-8">
<a href="/llvm.org/docs/clang-plugins-advanced.html"
class="inline-flex items-center px-8 py-3 bg-gradient-to-r from-amber-500 to-amber-400 text-white rounded-lg shadow-xl hover:from-amber-400 hover:to-amber-500 transition-all">
Continue to Advanced Topics
<svg class="w-5 h-5 ml-2" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 9 7.293 5.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd"/>
</svg>
</a>
</div>
</div>
</section>
<!-- Tutorial Outline -->
<section class="py-20 px-6 bg-zinc-800/50">
<div class="container mx-auto max-w-5xl">
<h2 class="text-4xl font-bold text-amber-400 mb-12 text-center">Tutorial Outline</h2>
<div class="space-y-6">
<div class="bg-zinc-800/70 rounded-xl p-6 border-l-4 border-amber-500">
<h3 class="text-amber-300 text-lg font-bold">Step 1: Setup Development Environment</h3>
<p class="text-zinc-300 mt-2">Install required build tools and clone LLVM repository with Clang source</p>
<code class="mt-3 block bg-zinc-900/50 p-3 rounded text-zinc-400">
$ git clone https://github.com/llvm/llvm-project.git
$ cd llvm-project
$ cmake -DLLVM_INCLUDE_EXTRAS=ON ...
</code>
</div>
<div class="bg-zinc-800/70 rounded-xl p-6 border-l-4 border-amber-500">
<h3 class="text-amber-300 text-lg font-bold">Step 2: Create Plugin Skeleton</h3>
<p class="text-zinc-300 mt-2">Implement basic plugin registration and AST consumer</p>
<code class="mt-3 block bg-zinc-900/50 p-3 rounded text-zinc-400">
// MyPlugin.cpp
#include "clang/Plugin/PluginASTAction.h"
#include "clang/Sema/Analyzer.h"
</code>
</div>
<div class="bg-zinc-800/70 rounded-xl p-6 border-l-4 border-amber-500">
<h3 class="text-amber-300 text-lg font-bold">Step 3: Build and Test</h3>
<p class="text-zinc-300 mt-2">Compile plugin and run with Clang command-line</p>
<code class="mt-3 block bg-zinc-900/50 p-3 rounded text-zinc-400">
$ clang -Xclang -load -Xclang myplugin.so -Xclang -plugin -Xclang my-plugin test.cc
</code>
</div>
</div>
</div>
</section>
<!-- Community Contribution -->
<section class="py-20 px-6 bg-gradient-to-b from-zinc-900 to-zinc-800">
<div class="container mx-auto max-w-3xl text-center">
<h2 class="text-3xl font-bold text-amber-400 mb-6">Help Improve Clang Plugins</h2>
<p class="text-zinc-300 mb-8">
Your first plugin could become the foundation for future compiler features!
</p>
<a href="/llvm.org/community/contribute.html"
class="px-8 py-3 text-lg font-bold bg-gradient-to-r from-amber-500 to-amber-400 text-white rounded-lg shadow-xl hover:from-amber-400 hover:to-amber-500 transition-all">
Share Your Plugin
</a>
</div>
</section>
<!-- Footer -->
<footer class="bg-zinc-800/90 border-t border-zinc-700">
<div class="container mx-auto px-6 py-12">
<div class="grid grid-cols-1 md:grid-cols-3 gap-8 text-zinc-400">
<div>
<h3 class="text-amber-400 font-bold text-lg mb-4">LLVM Project</h3>
<p class="text-sm mb-4">© 2025 The LLVM Project. All rights reserved.</p>
<ul class="flex space-x-4 text-sm">
<li>
<a href="/llvm.org/license.html" class="hover:text-amber-400 transition-colors">License</a>
</li>
<li>
<a href="/llvm.org/privacy.html" class="hover:text-amber-400 transition-colors">Privacy Policy</a>
</li>
</ul>
</div>
<div>
<h3 class="text-amber-400 font-bold text-lg mb-4">Tools</h3>
<ul class="space-y-2 text-sm">
<li><a href="/llvm.org/tools/clang.html" class="hover:text-amber-400 transition-colors">Clang</a></li>
<li><a href="/llvm.org/tools/lld.html" class="hover:text-amber-400 transition-colors">LLD</a></li>
<li><a href="/llvm.org/tools/lldb.html" class="hover:text-amber-400 transition-colors">LLDB</a></li>
</ul>
</div>
<div>
<h3 class="text-amber-400 font-bold text-lg mb-4">Resources</h3>
<ul class="space-y-2 text-sm">
<li><a href="/llvm.org/docs.html" class="hover:text-amber-400 transition-colors">Documentation</a></li>
<li><a href="/github.com/llvm/llvm-project" class="hover:text-amber-400 transition-colors">GitHub</a></li>
<li><a href="/llvm.org/community.html" class="hover:text-amber-400 transition-colors">Community</a></li>
</ul>
</div>
</div>
</div>
</footer>
</body>
</html>