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

Build fails on Fedora 38 with clang 16 (-Wgnu-offsetof-extensions) #13736

Closed
airlockgithubci opened this issue May 11, 2023 · 3 comments
Closed

Comments

@airlockgithubci
Copy link

The build fails on Fedora 38 with clang 16.

.bazelrc file to use clang:

build --config=clang
build --cxxopt=-std=c++17

build:clang --action_env=BAZEL_COMPILER=clang
build:clang --action_env=CC=clang --action_env=CXX=clang++
build:clang --linkopt=-fuse-ld=lld

Build error:

ERROR: /home/user/upb/BUILD:102:11: Compiling upb/arena.c failed: (Exit 1): clang-16 failed: error executing command (from target //:upb) /usr/bin/clang-16 -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -Wunused-but-set-parameter -Wno-free-nonheap-object -fcolor-diagnostics -fno-omit-frame-pointer -MD -MF ... (remaining 22 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
upb/arena.c:177:25: error: defining a type within '__builtin_offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions]
  n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena));
                        ^~~~~~~~~~~~~~~~~~~~~~~
./upb/port_def.inc:95:38: note: expanded from macro 'UPB_ALIGN_OF'
#define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member)
                                     ^~~~~~
/usr/lib64/clang/16/include/stddef.h:111:43: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                                          ^
./upb/port_def.inc:93:48: note: expanded from macro 'UPB_ALIGN_DOWN'
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
                                               ^~~~~
upb/arena.c:177:25: error: defining a type within '__builtin_offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions]
  n = UPB_ALIGN_DOWN(n, UPB_ALIGN_OF(upb_Arena));
                        ^~~~~~~~~~~~~~~~~~~~~~~
./upb/port_def.inc:95:38: note: expanded from macro 'UPB_ALIGN_OF'
#define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member)
                                     ^~~~~~
/usr/lib64/clang/16/include/stddef.h:111:43: note: expanded from macro 'offsetof'
#define offsetof(t, d) __builtin_offsetof(t, d)
                                          ^
./upb/port_def.inc:93:58: note: expanded from macro 'UPB_ALIGN_DOWN'
#define UPB_ALIGN_DOWN(size, align) ((size) / (align) * (align))
                                                         ^~~~~
2 errors generated.
@mkauf
Copy link

mkauf commented Jun 12, 2023

I have created this issue with the wrong GitHub account, sorry. If possible, please change the reporter to @mkauf .

@acozzette acozzette transferred this issue from protocolbuffers/upb Aug 29, 2023
RmStorm added a commit to RmStorm/protobuf that referenced this issue Oct 19, 2023
When compiling upb Clang will emit a warning like this:
error: defining a type within '__builtin_offsetof' is a Clang extension [-Werror,-Wgnu-offsetof-extensions]

As shown in issue protocolbuffers#13736, this commit fixes that error by adding
the compiler flag '-Wno-gnu-offsetof-extensions' which suppreses
the warning/error.
@esrauchg
Copy link

It looks like something else is happening here; if you look at the UPB_ALIGN_OF() macro definition it already has a separate definition for #ifdef clang with a different definition:
https://github.com/protocolbuffers/upb/blob/main/upb/port/def.inc#L120

It seems like the warning you're disabling is based on hitting the non-clang path with a clang compiler, is it possible your configuration is somehow using clang but without clang defined for the preprocessor?

@mkauf
Copy link

mkauf commented Oct 27, 2023

I think that the bug has been fixed and the issue can be closed :-)

Probably I have tested with the git revision that Envoy 1.26.0 used, and not with the main branch (sorry...). That was git revision protocolbuffers/upb@e4635f2

Commit protocolbuffers/upb@896e74c removed the compiler flags "-pedantic" and "-Werror=pedantic", so the build does not fail anymore.

Commit protocolbuffers/upb@21af783 fixed UPB_ALIGN_OF for clang, so clang now uses a different code path than gcc (thanks @esrauchg)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants