nlewycky created this revision.
Remove clang::Sema::CheckForIntOverflow(E) by calling into
E->EvaluateForOverflow instead. CheckForIntOverflow implemented a whitelist of
top-level expressions to check, currently BinaryOperator and InitListExpr.
Two changes are made to avoid regression with the existing test suite.
test/SemaCXX/eval-sizeof-dependent-type.cpp has an example of a value-dependent
InitListExpr. Handle value-dependent initializers in init list exprs.
test/Sema/integer-overflow.c tests that initializers are checked for overflow,
which was conditionally disabled for performance. Allow checking for overflow
of init list exprs in the performance check.
https://reviews.llvm.org/D32412
Files:
lib/AST/ExprConstant.cpp
lib/Sema/SemaChecking.cpp
test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
test/OpenMP/distribute_simd_aligned_messages.cpp
test/OpenMP/for_simd_aligned_messages.cpp
test/OpenMP/parallel_for_simd_aligned_messages.cpp
test/OpenMP/simd_aligned_messages.cpp
test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
test/OpenMP/target_simd_aligned_messages.cpp
test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
test/OpenMP/taskloop_simd_aligned_messages.cpp
test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
test/OpenMP/teams_distribute_simd_aligned_messages.cpp
Index: test/OpenMP/teams_distribute_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/teams_distribute_simd_aligned_messages.cpp
+++ test/OpenMP/teams_distribute_simd_aligned_messages.cpp
@@ -123,9 +123,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target
Index: test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -123,9 +123,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target
Index: test/OpenMP/taskloop_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/taskloop_simd_aligned_messages.cpp
+++ test/OpenMP/taskloop_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp taskloop simd aligned // expected-error {{expected '(' after 'aligned'}}
for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
+++ test/OpenMP/target_teams_distribute_simd_aligned_messages.cpp
@@ -110,9 +110,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target teams distribute simd aligned // expected-error {{expected '(' after 'aligned'}}
Index: test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/target_teams_distribute_parallel_for_simd_aligned_messages.cpp
@@ -110,9 +110,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target teams distribute parallel for simd aligned // expected-error {{expected '(' after 'aligned'}}
Index: test/OpenMP/target_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/target_simd_aligned_messages.cpp
+++ test/OpenMP/target_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target simd aligned // expected-error {{expected '(' after 'aligned'}}
for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/target_parallel_for_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target parallel for simd aligned // expected-error {{expected '(' after 'aligned'}}
for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/simd_aligned_messages.cpp
+++ test/OpenMP/simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp simd aligned // expected-error {{expected '(' after 'aligned'}}
for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/parallel_for_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/parallel_for_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp parallel for simd aligned // expected-error {{expected '(' after 'aligned'}}
for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/for_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/for_simd_aligned_messages.cpp
+++ test/OpenMP/for_simd_aligned_messages.cpp
@@ -107,9 +107,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp for simd aligned // expected-error {{expected '(' after 'aligned'}}
for (I k = 0; k < argc; ++k) ++k;
Index: test/OpenMP/distribute_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/distribute_simd_aligned_messages.cpp
+++ test/OpenMP/distribute_simd_aligned_messages.cpp
@@ -134,9 +134,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target
Index: test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
===================================================================
--- test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
+++ test/OpenMP/distribute_parallel_for_simd_aligned_messages.cpp
@@ -134,9 +134,8 @@
template<class I, class C> int foomain(I argc, C **argv) {
I e(argc);
I g(argc);
- int i; // expected-note {{declared here}} expected-note {{'i' defined here}}
- // expected-note@+2 {{declared here}}
- // expected-note@+1 {{reference to 'i' is not a constant expression}}
+ int i; // expected-note {{'i' defined here}}
+ // expected-note@+1 {{declared here}}
int &j = i;
#pragma omp target
Index: lib/Sema/SemaChecking.cpp
===================================================================
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -10386,7 +10386,7 @@
if (!E->isInstantiationDependent())
CheckUnsequencedOperations(E);
if (!IsConstexpr && !E->isValueDependent())
- CheckForIntOverflow(E);
+ E->EvaluateForOverflow(Context);
DiagnoseMisalignedMembers();
}
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -6203,6 +6203,10 @@
// the initializer list.
ImplicitValueInitExpr VIE(HaveInit ? Info.Ctx.IntTy : Field->getType());
const Expr *Init = HaveInit ? E->getInit(ElementNo++) : &VIE;
+ if (Init->isValueDependent()) {
+ Success = false;
+ continue;
+ }
// Temporarily override This, in case there's a CXXDefaultInitExpr in here.
ThisOverrideRAII ThisOverride(*Info.CurrentCall, &This,
@@ -9913,7 +9917,8 @@
}
static bool FastEvaluateAsRValue(const Expr *Exp, Expr::EvalResult &Result,
- const ASTContext &Ctx, bool &IsConst) {
+ const ASTContext &Ctx, bool &IsConst,
+ bool IsCheckingForOverflow) {
// Fast-path evaluations of integer literals, since we sometimes see files
// containing vast quantities of these.
if (const IntegerLiteral *L = dyn_cast<IntegerLiteral>(Exp)) {
@@ -9934,7 +9939,7 @@
// performance problems. Only do so in C++11 for now.
if (Exp->isRValue() && (Exp->getType()->isArrayType() ||
Exp->getType()->isRecordType()) &&
- !Ctx.getLangOpts().CPlusPlus11) {
+ !Ctx.getLangOpts().CPlusPlus11 && !IsCheckingForOverflow) {
IsConst = false;
return true;
}
@@ -9949,7 +9954,7 @@
/// will be applied to the result.
bool Expr::EvaluateAsRValue(EvalResult &Result, const ASTContext &Ctx) const {
bool IsConst;
- if (FastEvaluateAsRValue(this, Result, Ctx, IsConst))
+ if (FastEvaluateAsRValue(this, Result, Ctx, IsConst, false))
return IsConst;
EvalInfo Info(Ctx, Result, EvalInfo::EM_IgnoreSideEffects);
@@ -10074,7 +10079,7 @@
void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
bool IsConst;
EvalResult EvalResult;
- if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) {
+ if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst, true)) {
EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);
(void)::EvaluateAsRValue(Info, this, EvalResult.Val);
}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits