[clang] [ObjC] Enable diagnose_if on Objective-C methods (PR #115056)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 5 12:26:40 PST 2024
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 17d956588a2cc508acf98574f913eaef6d0e1af3 802e8e85de3b3d0a8c6ccd4f7ac3536f10183ea2 --extensions h,cpp -- clang/include/clang/AST/Expr.h clang/include/clang/Sema/Sema.h clang/lib/AST/ExprConstant.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/lib/Sema/SemaExprObjC.cpp clang/lib/Sema/SemaOverload.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index c684204ba0..243afc3041 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -742,7 +742,7 @@ public:
/// constant.
bool EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
const NamedDecl *Callee,
- ArrayRef<const Expr*> Args,
+ ArrayRef<const Expr *> Args,
const Expr *This = nullptr) const;
enum class ConstantExprKind {
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6a9a278ba2..09e6e4feaa 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -527,9 +527,7 @@ namespace {
CallableDecl(const FunctionDecl *MD) : DC(MD) {}
CallableDecl() : CallableDecl(nullptr) {}
- operator bool() const {
- return DC;
- }
+ operator bool() const { return DC; }
const NamedDecl *getAsNamedDecl() const {
if (auto Func = dyn_cast<FunctionDecl>(DC))
@@ -537,9 +535,7 @@ namespace {
return cast<ObjCMethodDecl>(DC);
}
- const DeclContext *getAsDeclContext() const {
- return DC;
- }
+ const DeclContext *getAsDeclContext() const { return DC; }
const FunctionDecl *getAsFunctionDecl() const {
return dyn_cast_or_null<FunctionDecl>(DC);
@@ -686,15 +682,13 @@ namespace {
llvm::DenseMap<const ValueDecl *, FieldDecl *> LambdaCaptureFields;
FieldDecl *LambdaThisCaptureField = nullptr;
- CallStackFrame(EvalInfo &Info, SourceRange CallRange,
- CallableDecl Callable, const LValue *This,
- const Expr *CallExpr, CallRef Arguments);
+ CallStackFrame(EvalInfo &Info, SourceRange CallRange, CallableDecl Callable,
+ const LValue *This, const Expr *CallExpr, CallRef Arguments);
- CallStackFrame(EvalInfo &Info, SourceRange CallRange,
- std::nullptr_t, const LValue *This,
- const Expr *CallExpr, CallRef Arguments)
- : CallStackFrame(Info, CallRange, CallableDecl(), This, CallExpr, Arguments)
- { }
+ CallStackFrame(EvalInfo &Info, SourceRange CallRange, std::nullptr_t,
+ const LValue *This, const Expr *CallExpr, CallRef Arguments)
+ : CallStackFrame(Info, CallRange, CallableDecl(), This, CallExpr,
+ Arguments) {}
~CallStackFrame();
@@ -738,10 +732,13 @@ namespace {
Frame *getCaller() const override { return Caller; }
SourceRange getCallRange() const override { return CallRange; }
- const FunctionDecl *getCallee() const override { return Callee.getAsFunctionDecl(); }
+ const FunctionDecl *getCallee() const override {
+ return Callee.getAsFunctionDecl();
+ }
bool isStdFunction() const {
- for (const DeclContext *DC = Callee.getAsDeclContext(); DC; DC = DC->getParent())
+ for (const DeclContext *DC = Callee.getAsDeclContext(); DC;
+ DC = DC->getParent())
if (DC->isStdNamespace())
return true;
return false;
@@ -2082,11 +2079,12 @@ void CallStackFrame::describe(raw_ostream &Out) const {
bool IsMemberCall = false;
const NamedDecl *ND = Callee.getAsNamedDecl();
if (auto MD = Callee.getAsCXXMethodDecl())
- IsMemberCall = !isa<CXXConstructorDecl>(MD) && MD->isImplicitObjectMemberFunction();
+ IsMemberCall =
+ !isa<CXXConstructorDecl>(MD) && MD->isImplicitObjectMemberFunction();
if (!IsMemberCall)
ND->getNameForDiagnostic(Out, Info.Ctx.getPrintingPolicy(),
- /*Qualified=*/false);
+ /*Qualified=*/false);
if (This && IsMemberCall) {
if (const auto *MCE = dyn_cast_if_present<CXXMemberCallExpr>(CallExpr)) {
@@ -2112,14 +2110,15 @@ void CallStackFrame::describe(raw_ostream &Out) const {
Out << ".";
}
ND->getNameForDiagnostic(Out, Info.Ctx.getPrintingPolicy(),
- /*Qualified=*/false);
+ /*Qualified=*/false);
IsMemberCall = false;
}
Out << '(';
for (CallableDecl::param_const_iterator I = Callee.param_begin(),
- E = Callee.param_end(); I != E; ++I, ++ArgIndex) {
+ E = Callee.param_end();
+ I != E; ++I, ++ArgIndex) {
if (ArgIndex > (unsigned)IsMemberCall)
Out << ", ";
@@ -3572,7 +3571,8 @@ static bool evaluateVarDeclInit(EvalInfo &Info, const Expr *E,
// constant expressions.
if (!Info.checkingPotentialConstantExpression() ||
!Info.CurrentCall->Callee ||
- !Info.CurrentCall->Callee.getAsDeclContext()->Equals(VD->getDeclContext())) {
+ !Info.CurrentCall->Callee.getAsDeclContext()->Equals(
+ VD->getDeclContext())) {
if (Info.getLangOpts().CPlusPlus11) {
Info.FFDiag(E, diag::note_constexpr_function_param_value_unknown)
<< VD;
@@ -8918,7 +8918,8 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
// to within 'E' actually represents a lambda-capture that maps to a
// data-member/field within the closure object, and if so, evaluate to the
// field or what the field refers to.
- if (Info.CurrentCall && isLambdaCallOperator(Info.CurrentCall->Callee.getAsFunctionDecl()) &&
+ if (Info.CurrentCall &&
+ isLambdaCallOperator(Info.CurrentCall->Callee.getAsFunctionDecl()) &&
isa<DeclRefExpr>(E) &&
cast<DeclRefExpr>(E)->refersToEnclosingVariableOrCapture()) {
// We don't always have a complete capture-map when checking or inferring if
@@ -8945,7 +8946,8 @@ bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
// variable) or be ill-formed (and trigger an appropriate evaluation
// diagnostic)).
CallStackFrame *CurrFrame = Info.CurrentCall;
- if (CurrFrame->Callee && CurrFrame->Callee.getAsDeclContext()->Equals(VD->getDeclContext())) {
+ if (CurrFrame->Callee &&
+ CurrFrame->Callee.getAsDeclContext()->Equals(VD->getDeclContext())) {
// Function parameters are stored in some caller's frame. (Usually the
// immediate caller, but for an inherited constructor they may be more
// distant.)
@@ -9468,8 +9470,8 @@ public:
if (Info.checkingPotentialConstantExpression())
return false;
- bool IsExplicitLambda =
- isLambdaCallWithExplicitObjectParameter(Info.CurrentCall->Callee.getAsFunctionDecl());
+ bool IsExplicitLambda = isLambdaCallWithExplicitObjectParameter(
+ Info.CurrentCall->Callee.getAsFunctionDecl());
if (!IsExplicitLambda) {
if (!Info.CurrentCall->This) {
DiagnoseInvalidUseOfThis();
@@ -9625,7 +9627,8 @@ bool PointerExprEvaluator::VisitCastExpr(const CastExpr *E) {
// that back to `const __impl*` in its body.
if (VoidPtrCastMaybeOK &&
(Info.getStdAllocatorCaller("allocate") ||
- IsDeclSourceLocationCurrent(Info.CurrentCall->Callee.getAsFunctionDecl()) ||
+ IsDeclSourceLocationCurrent(
+ Info.CurrentCall->Callee.getAsFunctionDecl()) ||
Info.getLangOpts().CPlusPlus26)) {
// Permitted.
} else {
@@ -17490,12 +17493,13 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
bool Expr::EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
const NamedDecl *Callee,
- ArrayRef<const Expr*> Args,
+ ArrayRef<const Expr *> Args,
const Expr *This) const {
assert(!isValueDependent() &&
"Expression evaluator can't be called on a dependent expression.");
- assert(Callee != nullptr || Args.empty() && "substitutions always fail when Callee is nullptr");
+ assert(Callee != nullptr ||
+ Args.empty() && "substitutions always fail when Callee is nullptr");
llvm::TimeTraceScope TimeScope("EvaluateWithSubstitution", [&] {
std::string Name;
@@ -17560,8 +17564,8 @@ bool Expr::EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,
Info.EvalStatus.HasSideEffects = false;
// Build fake call to Callee.
- CallStackFrame Frame(Info, Callee->getLocation(), Call.OrigCallee, ThisPtr, This,
- Call);
+ CallStackFrame Frame(Info, Callee->getLocation(), Call.OrigCallee, ThisPtr,
+ This, Call);
// FIXME: Missing ExprWithCleanups in enable_if conditions?
FullExpressionRAII Scope(Info);
return Evaluate(Value, Info, this) && Scope.destroy() &&
diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp
index a56b9026e2..f09fb695bf 100644
--- a/clang/lib/Sema/SemaExprObjC.cpp
+++ b/clang/lib/Sema/SemaExprObjC.cpp
@@ -2708,7 +2708,8 @@ ExprResult SemaObjC::BuildClassMessage(
// Check any arg-dependent diagnose_if conditions;
if (Method)
- SemaRef.diagnoseArgDependentDiagnoseIfAttrs(Method, nullptr, ArgsIn, RBracLoc);
+ SemaRef.diagnoseArgDependentDiagnoseIfAttrs(Method, nullptr, ArgsIn,
+ RBracLoc);
// Warn about explicit call of +initialize on its own class. But not on 'super'.
if (Method && Method->getMethodFamily() == OMF_initialize) {
@@ -3245,7 +3246,8 @@ ExprResult SemaObjC::BuildInstanceMessage(
// Check any arg-dependent diagnose_if conditions;
if (Method)
- SemaRef.diagnoseArgDependentDiagnoseIfAttrs(Method, nullptr, ArgsIn, RBracLoc);
+ SemaRef.diagnoseArgDependentDiagnoseIfAttrs(Method, nullptr, ArgsIn,
+ RBracLoc);
// In ARC, forbid the user from sending messages to
// retain/release/autorelease/dealloc/retainCount explicitly.
``````````
</details>
https://github.com/llvm/llvm-project/pull/115056
More information about the cfe-commits
mailing list