Project

General

Profile

Actions

Bug #21629

open

Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21

Added by debo (David Bohman) about 4 hours ago. Updated about 2 hours ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-darwin16]
[ruby-core:<unknown>]

Description

Here is the error I encountered. This is using clang version 21.1.3 as the compiler toolchain on Darwin.

DYLD_LIBRARY_PATH=.:../../.. ASAN_OPTIONS=detect_leaks=0 "clang -I../../../.ext/include/x86_64-darwin16 -I../../../../ruby-3.4.7/include -I../../../../ruby-3.4.7/ext/-test-/public_header_warnings -I/usr/local/include -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT   -fstack-protector-strong -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fdeclspec  -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wextra-tokens -Wdeprecated-declarations -Wdivision-by-zero -Wdiv-by-zero -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wshorten-64-to-32 -Wwrite-strings -Wold-style-definition -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wunused-variable -Wmisleading-indentation -Wundef  -fno-common -pipe  -D_TEST_OK -Werror -c conftest.c"
In file included from conftest.c:1:
In file included from ../../../../ruby-3.4.7/include/ruby.h:38:
In file included from ../../../../ruby-3.4.7/include/ruby/ruby.h:28:
In file included from ../../../../ruby-3.4.7/include/ruby/internal/arithmetic.h:24:
In file included from ../../../../ruby-3.4.7/include/ruby/internal/arithmetic/char.h:29:
../../../../ruby-3.4.7/include/ruby/internal/core/rstring.h:398:24: error: default initialization of an object of type 'struct RString' with const member leaves the object uninitialized [-Werror,-Wdefault-const-init-field-unsafe]
  398 |         struct RString retval;
      |                        ^
../../../../ruby-3.4.7/include/ruby/internal/core/rbasic.h:86:17: note: member 'klass' declared 'const' here
   86 |     const VALUE klass;
      |                 ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

The configuration is the following:

CC=clang CXX=clang++ CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib ../ruby-3.4.7/configure --enable-shared --with-rdoc=ri,html

Files

ruby-log.txt (432 KB) ruby-log.txt debo (David Bohman), 10/07/2025 11:06 PM
ruby-log-2.txt (372 KB) ruby-log-2.txt k0kubun's build of Ruby 3.4.7 with llvm-21 on macOS 26 k0kubun (Takashi Kokubun), 10/07/2025 11:14 PM
ruby-config-log.txt (27 KB) ruby-config-log.txt debo (David Bohman), 10/08/2025 12:46 AM
Actions #1

Updated by debo (David Bohman) about 4 hours ago

Let me know if you would like me to attach the entire build log.

Actions #2

Updated by debo (David Bohman) about 4 hours ago

Note that this is a tarball build.

Actions #3

Updated by k0kubun (Takashi Kokubun) about 4 hours ago · Edited

  • Status changed from Open to Feedback
  • ruby -v changed from ruby 3.4.6 (2025-09-16 revision dbd83256b1) +PRISM [x86_64-darwin16] to ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [arm64-darwin16]

Let me know if you would like me to attach the entire build log.

Please do. I'm not sure how an error in one of the things checked by configure (conftest.c) leads to a build failure from this log.

I confirmed that I can build the same tarball of Ruby 3.4.7 with Apple clang 17.0.0 on darwin25. You might want to consider testing it with Apple clang installed by XCode command-line tools and/or upgrading your macOS to a non-EOL version (Apple's support of darwin16/macOS 10.12 has ended in 2019).

Actions #4

Updated by k0kubun (Takashi Kokubun) about 4 hours ago

  • ruby -v changed from ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [arm64-darwin16] to ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-darwin16]
Actions #5

Updated by k0kubun (Takashi Kokubun) about 4 hours ago

  • Subject changed from Ruby-3.4.7 fails to build using clang / llvm to Ruby-3.4.7 fails to build using clang / llvm 21
  • Status changed from Feedback to Open

I'll see if I can reproduce it with clang 21 on my end too

Actions #6

Updated by debo (David Bohman) about 4 hours ago

  • Subject changed from Ruby-3.4.7 fails to build using clang / llvm 21 to Ruby-3.4.7 fails to build using clang / llvm

Note that I was using llvm-21.1.1 as the compiler toolchain when I built ruby-3.4.6. I'll try building ruby-3.4.6 again.

Actions #7

Updated by debo (David Bohman) about 4 hours ago

Attaching the build log for ruby-3.4.7.

Actions #8

Updated by k0kubun (Takashi Kokubun) about 4 hours ago · Edited

Attaching the build log for ruby-3.4.7.

Could you also include the logs of configure and the commands you ran (both configure and make)? As an example, I've attached mine.

As shown in the attached log, it succeeded with llvm-21. So this is not an issue of Ruby 3.4.7 with LLVM 21 on a still-supported macOS version. As such, I strongly encourage you to test it after upgrading your macOS to a non-EOL version.

Actions #9

Updated by k0kubun (Takashi Kokubun) about 3 hours ago

  • Subject changed from Ruby-3.4.7 fails to build using clang / llvm to Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm21
  • Status changed from Feedback to Open
  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: UNKNOWN to 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED

To me, the direct cause of the build failure seems to be -Werror added by your environment. I don't know what part of llvm-21 or darwin-16 on Intel Mac leads to adding -Werror, but it's unfortunately normal that new compiler versions show warnings on Ruby builds, so you shouldn't let warnings fail your Ruby build.

I'll repurpose this ticket for fixing the -Wdefault-const-init-field-unsafe warning. But the fact that you have -Werror in your build environment seems like a separate problem.

Actions #10

Updated by k0kubun (Takashi Kokubun) about 3 hours ago

  • Subject changed from Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm21 to Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21
Actions #11

Updated by debo (David Bohman) about 3 hours ago

  • Subject changed from Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21 to Ruby-3.4.7 fails to build using clang / llvm

I don't understand. The ruby build is what added the -Werror to the compile that failed.

Actions #12

Updated by nobu (Nobuyoshi Nakada) about 2 hours ago

  • Backport changed from 3.2: UNKNOWN, 3.3: UNKNOWN, 3.4: REQUIRED to 3.2: REQUIRED, 3.3: REQUIRED, 3.4: REQUIRED
Actions #13

Updated by k0kubun (Takashi Kokubun) about 2 hours ago · Edited

  • Subject changed from Ruby-3.4.7 fails to build using clang / llvm to Ruby-3.4.7 prints -Wdefault-const-init-field-unsafe warnings on clang / llvm 21

The ruby build is what added the -Werror to the compile that failed.

Could you point out the code that does it? As I said before, it didn't in my environment (Ruby 3.4.7, macOS 26, llvm-21), so I can't find the thing that I can't reproduce. You still haven't provided the logs of configure that I asked for, so it's also making it harder to figure out.

Actions #14

Updated by rhenium (Kazuki Yamaguchi) about 2 hours ago

The attached ruby-log.txt seems to show the build was successful, but the test case meant to catch this kind of problem failed, as intended:

*** Following extensions are not compiled:
-test-/public_header_warnings:
	Could not be configured. It will not be installed.
	/tera/tera/debo/Projects/ruby/ruby-3.4.7/ext/-test-/public_header_warnings/extconf.rb:14: baseline compiler warning test failed
	Check ext/-test-/public_header_warnings/mkmf.log for more details.
*** Fix the problems, then remove these directories and try again if you want.
Actions #15

Updated by debo (David Bohman) about 2 hours ago

Here is the configure log.

Actions #16

Updated by debo (David Bohman) about 2 hours ago · Edited

I just built ruby with make -j <n> where <n> is the number of cpu threads available on this machine.

Actions #17

Updated by debo (David Bohman) about 2 hours ago

The fact that the ruby build gets these warnings seems to be new in clang 21.

Actions #18

Updated by debo (David Bohman) about 2 hours ago

You are correct, it does build and install:

ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-darwin16]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0