[clang] e969bd7 - [clang][ExprConst] Move getLangOpts() to interp::State subclasses (#159280)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 17 06:16:33 PDT 2025


Author: Timm Baeder
Date: 2025-09-17T15:16:28+02:00
New Revision: e969bd71221bd45b5a64aaed5ae1d227b7242c0f

URL: https://github.com/llvm/llvm-project/commit/e969bd71221bd45b5a64aaed5ae1d227b7242c0f
DIFF: https://github.com/llvm/llvm-project/commit/e969bd71221bd45b5a64aaed5ae1d227b7242c0f.diff

LOG: [clang][ExprConst] Move getLangOpts() to interp::State subclasses (#159280)

Instead of having `State::getLangOpts()`, which does a virtual call to
`getASTContext()` to call `getLangOpts()` on that, just move
`getLangOpts()` to the subclasses so we can do that without the virtual
call. We never call `getLangOpts()` in `State.cpp`, so it's not needed
in the base class.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/InterpState.h
    clang/lib/AST/ByteCode/State.cpp
    clang/lib/AST/ByteCode/State.h
    clang/lib/AST/ExprConstant.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/InterpState.h b/clang/lib/AST/ByteCode/InterpState.h
index 1814d273ec1c6..a13244bf383ae 100644
--- a/clang/lib/AST/ByteCode/InterpState.h
+++ b/clang/lib/AST/ByteCode/InterpState.h
@@ -68,6 +68,9 @@ class InterpState final : public State, public SourceMapper {
     return Parent.getEvalStatus();
   }
   ASTContext &getASTContext() const override { return Ctx.getASTContext(); }
+  const LangOptions &getLangOpts() const {
+    return Ctx.getASTContext().getLangOpts();
+  }
 
   // Forward status checks and updates to the walker.
   bool keepEvaluatingAfterFailure() const override {

diff  --git a/clang/lib/AST/ByteCode/State.cpp b/clang/lib/AST/ByteCode/State.cpp
index dc3d0da7a4a46..323231fbf8236 100644
--- a/clang/lib/AST/ByteCode/State.cpp
+++ b/clang/lib/AST/ByteCode/State.cpp
@@ -112,10 +112,6 @@ OptionalDiagnostic State::diag(SourceLocation Loc, diag::kind DiagId,
   return OptionalDiagnostic();
 }
 
-const LangOptions &State::getLangOpts() const {
-  return getASTContext().getLangOpts();
-}
-
 void State::addCallStack(unsigned Limit) {
   // Determine which calls to skip, if any.
   unsigned ActiveCalls = getCallStackDepth() - 1;

diff  --git a/clang/lib/AST/ByteCode/State.h b/clang/lib/AST/ByteCode/State.h
index a834eed142de0..0695c61c07a05 100644
--- a/clang/lib/AST/ByteCode/State.h
+++ b/clang/lib/AST/ByteCode/State.h
@@ -151,8 +151,6 @@ class State {
   /// Directly reports a diagnostic message.
   DiagnosticBuilder report(SourceLocation Loc, diag::kind DiagId);
 
-  const LangOptions &getLangOpts() const;
-
   /// Whether or not we're in a context where the front end requires a
   /// constant value.
   bool InConstantContext = false;

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index d0c0c7f3ed120..a4332f076e8c0 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -945,6 +945,7 @@ namespace {
     }
 
     ASTContext &getASTContext() const override { return Ctx; }
+    const LangOptions &getLangOpts() const { return Ctx.getLangOpts(); }
 
     void setEvaluatingDecl(APValue::LValueBase Base, APValue &Value,
                            EvaluatingDeclKind EDK = EvaluatingDeclKind::Ctor) {


        


More information about the cfe-commits mailing list