]> granicus.if.org Git - clang/commit
[clang] perform semantic checking in constant context
authorGauthier Harnisch <tyker1@outlook.com>
Sat, 15 Jun 2019 08:32:56 +0000 (08:32 +0000)
committerGauthier Harnisch <tyker1@outlook.com>
Sat, 15 Jun 2019 08:32:56 +0000 (08:32 +0000)
commitd999cf60d597b73f414eec7e9240250e1fae6acd
treeb0e2ec84b5f28699d7c9aeb24389c8a5c345a2e8
parent6d054f34297ca09b81757cfad86cd8aab45aac9f
[clang] perform semantic checking in constant context

Summary:
Since the addition of __builtin_is_constant_evaluated the result of an expression can change based on whether it is evaluated in constant context. a lot of semantic checking performs evaluations with out specifying context. which can lead to wrong diagnostics.
for example:
```
constexpr int i0 = (long long)__builtin_is_constant_evaluated() * (1ll << 33); //#1
constexpr int i1 = (long long)!__builtin_is_constant_evaluated() * (1ll << 33); //#2
```
before the patch, #2 was diagnosed incorrectly and #1 wasn't diagnosed.
after the patch #1 is diagnosed as it should and #2 isn't.

Changes:
 - add a flag to Sema to passe in constant context mode.
 - in SemaChecking.cpp calls to Expr::Evaluate* are now done in constant context when they should.
 - in SemaChecking.cpp diagnostics for UB are not checked for in constant context because an error will be emitted by the constant evaluator.
 - in SemaChecking.cpp diagnostics for construct that cannot appear in constant context are not checked for in constant context.
 - in SemaChecking.cpp diagnostics on constant expression are always emitted because constant expression are always evaluated.
 - semantic checking for initialization of constexpr variables is now done in constant context.
 - adapt test that were depending on warning changes.
 - add test.

Reviewers: rsmith

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D62009

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@363488 91177308-0d34-0410-b5e6-96231b3b80d8
include/clang/AST/Expr.h
include/clang/Basic/DiagnosticASTKinds.td
include/clang/Sema/Sema.h
lib/AST/ExprConstant.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaChecking.cpp
test/SemaCXX/attr-nonnull.cpp
test/SemaCXX/constant-expression-cxx11.cpp