clang 24.0.0git
ClassUtils.cpp
Go to the documentation of this file.
1//===--- ClassUtils.cpp - Shared C++ class emission queries ---------------===//
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
11
12namespace clang::CodeGenUtils {
13namespace {
14/// A visitor which checks whether an initializer uses 'this' in a
15/// way which requires the vtable to be properly set.
16struct DynamicThisUseChecker
17 : ConstEvaluatedExprVisitor<DynamicThisUseChecker> {
18 using super = ConstEvaluatedExprVisitor<DynamicThisUseChecker>;
19
20 bool UsesThis = false;
21
22 DynamicThisUseChecker(const ASTContext &C) : super(C) {}
23
24 // Black-list all explicit and implicit references to 'this'.
25 //
26 // Do we need to worry about external references to 'this' derived
27 // from arbitrary code? If so, then anything which runs arbitrary
28 // external code might potentially access the vtable.
29 void VisitCXXThisExpr(const CXXThisExpr *E) { UsesThis = true; }
30};
31} // namespace
32
34 DynamicThisUseChecker Checker(Ctx);
35 Checker.Visit(Init);
36 return Checker.UsesThis;
37}
38
39} // namespace clang::CodeGenUtils
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:239
This represents one expression.
Definition Expr.h:113
bool baseInitializerUsesThis(ASTContext &Ctx, const Expr *Init)
Check whether Init uses 'this' in a way which requires the vtable to be properly set.