# LLVM meets Code Property Graphs

DevFeed: [LLVM meets Code Property Graphs](<https://devfeed.tech/articles/llvm-meets-code-property-graphs-43075.md>)

Original publisher: [Read original article](<https://blog.llvm.org/posts/2021-02-23-llvm-meets-code-property-graphs/>)

Author: Alex Denisov, Fabian Yamaguchi

Published: 2021-02-23T00:00:00Z

Content type: tutorial

Language: en

Sources: [LLVM Project](<https://devfeed.tech/sources/the-llvm-project-blog.md>)

Topics: [LLVM](<https://devfeed.tech/topics/llvm.md>), [code analysis](<https://devfeed.tech/topics/code-analysis.md>), [graph-database](<https://devfeed.tech/topics/graph-database.md>), [Code](<https://devfeed.tech/topics/code.md>), [Programming](<https://devfeed.tech/topics/programming.md>), [domain-specific language](<https://devfeed.tech/topics/domain-specific-language.md>)

Tags: [code](<https://devfeed.tech/tags/code.md>), [code-analysis](<https://devfeed.tech/tags/code-analysis.md>), [code-property-graph](<https://devfeed.tech/tags/code-property-graph.md>), [database](<https://devfeed.tech/tags/database.md>), [domain-specific-language](<https://devfeed.tech/tags/domain-specific-language.md>), [graphs](<https://devfeed.tech/tags/graphs.md>), [llvm](<https://devfeed.tech/tags/llvm.md>), [open-source](<https://devfeed.tech/tags/open-source.md>)

## AI overview

This article explains code property graphs, which combine syntax, control-flow, and data-flow representations in a graph database queried through a domain-specific language. It introduces Joern and describes an open-source llvm2cpg tool that adds LLVM Bitcode support to Joern for code analysis and vulnerability discovery.

## Source excerpt

The code property graph (CPG) is a data structure designed to mine large codebases for instances of programming patterns via a domain-specific query language. It was first introduced in the proceedings of the IEEE Security and Privacy conference in 2014 (publication, PDF) in the context of vulnerability discovery in C system code and the Linux kernel in particular. The core ideas of the approach are the following: the CPG combines several program representations into one the CPG is stored in a graph database the graph database comes with a DSL allowing to traverse and query the CPG Currently, the CPG infrastructure is supported by several tools: Ocular - a proprietary code analysis tool supporting Java, Scala, C#, Go, Python, and JavaScript languages Joern - an open-source counterpart of Ocular supporting C and C++ Plume - an open-source tool supporting Java Bytecode This article presents ShiftLeft's open-source implementation of llvm2cpg - a standalone tool that brings LLVM Bitcode support to Joern.But before we dive into details, let us say few more words about CPG and Joern. Code Property Graph The core idea of the CPG is that different classic program representations are merged into a property graph, a single data structure that holds information about the program's syntax, control- and intra-procedural data-flow. Graphically speaking, the following piece of code: void foo() { int x = source(); if (x < MAX) { int y = 2 * x; sink(y); }} combines these three different representations: into a single representation - Code Property Graph: Joern The property graph is stored in a graph database and made accessible via a domain-specific language (DSL) to identify programming patterns based on a DSL for graph traversals. The query language allows a seamless transition between the original code representations, making it possible to combine aspects of the code from different views these representations offer. One of the primary interfaces to the code property graphs is a