Browse Source

gcc: run-test: Support conditional directives.

* gcc-plugin/tests/run-test.in (diagnostic-matches-directive?): New
  `cflags' and `ldflags' parameters; adjust caller accordingly.  Support
  the `if optimizing?' and `unless optimizing?' directive conditionals.
Ludovic Courtès 12 years ago
parent
commit
efa93e4743
1 changed files with 23 additions and 8 deletions
  1. 23 8
      gcc-plugin/tests/run-test.in

+ 23 - 8
gcc-plugin/tests/run-test.in

@@ -233,14 +233,28 @@ pairs."
           (else
            (loop (read-char port) directives)))))
 
-(define (diagnostic-matches-directive? diagnostic directive location)
+(define (diagnostic-matches-directive? diagnostic directive location
+                                       cflags ldflags)
   "Return #t if DIAGNOSTIC matches DIRECTIVE, which is at LOCATION."
-  (and (location? (diagnostic-location diagnostic))
-       (location=? (diagnostic-location diagnostic) location)
-       (match directive
-         ((kind message)
-          (and (eq? kind (diagnostic-kind diagnostic))
-               (string-match message (diagnostic-message diagnostic)))))))
+  (define optimizing?
+    (let ((opt (find (cut string-prefix? "-O" <>) cflags)))
+      (match opt
+        ((or #f "-O0") #f)
+        (_ #t))))
+
+  (let loop ((directive directive))
+    (match directive
+      (('if 'optimizing? directive)
+       (or (not optimizing?)
+           (loop directive)))
+      (('unless 'optimizing? directive)
+       (or optimizing?
+           (loop directive)))
+      ((kind message)
+       (and (eq? kind (diagnostic-kind diagnostic))
+            (location? (diagnostic-location diagnostic))
+            (location=? (diagnostic-location diagnostic) location)
+            (string-match message (diagnostic-message diagnostic)))))))
 
 
 ;;;
@@ -260,7 +274,8 @@ unsatisfied directives."
           (values status diagnostics unsatisfied)
           (let* ((dir  (car directives))
                  (diag (find (cute diagnostic-matches-directive?
-                                   <> (cdr dir) (car dir))
+                                   <> (cdr dir) (car dir)
+                                   cflags ldflags)
                              diagnostics)))
             (if diag
                 (loop (delq diag diagnostics)