From f80704753ddd7262518532a051d19364627b927c Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 24 Nov 2025 22:55:51 -0700 Subject: [PATCH 1/2] Turn AIS_WARN_UNSAFE_BUFFER_OPS on by default This affects clang/llvm C++ only. We currently raise no warnings with this switched on. If it becomes problematic in the future, we can switch it back off, but it's useful to turn on to encourage developers to find other solutions if this raises warnings. This is only turned on by default w/ clang. For gcc, it remains off since it's not useful. It will now emit a FATAL_ERROR if enabled with gcc. --- INSTALL.md | 1 + cmake/AISClangSafeBuffers.cmake | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index 9208e63f..a9408f2d 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -37,6 +37,7 @@ Options |------|-------|-------| |AIS\_USE\_CLANG\_TIDY|OFF|Run the `clang-tidy` tool| |AIS\_USE\_IWYU|OFF|Run the `include-what-you-use` tool| +|AIS\_WARN\_UNSAFE\_BUFFER\_OPS|ON|Scan code for unsafe buffer operations (clang only)| |BUILD\_AIS\_DOCS|OFF|Build API documentation (requires Doxygen)| |BUILD\_AISCP|ON|Build `aiscp` example program (OFF if no hipFile)| |BUILD\_CODE\_COVERAGE|OFF|Generate code coverage information when tests are run| diff --git a/cmake/AISClangSafeBuffers.cmake b/cmake/AISClangSafeBuffers.cmake index a8281e34..3994f289 100644 --- a/cmake/AISClangSafeBuffers.cmake +++ b/cmake/AISClangSafeBuffers.cmake @@ -9,7 +9,13 @@ # # Fixing this cleanly requires C++20, so it's an option for now #----------------------------------------------------------------------------- -option(AIS_WARN_UNSAFE_BUFFER_OPS "Warn about unsafe buffer operations (llvm C++ only)" OFF) +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(USE_UBO ON) +else() + set(USE_UBO OFF) +endif() +option(AIS_WARN_UNSAFE_BUFFER_OPS "Warn about unsafe buffer operations (llvm C++ only)" ${USE_UBO}) + if(AIS_WARN_UNSAFE_BUFFER_OPS) if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(AIS_CLANG_WARNING_FLAGS @@ -17,5 +23,7 @@ if(AIS_WARN_UNSAFE_BUFFER_OPS) -fsafe-buffer-usage-suggestions ${AIS_CLANG_WARNING_FLAGS} ) + else() + message(FATAL_ERROR "Unsafe buffer warnings are only useful for clang/llvm") endif() endif() From 23d4895cdebd0077911f3bdcf37e040a30db904e Mon Sep 17 00:00:00 2001 From: Dana Robinson Date: Mon, 24 Nov 2025 23:06:10 -0700 Subject: [PATCH 2/2] Tweak INSTALL note --- INSTALL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index a9408f2d..9bd6996f 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -37,7 +37,7 @@ Options |------|-------|-------| |AIS\_USE\_CLANG\_TIDY|OFF|Run the `clang-tidy` tool| |AIS\_USE\_IWYU|OFF|Run the `include-what-you-use` tool| -|AIS\_WARN\_UNSAFE\_BUFFER\_OPS|ON|Scan code for unsafe buffer operations (clang only)| +|AIS\_WARN\_UNSAFE\_BUFFER\_OPS|ON|Scan code for unsafe buffer operations (clang only, OFF for others)| |BUILD\_AIS\_DOCS|OFF|Build API documentation (requires Doxygen)| |BUILD\_AISCP|ON|Build `aiscp` example program (OFF if no hipFile)| |BUILD\_CODE\_COVERAGE|OFF|Generate code coverage information when tests are run|