This avoids prematurely evaluating .if conditions within
repetitions/macros, that previously were erroneously
evaluated too early if the enclosing environment was wrapped
in an .if.
---
 gas-preprocessor.pl | 33 +++++++++++++++++++--------------
 test.S              | 18 ++++++++++++++++++
 2 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/gas-preprocessor.pl b/gas-preprocessor.pl
index 5917d2b..24977a7 100755
--- a/gas-preprocessor.pl
+++ b/gas-preprocessor.pl
@@ -301,21 +301,26 @@ sub parse_if_line {
 
     # evaluate .if blocks
     if (scalar(@ifstack)) {
-        if ($line =~ /\.endif/) {
-            pop(@ifstack);
-            return 1;
-        } elsif ($line =~ /\.elseif\s+(.*)/) {
-            if ($ifstack[-1] == 0) {
-                $ifstack[-1] = !!eval_expr($1);
-            } elsif ($ifstack[-1] > 0) {
-                $ifstack[-1] = -$ifstack[-1];
+        # Don't evaluate any new if statements if we're within
+        # a repetition or macro - they will be evaluated once
+        # the repetition is unrolled or the macro is expanded.
+        if (scalar(@rept_lines) == 0 and $macro_level == 0) {
+            if ($line =~ /\.endif/) {
+                pop(@ifstack);
+                return 1;
+            } elsif ($line =~ /\.elseif\s+(.*)/) {
+                if ($ifstack[-1] == 0) {
+                    $ifstack[-1] = !!eval_expr($1);
+                } elsif ($ifstack[-1] > 0) {
+                    $ifstack[-1] = -$ifstack[-1];
+                }
+                return 1;
+            } elsif ($line =~ /\.else/) {
+                $ifstack[-1] = !$ifstack[-1];
+                return 1;
+            } elsif (handle_if($line)) {
+                return 1;
             }
-            return 1;
-        } elsif ($line =~ /\.else/) {
-            $ifstack[-1] = !$ifstack[-1];
-            return 1;
-        } elsif (handle_if($line)) {
-            return 1;
         }
 
         # discard lines in false .if blocks
diff --git a/test.S b/test.S
index a05e743..f8372d5 100644
--- a/test.S
+++ b/test.S
@@ -30,3 +30,21 @@ m 0
 .irpc i, 01
     m \i
 .endr
+
+.macro outer
+    .macro inner
+        .if VAR1 > 10
+            mov r4, #42
+        .endif
+    .endm
+
+    .set VAR1, 5
+    inner
+    .set VAR1, 15
+    inner
+    .purgem inner
+.endm
+
+.if 2 > 1
+    outer
+.endif
-- 
1.8.5.2 (Apple Git-48)

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to