[clang] [llvm] [SSAF][PointerFlow] Factor out and make the pointer-flow matching reusable (PR #222780)
Jan Korous via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 15 16:53:34 PDT 2026
================
@@ -0,0 +1,122 @@
+//===- PointerFlowPairs.h ---------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+// This file provides PointerFlowPair and PointerFlowPairMatcher.
+//
+// PointerFlowPair represents an element '(l, r)' of the pointer-flow relation
+// over declarations and expressions of pointer/array type. Each pair
+// corresponds to a value-copying (or "assignment"-flavored) language construct
+// (e.g. an assignment, argument passing, a return, or an initialization). It
+// requires that if 'l's type is refined to carry a property (e.g., buffer
+// bounds), then 'r's type must follow; otherwise the property would be
+// lost in value-copy from 'r' to 'l'.
+//
+// PointerFlowPairMatcher walks an AST node and collects the PointerFlowPairs it
+// generates. It outputs matched pairs '(l, r)' such that
+// - 'l' and 'r' have compatible types;
+// - 'l' is either a pointer or an array;
+// - 'r' may be a list-initializer, when it has an array type.
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_POINTERFLOW_POINTERFLOWPAIRS_H
+#define LLVM_CLANG_SCALABLESTATICANALYSIS_ANALYSES_POINTERFLOW_POINTERFLOWPAIRS_H
+
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/TypeBase.h"
+#include "llvm/ADT/SmallVector.h"
+#include <type_traits>
+
+namespace clang::ssaf {
+
+/// Data structure representing a pointer flow.
+/// Invariant: LHS and RHS should have compatible types.
+struct PointerFlowPair {
+ /// The left-hand side of an assignment or a variable/field
+ /// definition, a formal parameter, or the function owning a return
+ /// stmt:
+ llvm::PointerUnion<const ValueDecl *, const Expr *> LHS;
+ /// The right-hand side of an assignment or a variable/field
+ /// definition, an actual argument, or the expr being returning:
+ const Expr *RHS;
+ /// True iff the left-hand side of this PointerFlowPair represents the
+ /// return entity of a callable:
+ bool IsLHSRet;
----------------
jkorous-apple wrote:
I just started reading the PR and it's not obvious to me why this is necessary.
I don't want to forget about this so commenting now and I might delete later if I find the explanation.
https://github.com/llvm/llvm-project/pull/222780
More information about the llvm-commits
mailing list