[PATCH] D91348: [OpenCL] Warn about side effects for unevaluated vec_step arg
Sven van Haastregt via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 13 01:49:11 PST 2020
svenvh updated this revision to Diff 305058.
svenvh added a comment.
Add test case for OpenCL.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D91348/new/
https://reviews.llvm.org/D91348
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaOpenCL/vec_step.cl
Index: clang/test/SemaOpenCL/vec_step.cl
===================================================================
--- clang/test/SemaOpenCL/vec_step.cl
+++ clang/test/SemaOpenCL/vec_step.cl
@@ -29,4 +29,6 @@
int res13 = vec_step(*incomplete1); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private struct S' invalid}}
int res14 = vec_step(int16*); // expected-error {{'vec_step' requires built-in scalar or vector type, '__private int16 *' invalid}}
int res15 = vec_step(void(void)); // expected-error {{'vec_step' requires built-in scalar or vector type, 'void (void)' invalid}}
+
+ int res_no_effect = vec_step(auto3++); // expected-warning {{expression with side effects has no effect in an unevaluated context}}
}
Index: clang/test/SemaCXX/coroutines.cpp
===================================================================
--- clang/test/SemaCXX/coroutines.cpp
+++ clang/test/SemaCXX/coroutines.cpp
@@ -328,6 +328,7 @@
// expected-warning at -1 {{declaration does not declare anything}}
sizeof(co_await a); // expected-error {{'co_await' cannot be used in an unevaluated context}}
// expected-error at -1 {{invalid application of 'sizeof' to an incomplete type 'void'}}
+ // expected-warning at -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 at -1 {{expression with side effects has no effect in an unevaluated context}}
// expected-warning at -2 {{expression result unused}}
@@ -335,6 +336,7 @@
// expected-warning at -1 {{declaration does not declare anything}}
sizeof(co_yield 2); // expected-error {{'co_yield' cannot be used in an unevaluated context}}
// expected-error at -1 {{invalid application of 'sizeof' to an incomplete type 'void'}}
+ // expected-warning at -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 at -1 {{expression with side effects has no effect in an unevaluated context}}
// expected-warning at -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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91348.305058.patch
Type: text/x-patch
Size: 3982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201113/ba3e5487/attachment-0001.bin>
More information about the cfe-commits
mailing list