[clang] df5213c - [clang][Interp][NFC] Return a const pointer from Pointer::getRecord()

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 4 08:22:09 PDT 2023


Author: Timm Bäder
Date: 2023-07-04T17:21:51+02:00
New Revision: df5213c4420e40dace6506d39bba28459a91c2a4

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

LOG: [clang][Interp][NFC] Return a const pointer from Pointer::getRecord()

Added: 
    

Modified: 
    clang/lib/AST/Interp/EvalEmitter.cpp
    clang/lib/AST/Interp/Interp.cpp
    clang/lib/AST/Interp/Pointer.h
    clang/lib/AST/Interp/Record.h

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/EvalEmitter.cpp b/clang/lib/AST/Interp/EvalEmitter.cpp
index 6d89bc407aad8d..f22cca90d4f412 100644
--- a/clang/lib/AST/Interp/EvalEmitter.cpp
+++ b/clang/lib/AST/Interp/EvalEmitter.cpp
@@ -123,7 +123,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
       Ty = AT->getValueType();
 
     if (auto *RT = Ty->getAs<RecordType>()) {
-      auto *Record = Ptr.getRecord();
+      const auto *Record = Ptr.getRecord();
       assert(Record && "Missing record descriptor");
 
       bool Ok = true;

diff  --git a/clang/lib/AST/Interp/Interp.cpp b/clang/lib/AST/Interp/Interp.cpp
index e906f65c371c27..c3503f4a078958 100644
--- a/clang/lib/AST/Interp/Interp.cpp
+++ b/clang/lib/AST/Interp/Interp.cpp
@@ -68,7 +68,7 @@ static bool CheckActive(InterpState &S, CodePtr OpPC, const Pointer &Ptr,
   }
 
   // Find the active field of the union.
-  Record *R = U.getRecord();
+  const Record *R = U.getRecord();
   assert(R && R->isUnion() && "Not a union");
   const FieldDecl *ActiveField = nullptr;
   for (unsigned I = 0, N = R->getNumFields(); I < N; ++I) {

diff  --git a/clang/lib/AST/Interp/Pointer.h b/clang/lib/AST/Interp/Pointer.h
index ab196beb93aa36..7d9e45a0a5a206 100644
--- a/clang/lib/AST/Interp/Pointer.h
+++ b/clang/lib/AST/Interp/Pointer.h
@@ -247,9 +247,11 @@ class Pointer {
   }
 
   /// Returns the record descriptor of a class.
-  Record *getRecord() const { return getFieldDesc()->ElemRecord; }
+  const Record *getRecord() const { return getFieldDesc()->ElemRecord; }
   /// Returns the element record type, if this is a non-primive array.
-  Record *getElemRecord() const { return getFieldDesc()->ElemDesc->ElemRecord; }
+  const Record *getElemRecord() const {
+    return getFieldDesc()->ElemDesc->ElemRecord;
+  }
   /// Returns the field information.
   const FieldDecl *getField() const { return getFieldDesc()->asFieldDecl(); }
 

diff  --git a/clang/lib/AST/Interp/Record.h b/clang/lib/AST/Interp/Record.h
index 52173fffa54474..24092f57c0d941 100644
--- a/clang/lib/AST/Interp/Record.h
+++ b/clang/lib/AST/Interp/Record.h
@@ -87,7 +87,7 @@ class Record final {
   }
 
   unsigned getNumBases() const { return Bases.size(); }
-  Base *getBase(unsigned I) { return &Bases[I]; }
+  const Base *getBase(unsigned I) const { return &Bases[I]; }
 
   using const_virtual_iter = VirtualBaseList::const_iterator;
   llvm::iterator_range<const_virtual_iter> virtual_bases() const {
@@ -95,7 +95,7 @@ class Record final {
   }
 
   unsigned getNumVirtualBases() const { return VirtualBases.size(); }
-  Base *getVirtualBase(unsigned I) { return &VirtualBases[I]; }
+  const Base *getVirtualBase(unsigned I) const { return &VirtualBases[I]; }
 
 private:
   /// Constructor used by Program to create record descriptors.


        


More information about the cfe-commits mailing list