Skip to content

Commit 3234887

Browse files
committed
[APSInt][OpenMP] Fix isNegative, etc. for unsigned types
Without this patch, APSInt inherits APInt::isNegative, which merely checks the sign bit without regard to whether the type is actually signed. isNonNegative and isStrictlyPositive call isNegative and so are also affected. This patch adjusts APSInt to override isNegative, isNonNegative, and isStrictlyPositive with implementations that consider whether the type is signed. A large set of Clang OpenMP tests are affected. Without this patch, these tests assume that `true` is not a valid argument for clauses like `collapse`. Indeed, `true` fails APInt::isStrictlyPositive but not APSInt::isStrictlyPositive. This patch adjusts those tests to assume `true` should be accepted. This patch also adds tests revealing various other similar fixes due to APSInt::isNegative calls in Clang's ExprConstant.cpp and SemaExpr.cpp: `++` and `--` overflow in `constexpr`, evaluated object size based on `alloc_size`, `<<` and `>>` shift count validation, and OpenMP array section validation. Reviewed By: lebedev.ri, ABataev, hfinkel Differential Revision: https://reviews.llvm.org/D59712 llvm-svn: 359012
1 parent bdb864a commit 3234887

File tree

64 files changed

+359
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+359
-124
lines changed

clang/test/CodeGen/alloc-size.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,12 @@ void test12() {
357357
// CHECK: store i32 -1
358358
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(-2, 1), 0);
359359
}
360+
361+
void *alloc_uchar(unsigned char) __attribute__((alloc_size(1)));
362+
363+
// CHECK-LABEL: @test13
364+
void test13() {
365+
// If 128 were incorrectly seen as negative, the result would become -1.
366+
// CHECK: store i32 128,
367+
gi = OBJECT_SIZE_BUILTIN(alloc_uchar(128), 0);
368+
}

clang/test/OpenMP/distribute_collapse_messages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
4242
// expected-note@+5 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
4343
#endif
4444
// expected-error@+3 2 {{directive '#pragma omp distribute' cannot contain more than one 'collapse' clause}}
45-
// expected-error@+2 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
45+
// expected-error@+2 {{argument to 'collapse' clause must be a strictly positive integer value}}
4646
// expected-error@+1 2 {{expression is not an integral constant expression}}
4747
#pragma omp distribute collapse (foobool(argc)), collapse (true), collapse (-5)
4848
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST];
@@ -85,7 +85,7 @@ int main(int argc, char **argv) {
8585
#endif
8686
// expected-error@+3 {{expression is not an integral constant expression}}
8787
// expected-error@+2 2 {{directive '#pragma omp distribute' cannot contain more than one 'collapse' clause}}
88-
// expected-error@+1 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
88+
// expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
8989
#pragma omp distribute collapse (foobool(argc)), collapse (true), collapse (-5)
9090
for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
9191
#pragma omp distribute collapse (S1) // expected-error {{'S1' does not refer to a value}}

clang/test/OpenMP/distribute_parallel_for_collapse_messages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
5353
#pragma omp distribute parallel for collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}}
5454
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp distribute parallel for', but found only 1}}
5555
// expected-error@+8 2 {{directive '#pragma omp distribute parallel for' cannot contain more than one 'collapse' clause}}
56-
// expected-error@+7 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
56+
// expected-error@+7 {{argument to 'collapse' clause must be a strictly positive integer value}}
5757
// expected-error@+6 2 {{expression is not an integral constant expression}}
5858
#if __cplusplus >= 201103L
5959
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
124124
// expected-note@+6{{non-constexpr function 'foobool' cannot be used in a constant expression}}
125125
#endif
126126
// expected-error@+4 2 {{directive '#pragma omp distribute parallel for' cannot contain more than one 'collapse' clause}}
127-
// expected-error@+3 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
127+
// expected-error@+3 {{argument to 'collapse' clause must be a strictly positive integer value}}
128128
#pragma omp target
129129
#pragma omp teams
130130
#pragma omp distribute parallel for collapse (foobool(argc)), collapse (true), collapse (-5)

clang/test/OpenMP/distribute_parallel_for_simd_collapse_messages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
5353
#pragma omp distribute parallel for simd collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}}
5454
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp distribute parallel for simd', but found only 1}}
5555
// expected-error@+8 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'collapse' clause}}
56-
// expected-error@+7 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
56+
// expected-error@+7 {{argument to 'collapse' clause must be a strictly positive integer value}}
5757
// expected-error@+6 2 {{expression is not an integral constant expression}}
5858
#if __cplusplus >= 201103L
5959
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
124124
// expected-note@+6{{non-constexpr function 'foobool' cannot be used in a constant expression}}
125125
#endif
126126
// expected-error@+4 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'collapse' clause}}
127-
// expected-error@+3 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
127+
// expected-error@+3 {{argument to 'collapse' clause must be a strictly positive integer value}}
128128
#pragma omp target
129129
#pragma omp teams
130130
#pragma omp distribute parallel for simd collapse (foobool(argc)), collapse (true), collapse (-5)

clang/test/OpenMP/distribute_parallel_for_simd_safelen_messages.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
6363
argv[0][i] = argv[0][i] - argv[0][i-ST];
6464

6565
#if __cplusplus >= 201103L
66-
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
66+
// expected-note@+7 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
6767
#endif
6868
#pragma omp target
6969
#pragma omp teams
70-
#pragma omp distribute parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5) // expected-error 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'safelen' clause}} expected-error 2 {{argument to 'safelen' clause must be a strictly positive integer value}} expected-error 2 {{expression is not an integral constant expression}}
70+
// expected-error@+3 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'safelen' clause}}
71+
// expected-error@+2 {{argument to 'safelen' clause must be a strictly positive integer value}}
72+
// expected-error@+1 2 {{expression is not an integral constant expression}}
73+
#pragma omp distribute parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5)
7174
for (int i = ST; i < N; i++)
7275
argv[0][i] = argv[0][i] - argv[0][i-ST];
7376

@@ -144,11 +147,14 @@ int main(int argc, char **argv) {
144147
argv[0][i] = argv[0][i] - argv[0][i-4];
145148

146149
#if __cplusplus >= 201103L
147-
// expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
150+
// expected-note@+7 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
148151
#endif
149152
#pragma omp target
150153
#pragma omp teams
151-
#pragma omp parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5) // expected-error 2 {{argument to 'safelen' clause must be a strictly positive integer value}} expected-error 2 {{directive '#pragma omp parallel for simd' cannot contain more than one 'safelen' clause}} expected-error {{expression is not an integral constant expression}}
154+
// expected-error@+3 {{argument to 'safelen' clause must be a strictly positive integer value}}
155+
// expected-error@+2 2 {{directive '#pragma omp parallel for simd' cannot contain more than one 'safelen' clause}}
156+
// expected-error@+1 {{expression is not an integral constant expression}}
157+
#pragma omp parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5)
152158
for (int i = 4; i < 12; i++)
153159
argv[0][i] = argv[0][i] - argv[0][i-4];
154160

clang/test/OpenMP/distribute_parallel_for_simd_simdlen_messages.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
6666
argv[0][i] = argv[0][i] - argv[0][i-ST];
6767

6868
#if __cplusplus >= 201103L
69-
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
69+
// expected-note@+7 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
7070
#endif
7171
#pragma omp target
7272
#pragma omp teams
73-
#pragma omp distribute parallel for simd simdlen (foobool(argc)), simdlen (true), simdlen (-5) // expected-error 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'simdlen' clause}} expected-error 2 {{argument to 'simdlen' clause must be a strictly positive integer value}} expected-error 2 {{expression is not an integral constant expression}}
73+
// expected-error@+3 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'simdlen' clause}}
74+
// expected-error@+2 {{argument to 'simdlen' clause must be a strictly positive integer value}}
75+
// expected-error@+1 2 {{expression is not an integral constant expression}}
76+
#pragma omp distribute parallel for simd simdlen (foobool(argc)), simdlen (true), simdlen (-5)
7477
for (int i = ST; i < N; i++)
7578
argv[0][i] = argv[0][i] - argv[0][i-ST];
7679

@@ -148,11 +151,14 @@ int main(int argc, char **argv) {
148151

149152

150153
#if __cplusplus >= 201103L
151-
// expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
154+
// expected-note@+7 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
152155
#endif
153156
#pragma omp target
154157
#pragma omp teams
155-
#pragma omp distribute parallel for simd simdlen (foobool(argc)), simdlen (true), simdlen (-5) // expected-error {{expression is not an integral constant expression}} expected-error 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'simdlen' clause}} expected-error 2 {{argument to 'simdlen' clause must be a strictly positive integer value}}
158+
// expected-error@+3 {{expression is not an integral constant expression}}
159+
// expected-error@+2 2 {{directive '#pragma omp distribute parallel for simd' cannot contain more than one 'simdlen' clause}}
160+
// expected-error@+1 {{argument to 'simdlen' clause must be a strictly positive integer value}}
161+
#pragma omp distribute parallel for simd simdlen (foobool(argc)), simdlen (true), simdlen (-5)
156162
for (int i = 4; i < 12; i++)
157163
argv[0][i] = argv[0][i] - argv[0][i-4];
158164

clang/test/OpenMP/distribute_simd_collapse_messages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
5353
#pragma omp distribute simd collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}}
5454
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp distribute simd', but found only 1}}
5555
// expected-error@+8 2 {{directive '#pragma omp distribute simd' cannot contain more than one 'collapse' clause}}
56-
// expected-error@+7 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
56+
// expected-error@+7 {{argument to 'collapse' clause must be a strictly positive integer value}}
5757
// expected-error@+6 2 {{expression is not an integral constant expression}}
5858
#if __cplusplus >= 201103L
5959
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
124124
// expected-note@+6{{non-constexpr function 'foobool' cannot be used in a constant expression}}
125125
#endif
126126
// expected-error@+4 2 {{directive '#pragma omp distribute simd' cannot contain more than one 'collapse' clause}}
127-
// expected-error@+3 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
127+
// expected-error@+3 {{argument to 'collapse' clause must be a strictly positive integer value}}
128128
#pragma omp target
129129
#pragma omp teams
130130
#pragma omp distribute simd collapse (foobool(argc)), collapse (true), collapse (-5)

clang/test/OpenMP/distribute_simd_safelen_messages.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
6363
argv[0][i] = argv[0][i] - argv[0][i-ST];
6464

6565
#if __cplusplus >= 201103L
66-
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
66+
// expected-note@+7 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
6767
#endif
6868
#pragma omp target
6969
#pragma omp teams
70-
#pragma omp distribute simd safelen (foobool(argc)), safelen (true), safelen (-5) // expected-error 2 {{directive '#pragma omp distribute simd' cannot contain more than one 'safelen' clause}} expected-error 2 {{argument to 'safelen' clause must be a strictly positive integer value}} expected-error 2 {{expression is not an integral constant expression}}
70+
// expected-error@+3 2 {{directive '#pragma omp distribute simd' cannot contain more than one 'safelen' clause}}
71+
// expected-error@+2 {{argument to 'safelen' clause must be a strictly positive integer value}}
72+
// expected-error@+1 2 {{expression is not an integral constant expression}}
73+
#pragma omp distribute simd safelen (foobool(argc)), safelen (true), safelen (-5)
7174
for (int i = ST; i < N; i++)
7275
argv[0][i] = argv[0][i] - argv[0][i-ST];
7376

@@ -144,11 +147,14 @@ int main(int argc, char **argv) {
144147
argv[0][i] = argv[0][i] - argv[0][i-4];
145148

146149
#if __cplusplus >= 201103L
147-
// expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
150+
// expected-note@+7 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
148151
#endif
149152
#pragma omp target
150153
#pragma omp teams
151-
#pragma omp parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5) // expected-error 2 {{argument to 'safelen' clause must be a strictly positive integer value}} expected-error 2 {{directive '#pragma omp parallel for simd' cannot contain more than one 'safelen' clause}} expected-error {{expression is not an integral constant expression}}
154+
// expected-error@+3 {{argument to 'safelen' clause must be a strictly positive integer value}}
155+
// expected-error@+2 2 {{directive '#pragma omp parallel for simd' cannot contain more than one 'safelen' clause}}
156+
// expected-error@+1 {{expression is not an integral constant expression}}
157+
#pragma omp parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5)
152158
for (int i = 4; i < 12; i++)
153159
argv[0][i] = argv[0][i] - argv[0][i-4];
154160

clang/test/OpenMP/distribute_simd_simdlen_messages.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,14 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
6363
argv[0][i] = argv[0][i] - argv[0][i-ST];
6464

6565
#if __cplusplus >= 201103L
66-
// expected-note@+4 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
66+
// expected-note@+7 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
6767
#endif
6868
#pragma omp target
6969
#pragma omp teams
70-
#pragma omp distribute simd safelen (foobool(argc)), safelen (true), safelen (-5) // expected-error 2 {{directive '#pragma omp distribute simd' cannot contain more than one 'safelen' clause}} expected-error 2 {{argument to 'safelen' clause must be a strictly positive integer value}} expected-error 2 {{expression is not an integral constant expression}}
70+
// expected-error@+3 2 {{directive '#pragma omp distribute simd' cannot contain more than one 'safelen' clause}}
71+
// expected-error@+2 {{argument to 'safelen' clause must be a strictly positive integer value}}
72+
// expected-error@+1 2 {{expression is not an integral constant expression}}
73+
#pragma omp distribute simd safelen (foobool(argc)), safelen (true), safelen (-5)
7174
for (int i = ST; i < N; i++)
7275
argv[0][i] = argv[0][i] - argv[0][i-ST];
7376

@@ -144,11 +147,14 @@ int main(int argc, char **argv) {
144147
argv[0][i] = argv[0][i] - argv[0][i-4];
145148

146149
#if __cplusplus >= 201103L
147-
// expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
150+
// expected-note@+7 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
148151
#endif
149152
#pragma omp target
150153
#pragma omp teams
151-
#pragma omp parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5) // expected-error 2 {{argument to 'safelen' clause must be a strictly positive integer value}} expected-error 2 {{directive '#pragma omp parallel for simd' cannot contain more than one 'safelen' clause}} expected-error {{expression is not an integral constant expression}}
154+
// expected-error@+3 {{argument to 'safelen' clause must be a strictly positive integer value}}
155+
// expected-error@+2 2 {{directive '#pragma omp parallel for simd' cannot contain more than one 'safelen' clause}}
156+
// expected-error@+1 {{expression is not an integral constant expression}}
157+
#pragma omp parallel for simd safelen (foobool(argc)), safelen (true), safelen (-5)
152158
for (int i = 4; i < 12; i++)
153159
argv[0][i] = argv[0][i] - argv[0][i-4];
154160

clang/test/OpenMP/for_collapse_messages.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}}
3939
#pragma omp for collapse ((ST > 0) ? 1 + ST : 2) // expected-note 2 {{as specified in 'collapse' clause}}
4040
for (int i = ST; i < N; i++) argv[0][i] = argv[0][i] - argv[0][i-ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp for', but found only 1}}
4141
// expected-error@+6 2 {{directive '#pragma omp for' cannot contain more than one 'collapse' clause}}
42-
// expected-error@+5 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
42+
// expected-error@+5 {{argument to 'collapse' clause must be a strictly positive integer value}}
4343
// expected-error@+4 2 {{expression is not an integral constant expression}}
4444
#if __cplusplus >= 201103L
4545
// expected-note@+2 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
@@ -86,7 +86,7 @@ int main(int argc, char **argv) {
8686
// expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
8787
#endif
8888
// expected-error@+2 2 {{directive '#pragma omp for' cannot contain more than one 'collapse' clause}}
89-
// expected-error@+1 2 {{argument to 'collapse' clause must be a strictly positive integer value}}
89+
// expected-error@+1 {{argument to 'collapse' clause must be a strictly positive integer value}}
9090
#pragma omp for collapse (foobool(argc)), collapse (true), collapse (-5)
9191
for (int i = 4; i < 12; i++) argv[0][i] = argv[0][i] - argv[0][i-4];
9292
#pragma omp for collapse (S1) // expected-error {{'S1' does not refer to a value}}

clang/test/OpenMP/for_ordered_clause.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ T tmain(T argc, S **argv) { //expected-note 2 {{declared here}
4747
for (int i = ST; i < N; i++)
4848
argv[0][i] = argv[0][i] - argv[0][i - ST]; // expected-error 2 {{expected 2 for loops after '#pragma omp for', but found only 1}}
4949
// expected-error@+6 2 {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
50-
// expected-error@+5 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
50+
// expected-error@+5 {{argument to 'ordered' clause must be a strictly positive integer value}}
5151
// expected-error@+4 2 {{expression is not an integral constant expression}}
5252
#if __cplusplus >= 201103L
5353
// expected-note@+2 2 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
@@ -113,7 +113,7 @@ int main(int argc, char **argv) {
113113
// expected-note@+4 {{non-constexpr function 'foobool' cannot be used in a constant expression}}
114114
#endif
115115
// expected-error@+2 2 {{directive '#pragma omp for' cannot contain more than one 'ordered' clause}}
116-
// expected-error@+1 2 {{argument to 'ordered' clause must be a strictly positive integer value}}
116+
// expected-error@+1 {{argument to 'ordered' clause must be a strictly positive integer value}}
117117
#pragma omp for ordered(foobool(argc)), ordered(true), ordered(-5)
118118
for (int i = 4; i < 12; i++)
119119
argv[0][i] = argv[0][i] - argv[0][i - 4];

0 commit comments

Comments
 (0)