[libc-commits] [libc] [libc] build with -Werror (PR #73966)

Nick Desaulniers via libc-commits libc-commits at lists.llvm.org
Mon Dec 4 10:14:42 PST 2023


https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/73966

>From ca08f81a7e42053e0982d34161f61b5d23969327 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Thu, 30 Nov 2023 09:54:15 -0800
Subject: [PATCH 1/4] [libc] build with -Werror

A recent commit introduced warnings observable when building unit tests. If the
unit tests don't fail when warnings are introduced into the build, then we
might fail to notice them in the stream of output from check-libc.

Link: https://github.com/llvm/llvm-project/pull/72763/files#r1410932348
---
 libc/cmake/modules/LLVMLibCObjectRules.cmake | 1 +
 1 file changed, 1 insertion(+)

diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 5fbbfd58db2d0..7d390dd27ebe8 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -43,6 +43,7 @@ function(_get_common_compile_options output_var flags)
     list(APPEND compile_options "-fno-rtti")
     list(APPEND compile_options "-Wall")
     list(APPEND compile_options "-Wextra")
+    list(APPEND compile_options "-Werror")
     list(APPEND compile_options "-Wconversion")
     list(APPEND compile_options "-Wno-sign-conversion")
     list(APPEND compile_options "-Wimplicit-fallthrough")

>From eb6bac42efb1704ce2b2f2d2fb94cfbe96aec515 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Fri, 1 Dec 2023 15:43:14 -0800
Subject: [PATCH 2/4] add LLVM_LIBC_WNO_ERROR config

---
 libc/cmake/modules/LLVMLibCObjectRules.cmake | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 7d390dd27ebe8..da213444fe7d1 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -43,7 +43,10 @@ function(_get_common_compile_options output_var flags)
     list(APPEND compile_options "-fno-rtti")
     list(APPEND compile_options "-Wall")
     list(APPEND compile_options "-Wextra")
-    list(APPEND compile_options "-Werror")
+    # -DLLVM_LIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
+    if(NOT LLVM_LIBC_WNO_ERROR)
+      list(APPEND compile_options "-Werror")
+    endif()
     list(APPEND compile_options "-Wconversion")
     list(APPEND compile_options "-Wno-sign-conversion")
     list(APPEND compile_options "-Wimplicit-fallthrough")

>From 1fa2e4df97a85dc6dbede03d3e4a1cfbd65228db Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 4 Dec 2023 09:44:59 -0800
Subject: [PATCH 3/4] s/LLVM_//

---
 libc/cmake/modules/LLVMLibCObjectRules.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index da213444fe7d1..ef654bd7b34ab 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -43,8 +43,8 @@ function(_get_common_compile_options output_var flags)
     list(APPEND compile_options "-fno-rtti")
     list(APPEND compile_options "-Wall")
     list(APPEND compile_options "-Wextra")
-    # -DLLVM_LIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
-    if(NOT LLVM_LIBC_WNO_ERROR)
+    # -DLIBC_WNO_ERROR=ON if you can't build cleanly with -Werror.
+    if(NOT LIBC_WNO_ERROR)
       list(APPEND compile_options "-Werror")
     endif()
     list(APPEND compile_options "-Wconversion")

>From a224d0bd3982d706b071800fa7202dfbbed6f300 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 4 Dec 2023 10:14:23 -0800
Subject: [PATCH 4/4] add note to coding style docs about no warnings

---
 libc/docs/dev/code_style.rst | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libc/docs/dev/code_style.rst b/libc/docs/dev/code_style.rst
index a050a4c1d3dd7..eeeced0359adb 100644
--- a/libc/docs/dev/code_style.rst
+++ b/libc/docs/dev/code_style.rst
@@ -178,3 +178,11 @@ these functions do not call the constructors and destructors of the
 allocated/deallocated objects. So, use these functions carefully and only
 when it is absolutely clear that constructor and destructor invocation is
 not required.
+
+Warnings in sources
+===================
+
+We expect contributions to be free of warnings from the `minimum supported
+compiler versions`__ (and newer).
+
+.. __: https://libc.llvm.org/compiler_support.html#minimum-supported-versions



More information about the libc-commits mailing list