c-parser.c (c_parser_omp_context_selector): Don't require score argument to fit into...
authorJakub Jelinek <jakub@redhat.com>
Thu, 14 Nov 2019 08:14:16 +0000 (09:14 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Thu, 14 Nov 2019 08:14:16 +0000 (09:14 +0100)
* c-parser.c (c_parser_omp_context_selector): Don't require score
argument to fit into shwi, just to be INTEGER_CST.  Diagnose
negative score.

* parser.c (cp_parser_omp_context_selector): Don't require score
argument to fit into shwi, just to be INTEGER_CST.  Diagnose
negative score.
* pt.c (tsubst_attribute): Likewise.

* c-c++-common/gomp/declare-variant-2.c: Add test for non-integral
score and for negative score.
* c-c++-common/gomp/declare-variant-3.c: Add test for zero score.
* g++.dg/gomp/declare-variant-8.C: Add test for negative and zero
scores.

From-SVN: r278204

gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/gomp/declare-variant-2.c
gcc/testsuite/c-c++-common/gomp/declare-variant-3.c
gcc/testsuite/g++.dg/gomp/declare-variant-8.C

index b60c6482993e56fedcdd4158194cc88576e0c318..c19cf2fae3292527253c71f1c8a1af6e43c552ea 100644 (file)
@@ -1,5 +1,9 @@
 2019-11-14  Jakub Jelinek  <jakub@redhat.com>
 
+       * c-parser.c (c_parser_omp_context_selector): Don't require score
+       argument to fit into shwi, just to be INTEGER_CST.  Diagnose
+       negative score.
+
        * c-parser.c (c_parser_omp_context_selector): Rename
        CTX_PROPERTY_IDLIST to CTX_PROPERTY_NAME_LIST, add CTX_PROPERTY_ID.
        Use CTX_PROPERTY_ID for atomic_default_mem_order, only allow a single
index 7219fc4f982b688882be56eaecb03c413bf61e4a..5e30a7f19168bb11f85b93dfee7ca7d6c23f7c01 100644 (file)
@@ -19823,9 +19823,12 @@ c_parser_omp_context_selector (c_parser *parser, tree set, tree parms)
                  mark_exp_read (score);
                  score = c_fully_fold (score, false, NULL);
                  if (!INTEGRAL_TYPE_P (TREE_TYPE (score))
-                     || !tree_fits_shwi_p (score))
+                     || TREE_CODE (score) != INTEGER_CST)
                    error_at (token->location, "score argument must be "
                              "constant integer expression");
+                 else if (tree_int_cst_sgn (score) < 0)
+                   error_at (token->location, "score argument must be "
+                             "non-negative");
                  else
                    properties = tree_cons (get_identifier (" score"),
                                            score, properties);
index ec053f3933f91fce1b200261aefc6e0d1579aef9..c836859a6f516b2a7584718ca3f8e35faf2c1bc5 100644 (file)
@@ -1,5 +1,10 @@
 2019-11-14  Jakub Jelinek  <jakub@redhat.com>
 
+       * parser.c (cp_parser_omp_context_selector): Don't require score
+       argument to fit into shwi, just to be INTEGER_CST.  Diagnose
+       negative score.
+       * pt.c (tsubst_attribute): Likewise.
+
        * parser.c (cp_parser_omp_context_selector): Rename
        CTX_PROPERTY_IDLIST to CTX_PROPERTY_NAME_LIST, add CTX_PROPERTY_ID.
        Use CTX_PROPERTY_ID for atomic_default_mem_order, only allow a single
index be29a2782c12a913a0b04a90ebea51bdb4708ab9..c473e7fd92f2e956d276788e330f14553e9ab6cc 100644 (file)
@@ -40565,11 +40565,16 @@ cp_parser_omp_context_selector (cp_parser *parser, tree set, bool has_parms_p)
                  if (score != error_mark_node)
                    {
                      score = fold_non_dependent_expr (score);
-                     if (!value_dependent_expression_p (score)
-                         && (!INTEGRAL_TYPE_P (TREE_TYPE (score))
-                             || !tree_fits_shwi_p (score)))
+                     if (value_dependent_expression_p (score))
+                       properties = tree_cons (get_identifier (" score"),
+                                               score, properties);
+                     else if (!INTEGRAL_TYPE_P (TREE_TYPE (score))
+                              || TREE_CODE (score) != INTEGER_CST)
                        error_at (token->location, "score argument must be "
                                  "constant integer expression");
+                     else if (tree_int_cst_sgn (score) < 0)
+                       error_at (token->location, "score argument must be "
+                                 "non-negative");
                      else
                        properties = tree_cons (get_identifier (" score"),
                                                score, properties);
index 307ae6ee1717154a1422194c4c88e28b2bdf9687..84db3f9c663683b9c637d88f00b9695401069358 100644 (file)
@@ -11172,7 +11172,9 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
                        v = tsubst_expr (v, args, complain, in_decl, true);
                        v = fold_non_dependent_expr (v);
                        if (!INTEGRAL_TYPE_P (TREE_TYPE (v))
-                           || !tree_fits_shwi_p (v))
+                           || (TREE_PURPOSE (t3) == score
+                               ? TREE_CODE (v) != INTEGER_CST
+                               : !tree_fits_shwi_p (v)))
                          {
                            location_t loc
                              = cp_expr_loc_or_loc (TREE_VALUE (t3),
@@ -11189,6 +11191,16 @@ tsubst_attribute (tree t, tree *decl_p, tree args,
                                             "integer expression");
                            return NULL_TREE;
                          }
+                       else if (TREE_PURPOSE (t3) == score
+                                && tree_int_cst_sgn (v) < 0)
+                         {
+                           location_t loc
+                             = cp_expr_loc_or_loc (TREE_VALUE (t3),
+                                                   match_loc);
+                           error_at (loc, "score argument must be "
+                                          "non-negative");
+                           return NULL_TREE;
+                         }
                        TREE_VALUE (t3) = v;
                      }
                }
index fa87ca7c3c73a2cc91b108476d0bddde5f175c9f..b94cac2b50bf04531229be54e72c9a585c60145d 100644 (file)
@@ -1,5 +1,11 @@
 2019-11-14  Jakub Jelinek  <jakub@redhat.com>
 
+       * c-c++-common/gomp/declare-variant-2.c: Add test for non-integral
+       score and for negative score.
+       * c-c++-common/gomp/declare-variant-3.c: Add test for zero score.
+       * g++.dg/gomp/declare-variant-8.C: Add test for negative and zero
+       scores.
+
        * c-c++-common/gomp/declare-variant-3.c: Add testcase for vendor nvidia.
 
        * c-c++-common/gomp/declare-variant-2.c: Adjust expected diagnostics,
index 949a239aa91fd4d308eee96ba354bc364a875a6c..5554059bd60c100ce7818e1217f7af609bbc6ced 100644 (file)
@@ -153,3 +153,7 @@ void f74 (void);
 void f75 (void);
 #pragma omp declare variant (f1) match(implementation={atomic_default_mem_order("relaxed")})   /* { dg-error "expected identifier before string constant" } */
 void f76 (void);
+#pragma omp declare variant (f1) match(user={condition(score(&f76):1)})        /* { dg-error "score argument must be constant integer expression" "" { target { ! c++98_only } } } */
+void f77 (void);                                                       /* { dg-error "cannot appear in a constant-expression" "" { target c++98_only } .-1 } */
+#pragma omp declare variant (f1) match(user={condition(score(-130):1)})        /* { dg-error "score argument must be non-negative" } */
+void f78 (void);
index d0800ff2b04e757621c72399baadf2d311497260..f5d7797f45840889375a3756b78ac0200e90767f 100644 (file)
@@ -147,3 +147,5 @@ void f76 (void);
 void f77 (void);
 #pragma omp declare variant (f13) match (implementation={vendor(nvidia)})
 void f78 (void);
+#pragma omp declare variant (f13) match (user={condition(score(0):0)})
+void f79 (void);
index f72d862250ab4334bda0afe96c4fccd928620043..b5da619dd033e4820bb5c9f4d23f9579508db429 100644 (file)
@@ -9,10 +9,20 @@ void f03 ();
 #pragma omp declare variant (f03) match (user={condition(score((T) 1):1)})     // { dg-error "score argument must be constant integer expression" }
 template <typename T>
 void f04 ();
+void f05 ();
+#pragma omp declare variant (f05) match (user={condition(score(N):1)}) // { dg-error "score argument must be non-negative" }
+template <int N>
+void f06 ();
+void f07 ();
+#pragma omp declare variant (f05) match (user={condition(score(N):1)})
+template <int N>
+void f08 ();
 
 void
 test ()
 {
   f02 <double> ();
   f04 <float> ();
+  f06 <-1> ();
+  f08 <0> ();
 }