Author: David Stone Date: 2025-12-17T09:12:46-07:00 New Revision: 97cf9ea3b93b417825e7c6672242f7c8d06f5054
URL: https://github.com/llvm/llvm-project/commit/97cf9ea3b93b417825e7c6672242f7c8d06f5054 DIFF: https://github.com/llvm/llvm-project/commit/97cf9ea3b93b417825e7c6672242f7c8d06f5054.diff LOG: [clang][NFC] `inferNoReturnAttr` modifies the `Decl`, so it shouldn't be marked `const` (#172571) This removes a `const_cast`. Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/Sema.cpp clang/lib/Sema/SemaDeclAttr.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 22d7fa4b9c500..163612a835f03 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -844,7 +844,7 @@ enum Specifier { None, CPU, Tune }; enum AttrName { Target, TargetClones, TargetVersion }; } // end namespace DiagAttrParams -void inferNoReturnAttr(Sema &S, const Decl *D); +void inferNoReturnAttr(Sema &S, Decl *D); #ifdef __GNUC__ #pragma GCC diagnostic push @@ -1070,8 +1070,7 @@ class Sema final : public SemaBase { /// \param BlockType The type of the block expression, if D is a BlockDecl. PoppedFunctionScopePtr PopFunctionScopeInfo(const sema::AnalysisBasedWarnings::Policy *WP = nullptr, - const Decl *D = nullptr, - QualType BlockType = QualType()); + Decl *D = nullptr, QualType BlockType = QualType()); sema::FunctionScopeInfo *getEnclosingFunction() const; diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp index d32d7b960288d..6eea8f6e9d97e 100644 --- a/clang/lib/Sema/Sema.cpp +++ b/clang/lib/Sema/Sema.cpp @@ -2440,8 +2440,8 @@ static void markEscapingByrefs(const FunctionScopeInfo &FSI, Sema &S) { } Sema::PoppedFunctionScopePtr -Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP, - const Decl *D, QualType BlockType) { +Sema::PopFunctionScopeInfo(const AnalysisBasedWarnings::Policy *WP, Decl *D, + QualType BlockType) { assert(!FunctionScopes.empty() && "mismatched push/pop!"); markEscapingByrefs(*FunctionScopes.back(), *this); diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index df4aa0e6189c4..d5295b1f1f58e 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -2042,7 +2042,7 @@ static bool isKnownToAlwaysThrow(const FunctionDecl *FD) { return false; } -void clang::inferNoReturnAttr(Sema &S, const Decl *D) { +void clang::inferNoReturnAttr(Sema &S, Decl *D) { auto *FD = dyn_cast<FunctionDecl>(D); if (!FD) return; @@ -2054,7 +2054,6 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) { if (FD->getTemplateSpecializationKind() == TSK_ExplicitSpecialization) return; - auto *NonConstFD = const_cast<FunctionDecl *>(FD); DiagnosticsEngine &Diags = S.getDiagnostics(); if (Diags.isIgnored(diag::warn_falloff_nonvoid, FD->getLocation()) && Diags.isIgnored(diag::warn_suggest_noreturn_function, FD->getLocation())) @@ -2062,7 +2061,7 @@ void clang::inferNoReturnAttr(Sema &S, const Decl *D) { if (!FD->isNoReturn() && !FD->hasAttr<InferredNoReturnAttr>() && isKnownToAlwaysThrow(FD)) { - NonConstFD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context)); + FD->addAttr(InferredNoReturnAttr::CreateImplicit(S.Context)); // [[noreturn]] can only be added to lambdas since C++23 if (const auto *MD = dyn_cast<CXXMethodDecl>(FD); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
