[clang] 57304bb - [clang][Sema][NFC] Add const where appropriate

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Fri Apr 21 23:31:07 PDT 2023


Author: Timm Bäder
Date: 2023-04-22T08:28:27+02:00
New Revision: 57304bbda20014b23d5c706f99fefec7b5f6a31c

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

LOG: [clang][Sema][NFC] Add const where appropriate

Added: 
    

Modified: 
    clang/include/clang/AST/Expr.h
    clang/include/clang/Sema/Sema.h
    clang/lib/AST/Expr.cpp
    clang/lib/Sema/SemaLookup.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a7e28c852d6ec..d9b17f8eaf936 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3975,7 +3975,8 @@ class BinaryOperator : public Expr {
   // would match the 'p = (i8*)nullptr + n' idiom for casting a pointer-sized
   // integer to a pointer.
   static bool isNullPointerArithmeticExtension(ASTContext &Ctx, Opcode Opc,
-                                               Expr *LHS, Expr *RHS);
+                                               const Expr *LHS,
+                                               const Expr *RHS);
 
   static bool classof(const Stmt *S) {
     return S->getStmtClass() >= firstBinaryOperatorConstant &&

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index fd0b89eaec87c..0ab5dd9e8bb64 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2403,8 +2403,8 @@ class Sema final {
   bool hasReachableDeclarationSlow(
       const NamedDecl *D, llvm::SmallVectorImpl<Module *> *Modules = nullptr);
 
-  bool hasVisibleMergedDefinition(NamedDecl *Def);
-  bool hasMergedDefinitionInCurrentModule(NamedDecl *Def);
+  bool hasVisibleMergedDefinition(const NamedDecl *Def);
+  bool hasMergedDefinitionInCurrentModule(const NamedDecl *Def);
 
   /// Determine if \p D and \p Suggested have a structurally compatible
   /// layout as described in C11 6.2.7/1.

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 756acc37d569e..0ff10a511ef44 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1529,19 +1529,17 @@ unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
 Decl *Expr::getReferencedDeclOfCallee() {
   Expr *CEE = IgnoreParenImpCasts();
 
-  while (SubstNonTypeTemplateParmExpr *NTTP =
-             dyn_cast<SubstNonTypeTemplateParmExpr>(CEE)) {
+  while (auto *NTTP = dyn_cast<SubstNonTypeTemplateParmExpr>(CEE))
     CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
-  }
 
   // If we're calling a dereference, look at the pointer instead.
   while (true) {
-    if (BinaryOperator *BO = dyn_cast<BinaryOperator>(CEE)) {
+    if (auto *BO = dyn_cast<BinaryOperator>(CEE)) {
       if (BO->isPtrMemOp()) {
         CEE = BO->getRHS()->IgnoreParenImpCasts();
         continue;
       }
-    } else if (UnaryOperator *UO = dyn_cast<UnaryOperator>(CEE)) {
+    } else if (auto *UO = dyn_cast<UnaryOperator>(CEE)) {
       if (UO->getOpcode() == UO_Deref || UO->getOpcode() == UO_AddrOf ||
           UO->getOpcode() == UO_Plus) {
         CEE = UO->getSubExpr()->IgnoreParenImpCasts();
@@ -1551,9 +1549,9 @@ Decl *Expr::getReferencedDeclOfCallee() {
     break;
   }
 
-  if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(CEE))
+  if (auto *DRE = dyn_cast<DeclRefExpr>(CEE))
     return DRE->getDecl();
-  if (MemberExpr *ME = dyn_cast<MemberExpr>(CEE))
+  if (auto *ME = dyn_cast<MemberExpr>(CEE))
     return ME->getMemberDecl();
   if (auto *BE = dyn_cast<BlockExpr>(CEE))
     return BE->getBlockDecl();
@@ -1563,7 +1561,7 @@ Decl *Expr::getReferencedDeclOfCallee() {
 
 /// If this is a call to a builtin, return the builtin ID. If not, return 0.
 unsigned CallExpr::getBuiltinCallee() const {
-  auto *FDecl = getDirectCallee();
+  const auto *FDecl = getDirectCallee();
   return FDecl ? FDecl->getBuiltinID() : 0;
 }
 
@@ -1618,8 +1616,8 @@ const Attr *CallExpr::getUnusedResultAttr(const ASTContext &Ctx) const {
 }
 
 SourceLocation CallExpr::getBeginLoc() const {
-  if (isa<CXXOperatorCallExpr>(this))
-    return cast<CXXOperatorCallExpr>(this)->getBeginLoc();
+  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
+    return OCE->getBeginLoc();
 
   SourceLocation begin = getCallee()->getBeginLoc();
   if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
@@ -1627,8 +1625,8 @@ SourceLocation CallExpr::getBeginLoc() const {
   return begin;
 }
 SourceLocation CallExpr::getEndLoc() const {
-  if (isa<CXXOperatorCallExpr>(this))
-    return cast<CXXOperatorCallExpr>(this)->getEndLoc();
+  if (const auto *OCE = dyn_cast<CXXOperatorCallExpr>(this))
+    return OCE->getEndLoc();
 
   SourceLocation end = getRParenLoc();
   if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
@@ -1953,7 +1951,7 @@ const char *CastExpr::getCastKindName(CastKind CK) {
 namespace {
 // Skip over implicit nodes produced as part of semantic analysis.
 // Designed for use with IgnoreExprNodes.
-Expr *ignoreImplicitSemaNodes(Expr *E) {
+static Expr *ignoreImplicitSemaNodes(Expr *E) {
   if (auto *Materialize = dyn_cast<MaterializeTemporaryExpr>(E))
     return Materialize->getSubExpr();
 
@@ -2198,12 +2196,13 @@ OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) {
 
 bool BinaryOperator::isNullPointerArithmeticExtension(ASTContext &Ctx,
                                                       Opcode Opc,
-                                                      Expr *LHS, Expr *RHS) {
+                                                      const Expr *LHS,
+                                                      const Expr *RHS) {
   if (Opc != BO_Add)
     return false;
 
   // Check that we have one pointer and one integer operand.
-  Expr *PExp;
+  const Expr *PExp;
   if (LHS->getType()->isPointerType()) {
     if (!RHS->getType()->isIntegerType())
       return false;

diff  --git a/clang/lib/Sema/SemaLookup.cpp b/clang/lib/Sema/SemaLookup.cpp
index 1fda7269b6459..767dfeeb3cd7b 100644
--- a/clang/lib/Sema/SemaLookup.cpp
+++ b/clang/lib/Sema/SemaLookup.cpp
@@ -1603,14 +1603,14 @@ bool Sema::isUsableModule(const Module *M) {
   return false;
 }
 
-bool Sema::hasVisibleMergedDefinition(NamedDecl *Def) {
+bool Sema::hasVisibleMergedDefinition(const NamedDecl *Def) {
   for (const Module *Merged : Context.getModulesWithMergedDefinition(Def))
     if (isModuleVisible(Merged))
       return true;
   return false;
 }
 
-bool Sema::hasMergedDefinitionInCurrentModule(NamedDecl *Def) {
+bool Sema::hasMergedDefinitionInCurrentModule(const NamedDecl *Def) {
   for (const Module *Merged : Context.getModulesWithMergedDefinition(Def))
     if (isUsableModule(Merged))
       return true;


        


More information about the cfe-commits mailing list