1 //===- UnsafeBufferUsage.h - Replace pointers with modern C++ ---*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines an analysis that aids replacing buffer accesses through 10 // raw pointers with safer C++ abstractions such as containers and views/spans. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H 15 #define LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H 16 17 #include "clang/AST/Decl.h" 18 #include "clang/AST/Stmt.h" 19 20 namespace clang { 21 22 /// The interface that lets the caller handle unsafe buffer usage analysis 23 /// results by overriding this class's handle... methods. 24 class UnsafeBufferUsageHandler { 25 public: 26 UnsafeBufferUsageHandler() = default; 27 virtual ~UnsafeBufferUsageHandler() = default; 28 29 /// This analyses produces large fixits that are organized into lists 30 /// of primitive fixits (individual insertions/removals/replacements). 31 using FixItList = llvm::SmallVectorImpl<FixItHint>; 32 33 /// Invoked when an unsafe operation over raw pointers is found. 34 virtual void handleUnsafeOperation(const Stmt *Operation, 35 bool IsRelatedToDecl) = 0; 36 37 /// Invoked when a fix is suggested against a variable. 38 virtual void handleFixableVariable(const VarDecl *Variable, 39 FixItList &&List) = 0; 40 }; 41 42 // This function invokes the analysis and allows the caller to react to it 43 // through the handler class. 44 void checkUnsafeBufferUsage(const Decl *D, UnsafeBufferUsageHandler &Handler); 45 46 } // end namespace clang 47 48 #endif /* LLVM_CLANG_ANALYSIS_ANALYSES_UNSAFEBUFFERUSAGE_H */ 49