[PATCH] D62009: [clang] perform semantic checking in constant context
Tyker via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 22 02:18:48 PDT 2019
Tyker updated this revision to Diff 200662.
Tyker added a comment.
most comments were fixed. but there is a few point on which the direction isn't clear.
> I think all of the new warnings in the test cases here are undesirable (they duplicate errors produced by the constant evaluator)
in the last revision `warn_impcast_integer_precision_constant` was always diagnosed in constant expression and diagnosed if reachable otherwise. this warning was responsible of all new warnings but isn't diagnosed by the constant evaluator. which is correct because AFAIK integral casts have implementation defined behavior and not undefined behavior.
> For code patterns that are suspicious but defined (eg, we think they might do something other than what the programmer intended), we should typically diagnose using Diag, regardless of whether they appear in a constant context.
this is not currently done even in non constant context. for example `warn_impcast_integer_precision_constant` is diagnosed via `DiagRuntimeBehavior`.
in this revision
constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); //#1
is diagnosed as it should by the reason it is diagnosed isn't correct. it is diagnosed only because `CheckCompletedExpr` doesn't push an `ExpressionEvaluationContextRecord` but just set isConstantEvaluatedOverride. so `DiagRuntimeBehavior` doesn't see the context as constant context. This means that other context that are correctly in constant context like:
case (long long)__builtin_is_constant_evaluated() * (1ll << 33):; //#1
will not be diagnosed even thought they probably should.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D62009/new/
https://reviews.llvm.org/D62009
Files:
clang/include/clang/AST/Expr.h
clang/include/clang/Basic/DiagnosticASTKinds.td
clang/include/clang/Basic/DiagnosticIDs.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ExprConstant.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/attr-nonnull.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62009.200662.patch
Type: text/x-patch
Size: 35491 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190522/4df60261/attachment-0001.bin>
More information about the cfe-commits
mailing list