Author: Aaron Ballman Date: 2022-05-05T12:12:30-04:00 New Revision: 199dfb4d0cca0aaa217e79bd2371f96f6336bbc5
URL: https://github.com/llvm/llvm-project/commit/199dfb4d0cca0aaa217e79bd2371f96f6336bbc5 DIFF: https://github.com/llvm/llvm-project/commit/199dfb4d0cca0aaa217e79bd2371f96f6336bbc5.diff LOG: Silence a false positive about an unevaluated expr w/side effects If the operand to `sizeof` is an expression of VLA type, the operand is still evaluated, so we should not issue a diagnostic about ignoring the side effects in this case, as they're not actually ignored. Fixes #48010 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaExpr.cpp clang/test/Sema/warn-unused-value.c Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 4ddf1c6eb5382..f5e9cd941e091 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -139,6 +139,9 @@ Bug Fixes - Fixed a crash when the ``__bf16`` type is used such that its size or alignment is calculated on a target which does not support that type. This fixes `Issue 50171 <https://github.com/llvm/llvm-project/issues/50171>`_. +- Fixed a false positive diagnostic about an unevaluated expression having no + side effects when the expression is of VLA type and is an operand of the + ``sizeof`` operator. Fixes `Issue 48010 <https://github.com/llvm/llvm-project/issues/48010>`_. Improvements to Clang's diagnostics ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 058967b656bc9..6b86c02c60913 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4245,6 +4245,7 @@ bool Sema::CheckUnaryExprOrTypeTraitOperand(Expr *E, // FIXME: Should we consider instantiation-dependent operands to 'alignof'? if (IsUnevaluatedOperand && !inTemplateInstantiation() && !E->isInstantiationDependent() && + !E->getType()->isVariableArrayType() && E->HasSideEffects(Context, false)) Diag(E->getExprLoc(), diag::warn_side_effects_unevaluated_context); diff --git a/clang/test/Sema/warn-unused-value.c b/clang/test/Sema/warn-unused-value.c index cc54ad61f0b93..9e353ef1d14c4 100644 --- a/clang/test/Sema/warn-unused-value.c +++ b/clang/test/Sema/warn-unused-value.c @@ -99,11 +99,15 @@ void unevaluated_operands(void) { (void)_Generic(val++, default : 0); // expected-warning {{expression with side effects has no effect in an unevaluated context}} (void)_Alignof(val++); // expected-warning {{expression with side effects has no effect in an unevaluated context}} expected-warning {{'_Alignof' applied to an expression is a GNU extension}} - // VLAs can have side effects so long as it's part of the type and not - // an expression. + // VLAs can have side effects so long as it's part of the type and not an + // expression, except for sizeof() where it can also have a side effect if + // the operand is of VLA type. (void)sizeof(int[++val]); // Ok (void)_Alignof(int[++val]); // Ok + int GH48010[val]; + (void)sizeof(*(val = 1, &GH48010)); // Ok + // Side effects as part of macro expansion are ok. GenTest(val++); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits