Bug 245176 - [CMake] Clang warnings about C code being built in C++ mode
Summary: [CMake] Clang warnings about C code being built in C++ mode
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Tools / Tests (show other bugs)
Version: WebKit Nightly Build
Hardware: PC Linux
: P2 Minor
Assignee: Lauro Moura
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2022-09-14 05:06 PDT by Adrian Perez
Modified: 2022-11-13 20:26 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Perez 2022-09-14 05:06:30 PDT
I haven't researched the root cause yet, but it looks like either the build is using “clang++”
to compile plain C files, or passing “-x c++” to the “clang” driver (less likely): 

  [3/30/6151|2.0/s|  0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/bmalloc_heap.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/31/6151|2.0/s|  0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/bmalloc_heap_config.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/39/6151|2.5/s|  0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/jit_heap.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/40/6151|2.5/s|  0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/jit_heap_config.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/57/6151|3.4/s|  0%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_bitfit_page_config_kind.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/95/6151|5.3/s|  1%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_fast_megapage_cache.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/101/6151|5.5/s|  1%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_heap_config_kind.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/152/6151|7.7/s|  2%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_segregated_page_config_kind.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/167/6151|8.3/s|  2%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_thread_local_cache.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
  [3/172/6151|8.5/s|  2%] Building CXX object Source/bmalloc/CMakeFiles/bmalloc.dir/libpas/src/libpas/pas_utility_heap_config.c.o
  clang-14: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]

...unless this is intentional and some of the libpas files are expected to be built with a C++
compiler for some reason even if their suffix is “.c” (not very likely, I suppose).
Comment 1 Adrian Perez 2022-09-14 05:07:35 PDT
This is easily reproducible with:

  CC=clang CXX=clang++ cmake -S. -Bbuild -DPORT=GTK -GNinja
  ninja -Cbuild
Comment 2 Fujii Hironori 2022-09-14 13:16:41 PDT
What about adding enable_language(C)?
Comment 3 Yusuke Suzuki 2022-09-14 13:35:42 PDT
This is intentional since these files cannot be compiled as C in GCC probably because GCC lacks some constant propagation feature, which requires this explicit C++ handling.
Comment 4 Yusuke Suzuki 2022-09-14 13:36:14 PDT
So, I think, if we are using clang, then we do not need to mark them as C++.
Comment 5 Stephan Szabo 2022-09-14 14:12:54 PDT
We'd noticed something similar in the past, but we thought it was something specific to our downstream compilers, so in our case we ended up forcing a -xc++ into the build in our toolchain.

It feels like this should work from the CMake side (setting the language to CXX for a file that has .c extension), so if it's more general and happens in a test project, I wonder if it's something that should get handled inside the CMake code (well the modules for the compiler).
Comment 6 Stephan Szabo 2022-09-15 09:42:31 PDT
From discussion on CMake discourse, with a minimum 3.20 or policy CMP0119 set to NEW, we'd get the -xc++ automatically when setting the language, but that won't help us for older versions.
Comment 7 Lauro Moura 2022-10-26 06:49:36 PDT
Pull request: https://github.com/WebKit/WebKit/pull/5814
Comment 8 EWS 2022-11-13 20:25:31 PST
Committed 256626@main (e071c895f5fc): <https://commits.webkit.org/256626@main>

Reviewed commits have been landed. Closing PR #5814 and removing active labels.
Comment 9 Radar WebKit Bug Importer 2022-11-13 20:26:20 PST
<rdar://problem/102302395>