diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /build/clang-plugin/VariableUsageHelpers.h | |
parent | Initial commit. (diff) | |
download | firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.tar.xz firefox-esr-37a0381f8351b370577b65028ba1f6563ae23fdf.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | build/clang-plugin/VariableUsageHelpers.h | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/build/clang-plugin/VariableUsageHelpers.h b/build/clang-plugin/VariableUsageHelpers.h new file mode 100644 index 0000000000..d498857eea --- /dev/null +++ b/build/clang-plugin/VariableUsageHelpers.h @@ -0,0 +1,63 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef VariableUsageHelpers_h__ +#define VariableUsageHelpers_h__ + +#include "plugin.h" + +/// Returns a list of the statements where the given declaration is used as an +/// rvalue (within the provided function). +/// +/// WARNING: incomplete behaviour/implementation for general-purpose use outside +/// of escapesFunction(). This only detects very basic usages (see +/// implementation for more details). +std::vector<const Stmt *> getUsageAsRvalue(const ValueDecl *ValueDeclaration, + const FunctionDecl *FuncDecl); + +/// This is the error enumeration for escapesFunction(), describing all the +/// possible error cases. +enum class EscapesFunctionError { + ConstructorDeclNotFound = 1, + FunctionDeclNotFound, + FunctionIsBuiltin, + FunctionIsVariadic, + ExprNotInCall, + NoParamForArg, + ArgAndParamNotPointers +}; + +/// Required by the std::error_code system to convert our enum into a general +/// error code. +std::error_code make_error_code(EscapesFunctionError); + +/// Returns a (statement, decl) tuple if an argument from an argument list +/// escapes the function scope through globals/statics/other things. The +/// statement is where the value escapes the function, while the declaration +/// points to what it escapes through. If the argument doesn't escape the +/// function, the tuple will only contain nullptrs. +/// If the analysis runs into an unexpected error or into an unimplemented +/// configuration, it will return an error_code of type EscapesFunctionError +/// representing the precise issue. +/// +/// WARNING: incomplete behaviour/implementation for general-purpose use outside +/// of DanglingOnTemporaryChecker. This only covers a limited set of cases, +/// mainly in terms of arguments and parameter types. +ErrorOr<std::tuple<const Stmt *, const Decl *>> +escapesFunction(const Expr *Arg, const FunctionDecl *FuncDecl, + const Expr *const *Arguments, unsigned NumArgs); + +/// Helper function taking a call expression. +ErrorOr<std::tuple<const Stmt *, const Decl *>> +escapesFunction(const Expr *Arg, const CallExpr *Call); + +/// Helper function taking a construct expression. +ErrorOr<std::tuple<const Stmt *, const Decl *>> +escapesFunction(const Expr *Arg, const CXXConstructExpr *Construct); + +/// Helper function taking an operator call expression. +ErrorOr<std::tuple<const Stmt *, const Decl *>> +escapesFunction(const Expr *Arg, const CXXOperatorCallExpr *OpCall); + +#endif |