Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brace-enclosed initializing of a union type #1385

Open
madebr opened this issue Jan 25, 2025 · 1 comment
Open

Brace-enclosed initializing of a union type #1385

madebr opened this issue Jan 25, 2025 · 1 comment
Labels
bug C C compiler C99 Features specific to C99

Comments

@madebr
Copy link

madebr commented Jan 25, 2025

While trying to build dethrace with OpenWatcom 2 (I haven't tried 1.x), I stumbled on this issue.
Dethrace is a CMake project, to which I had to apply small patches to support OpenWatcom.

Brace-enclosed initializing of a union type does not seem to work.

Building the example below in a minimal CMake project causes the following errors to be emitted:

Error log
/home/maarten/owatcom2/binl/wcl386 -zq -d+  -I/home/maarten/owatcom2/h -I/home/maarten/owatcom2/h/nt -aa -za -s -ot -d0 -dNDEBUG -foCMakeFiles/union_test.dir/main.c.obj -c -cc /home/maarten/projects/issues/main.c
/home/maarten/projects/issues/main.c(45): Error! E1063: Missing operand
/home/maarten/projects/issues/main.c(45): Error! E1009: Expecting ',' but found '{'
/home/maarten/projects/issues/main.c(45): Error! E1009: Expecting '}' but found '.'
/home/maarten/projects/issues/main.c(45): Error! E1009: Expecting ',' but found 'i'
/home/maarten/projects/issues/main.c(45): Error! E1063: Missing operand
/home/maarten/projects/issues/main.c(45): Error! E1009: Expecting ';' but found '}'
/home/maarten/projects/issues/main.c(45): Warning! W107: Missing return value for function 'main'
/home/maarten/projects/issues/main.c(45): Error! E1061: Expecting data or function declaration, but found ','
/home/maarten/projects/issues/main.c(46): Error! E1026: Invalid declarator
/home/maarten/projects/issues/main.c(46): Error! E1009: Expecting ';' but found '{'
/home/maarten/projects/issues/main.c(46): Error! E1061: Expecting data or function declaration, but found '{'
/home/maarten/projects/issues/main.c(46): Warning! W132: No storage class or type specified
/home/maarten/projects/issues/main.c(46): Error! E1034: Symbol 'BRT_MATRIX4' already defined
/home/maarten/projects/issues/main.c(46): Note! N2002: 'BRT_MATRIX4' defined in: /home/maarten/projects/issues/main.c(11)
/home/maarten/projects/issues/main.c(46): Error! E1034: Symbol 'br_value' already defined
/home/maarten/projects/issues/main.c(46): Note! N2002: 'br_value' defined in: /home/maarten/projects/issues/main.c(35)
/home/maarten/projects/issues/main.c(46): Error! E1129: Type does not agree with previous definition of 'br_value'
/home/maarten/projects/issues/main.c(46): Note! N2002: 'br_value' defined in: /home/maarten/projects/issues/main.c(35)
/home/maarten/projects/issues/main.c(46): Error! E1009: Expecting ';' but found '{'
/home/maarten/projects/issues/main.c(46): Error! E1061: Expecting data or function declaration, but found '{'
/home/maarten/projects/issues/main.c(46): Error! E1026: Invalid declarator
/home/maarten/projects/issues/main.c(46): Error! E1009: Expecting ';' but found '.'
/home/maarten/projects/issues/main.c(46): Error! E1061: Expecting data or function declaration, but found '.'
/home/maarten/projects/issues/main.c(46): Warning! W132: No storage class or type specified
/home/maarten/projects/issues/main.c(46): Warning! W102: Type mismatch (warning)
/home/maarten/projects/issues/main.c(46): Note! N2003: source conversion type is 'int *'
/home/maarten/projects/issues/main.c(46): Note! N2004: target conversion type is 'int'
/home/maarten/projects/issues/main.c(46): Error! E1009: Expecting ';' but found '}'
/home/maarten/projects/issues/main.c(46): Error! E1061: Expecting data or function declaration, but found '}'
/home/maarten/projects/issues/main.c(46): Error! E1147: Too many errors: compilation aborted
Error: Compiler returned a bad status compiling '/home/maarten/projects/issues/main.c'
ninja: build stopped: subcommand failed.
Small example
# Save this file as CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(openwatcom_unions)
add_executable(union_test main.c)
/* Save this file as main.c */
#include <stddef.h>

typedef enum {
    BRT_NULL_TOKEN,
    BRT_TOKEN,
    BRT_NULL,
    BRT_POINTER,
    BRT_FLOAT,
    BRT_INTEGER,
    BRT_MATRIX3,
    BRT_MATRIX4,
    BRT_MATRIX34
} br_token;

typedef struct {
    float v[4][4];
} matrix4_t;

typedef struct {
    float v[4][3];
} matrix34_t;

typedef struct {
    float v[3][3];
} matrix3_t;

typedef union {
    void *p;
    float f;
    int i;
    br_token t;
    matrix3_t *m3;
    matrix4_t *m4;
    matrix34_t *m34;
} br_value;

typedef struct {
    br_token a;
    br_value v;
} br_token_value;

int main(int argc, char *argv[]) {
    matrix4_t m4;
    br_token_value is_alternative[] = {
        { BRT_INTEGER, (br_value) { .i = 1337 } },
        { BRT_MATRIX4 , (br_value) { .m4 = &m4 }},
        { BRT_NULL_TOKEN , (br_value) { .p = NULL }}
    };
    return 0;
}

I can also reproduce this on ci: this is the project, and this is the ci result

edit
I've been asked to run wcl386 without -zq so it showed the wcc386 invocation.
The build system runs (after configuring with -DCMAKE_C_FLAGS="-aa -za99"):

/home/maarten/owatcom2/binl/wcl386 -zq -d+  -I/home/maarten/owatcom2/h -I/home/maarten/owatcom2/h/nt -aa -za99 -s -ot -d0 -dNDEBUG -foCMakeFiles/union_test.dir/src.c.obj -c -cc /home/maarten/projects/issues/src.c

Removing -zq shows:

wcc386 /home/maarten/projects/issues/src.c  -d+ -I/home/maarten/owatcom2/h -I/home/maarten/owatcom2/h/nt -aa -za99 -s -ot -d0 -dNDEBUG -foCMakeFiles/union_test.dir/src.c.obj
@jmalak jmalak added bug C C compiler C99 Features specific to C99 labels Jan 25, 2025
@jmalak
Copy link
Member

jmalak commented Jan 25, 2025

Thanks for your bug report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug C C compiler C99 Features specific to C99
Projects
None yet
Development

No branches or pull requests

2 participants