svenvh created this revision. svenvh added a reviewer: Anastasia. Herald added a subscriber: yaxunl. Herald added a project: clang. svenvh requested review of this revision.
The argument to the `vec_step` builtin is not evaluated. Hoist the diagnostic for this in `Sema::CheckUnaryExprOrTypeTraitOperand` such that it comes before `Sema::CheckVecStepTraitOperandType`. A minor side-effect of this change is that it also produces the warning for `co_await` and `co_yield` now. Associated spec clarification: https://github.com/KhronosGroup/OpenCL-Docs/pull/481 Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D91348 Files: clang/lib/Sema/SemaExpr.cpp clang/test/SemaCXX/coroutines.cpp Index: clang/test/SemaCXX/coroutines.cpp =================================================================== --- clang/test/SemaCXX/coroutines.cpp +++ clang/test/SemaCXX/coroutines.cpp @@ -328,6 +328,7 @@ // expected-warning@-1 {{declaration does not declare anything}} sizeof(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}} // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}} + // expected-warning@-2 {{expression with side effects has no effect in an unevaluated context}} typeid(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}} // expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}} // expected-warning@-2 {{expression result unused}} @@ -335,6 +336,7 @@ // expected-warning@-1 {{declaration does not declare anything}} sizeof(co_yield 2); // expected-error {{'co_yield' cannot be used in an unevaluated context}} // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}} + // expected-warning@-2 {{expression with side effects has no effect in an unevaluated context}} typeid(co_yield 3); // expected-error {{'co_yield' cannot be used in an unevaluated context}} // expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}} // expected-warning@-2 {{expression result unused}} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -4027,7 +4027,7 @@ bool IsUnevaluatedOperand = (ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf || - ExprKind == UETT_PreferredAlignOf); + ExprKind == UETT_PreferredAlignOf || ExprKind == UETT_VecStep); if (IsUnevaluatedOperand) { ExprResult Result = CheckUnevaluatedOperand(E); if (Result.isInvalid()) @@ -4035,6 +4035,12 @@ E = Result.get(); } + // The operand for sizeof and alignof is in an unevaluated expression context, + // so side effects could result in unintended consequences. + if (IsUnevaluatedOperand && !inTemplateInstantiation() && + E->HasSideEffects(Context, false)) + Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); + if (ExprKind == UETT_VecStep) return CheckVecStepTraitOperandType(*this, ExprTy, E->getExprLoc(), E->getSourceRange()); @@ -4071,12 +4077,6 @@ return true; } - // The operand for sizeof and alignof is in an unevaluated expression context, - // so side effects could result in unintended consequences. - if (IsUnevaluatedOperand && !inTemplateInstantiation() && - E->HasSideEffects(Context, false)) - Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); - if (CheckObjCTraitOperandConstraints(*this, ExprTy, E->getExprLoc(), E->getSourceRange(), ExprKind)) return true;
Index: clang/test/SemaCXX/coroutines.cpp =================================================================== --- clang/test/SemaCXX/coroutines.cpp +++ clang/test/SemaCXX/coroutines.cpp @@ -328,6 +328,7 @@ // expected-warning@-1 {{declaration does not declare anything}} sizeof(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}} // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}} + // expected-warning@-2 {{expression with side effects has no effect in an unevaluated context}} typeid(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}} // expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}} // expected-warning@-2 {{expression result unused}} @@ -335,6 +336,7 @@ // expected-warning@-1 {{declaration does not declare anything}} sizeof(co_yield 2); // expected-error {{'co_yield' cannot be used in an unevaluated context}} // expected-error@-1 {{invalid application of 'sizeof' to an incomplete type 'void'}} + // expected-warning@-2 {{expression with side effects has no effect in an unevaluated context}} typeid(co_yield 3); // expected-error {{'co_yield' cannot be used in an unevaluated context}} // expected-warning@-1 {{expression with side effects has no effect in an unevaluated context}} // expected-warning@-2 {{expression result unused}} Index: clang/lib/Sema/SemaExpr.cpp =================================================================== --- clang/lib/Sema/SemaExpr.cpp +++ clang/lib/Sema/SemaExpr.cpp @@ -4027,7 +4027,7 @@ bool IsUnevaluatedOperand = (ExprKind == UETT_SizeOf || ExprKind == UETT_AlignOf || - ExprKind == UETT_PreferredAlignOf); + ExprKind == UETT_PreferredAlignOf || ExprKind == UETT_VecStep); if (IsUnevaluatedOperand) { ExprResult Result = CheckUnevaluatedOperand(E); if (Result.isInvalid()) @@ -4035,6 +4035,12 @@ E = Result.get(); } + // The operand for sizeof and alignof is in an unevaluated expression context, + // so side effects could result in unintended consequences. + if (IsUnevaluatedOperand && !inTemplateInstantiation() && + E->HasSideEffects(Context, false)) + Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); + if (ExprKind == UETT_VecStep) return CheckVecStepTraitOperandType(*this, ExprTy, E->getExprLoc(), E->getSourceRange()); @@ -4071,12 +4077,6 @@ return true; } - // The operand for sizeof and alignof is in an unevaluated expression context, - // so side effects could result in unintended consequences. - if (IsUnevaluatedOperand && !inTemplateInstantiation() && - E->HasSideEffects(Context, false)) - Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); - if (CheckObjCTraitOperandConstraints(*this, ExprTy, E->getExprLoc(), E->getSourceRange(), ExprKind)) return true;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits