[pcre-dev] [Bug 2154] New: sljitNativeMIPS_common.c:506:3: e…

Top Page
Delete this message
Author: admin
Date:  
To: pcre-dev
Subject: [pcre-dev] [Bug 2154] New: sljitNativeMIPS_common.c:506:3: error: a label can only be part of a statement and a declaration is not a statement
https://bugs.exim.org/show_bug.cgi?id=2154

            Bug ID: 2154
           Summary: sljitNativeMIPS_common.c:506:3: error: a label can
                    only be part of a statement and a declaration is not a
                    statement
           Product: PCRE
           Version: 8.41
          Hardware: SGI
                OS: Linux
            Status: NEW
          Severity: bug
          Priority: high
         Component: Code
          Assignee: ph10@???
          Reporter: kumba@???
                CC: pcre-dev@???


Created attachment 1029
--> https://bugs.exim.org/attachment.cgi?id=1029&action=edit
Fix compile on MIPS for sljitNativeMIPS_common.c

In libpcre-8.41, on a MIPS platform, it looks like in some specific case, this
code change (from 8.40):

+SLJIT_API_FUNC_ATTRIBUTE sljit_s32 sljit_has_cpu_feature(sljit_s32
feature_type)
+{
+    switch (feature_type) {
+    case SLJIT_HAS_FPU:
+#ifdef SLJIT_IS_FPU_AVAILABLE
+        return SLJIT_IS_FPU_AVAILABLE;
+#elif defined(__GNUC__)
+        sljit_sw fir;
+        asm ("cfc1 %0, $0" : "=r"(fir));
+        return (fir >> 22) & 0x1;
+#else
+#error "FIR check is not implemented for this architecture"
+#endif
+
+#if (defined SLJIT_MIPS_R1 && SLJIT_MIPS_R1)
+    case SLJIT_HAS_CLZ:
+    case SLJIT_HAS_CMOV:
+        return 1;
+#endif
+
+    default:
+        return 0;
+    }
+}
+


Produces this compiler error:

libtool: compile:  mips-unknown-linux-uclibc-gcc -DHAVE_CONFIG_H -I.
-I/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41 -fvisibility=hidden -Os
-march=rm7000 -mtune=rm7000 -pipe -mplt -fomit-frame-pointer -c
/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41/pcre_jit_compile.c  -fPIC
-DPIC -o .libs/libpcre_la-pcre_jit_compile.o
In file included from
/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41/sljit/sljitLir.c:1747:0,
                 from
/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41/pcre_jit_compile.c:62:
/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41/sljit/sljitNativeMIPS_common.c:
In function 'sljit_has_cpu_feature':
/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41/sljit/sljitNativeMIPS_common.c:506:3:
error: a label can only be part of a statement and a declaration is not a
statement
   sljit_sw fir;
   ^~~~~~~~
make[1]: *** [Makefile:1734: libpcre_la-pcre_jit_compile.lo] Error 1
make[1]: Leaving directory
'/usr/obj/portage/dev-libs/libpcre-8.41/work/pcre-8.41-abi_mips_o32.o32'
make: *** [Makefile:1322: all] Error 2


The error is because SLJIT_IS_FPU_AVAILABLE is not set, but __GNUC__ is, so the
switch statement comes out like this:

    switch (feature_type) {
    case SLJIT_HAS_FPU:
        sljit_sw fir;
        asm ("cfc1 %0, $0" : "=r"(fir));
        return (fir >> 22) & 0x1;


    default:
        return 0;
    }


And this runs afoul of a quirk in C grammar, based on an explanation at this
StackOverflow post:
https://stackoverflow.com/a/18496414/

"""
This is a quirk of the C grammar. A label (Cleanup:) is not allowed to appear
immediately before a declaration (such as char *str ...;), only before a
statement (printf(...);). In C89 this was no great difficulty because
declarations could only appear at the very beginning of a block, so you could
always move the label down a bit and avoid the issue. In C99 you can mix
declarations and code, but you still can't put a label immediately before a
declaration.
"""


A simple fix for this is to wrap the code block in the __GNUC__ case in braces.
I have attached a patch that does this, and can confirm on running hardware
(an SGI O2) that pcre-8.41 will compile with the patch.

--
You are receiving this mail because:
You are on the CC list for the bug.