[Openmp-commits] [clang] [openmp] [DO NOT MERGE] Verify openmp under -Wunused-template (PR #207957)
Aditya Medhane via Openmp-commits
openmp-commits at lists.llvm.org
Tue Jul 7 03:19:22 PDT 2026
https://github.com/flash1729 created https://github.com/llvm/llvm-project/pull/207957
None
>From ce44d058dd0caad7e96f1ec18282f74e7df9f9c6 Mon Sep 17 00:00:00 2001
From: flash1729 <sherlockedaditya at gmail.com>
Date: Tue, 7 Jul 2026 15:32:02 +0530
Subject: [PATCH 1/2] [DO NOT MERGE] CI trigger: pull openmp into premerge
footprint
---
openmp/runtime/src/kmp_utility.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/openmp/runtime/src/kmp_utility.cpp b/openmp/runtime/src/kmp_utility.cpp
index bfa450c9ced26..252bc1dc10b28 100644
--- a/openmp/runtime/src/kmp_utility.cpp
+++ b/openmp/runtime/src/kmp_utility.cpp
@@ -10,6 +10,9 @@
//
//===----------------------------------------------------------------------===//
+// NOTE: temporary CI trigger for a do-not-merge draft PR; this line will not
+// be merged.
+
#include "kmp.h"
#include "kmp_i18n.h"
#include "kmp_str.h"
>From d359b734d655de360a98535584127bf880bc6c01 Mon Sep 17 00:00:00 2001
From: flash1729 <sherlockedaditya at gmail.com>
Date: Fri, 26 Jun 2026 21:40:49 +0530
Subject: [PATCH 2/2] [Clang] Enable -Wunused-template under -Wall
Uncomment UnusedTemplate in the Unused diagnostic group so -Wunused-template
is part of -Wall. It diagnoses unused function and variable templates with
internal linkage; in a header, such a template gives every translation unit
its own internal-linkage copy, which is a latent ODR violation.
Also update the affected tests (Misc/warning-wall.c and the
warn-func-not-needed.cpp / warn-variable-not-needed.cpp -verify tests) and add
a release note.
Closes #202945.
---
clang/docs/ReleaseNotes.md | 5 +++++
clang/include/clang/Basic/DiagnosticGroups.td | 2 +-
clang/test/Misc/warning-wall.c | 2 ++
clang/test/SemaCXX/warn-func-not-needed.cpp | 2 +-
clang/test/SemaCXX/warn-variable-not-needed.cpp | 2 +-
5 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md
index cc85604343da9..e81670acb0452 100644
--- a/clang/docs/ReleaseNotes.md
+++ b/clang/docs/ReleaseNotes.md
@@ -563,6 +563,11 @@ latest release, please see the [Clang Web Site](https://clang.llvm.org) or the
allowing it to be disabled independently with `-Wno-unused-but-set-global`.
(#GH148361)
+- `-Wunused-template` is now part of `-Wunused` (which is enabled by `-Wall`).
+ It diagnoses unused function and variable templates with internal linkage,
+ which in a header is a latent ODR hazard. It can be disabled with
+ `-Wno-unused-template`. (#GH202945)
+
- Added `-Wlifetime-safety` to enable lifetime safety analysis,
a CFG-based intra-procedural analysis that detects use-after-free and related
temporal safety bugs. See the
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 73fb97aeeb302..79583534b9bbd 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -1369,7 +1369,7 @@ def Conversion
def Unused : DiagGroup<"unused",
[UnusedArgument, UnusedFunction, UnusedLabel,
// UnusedParameter, (matches GCC's behavior)
- // UnusedTemplate, (clean-up libc++ before enabling)
+ UnusedTemplate,
// UnusedMemberFunction, (clean-up llvm before enabling)
UnusedPrivateField, UnusedLambdaCapture,
UnusedLocalTypedef, UnusedValue, UnusedVariable,
diff --git a/clang/test/Misc/warning-wall.c b/clang/test/Misc/warning-wall.c
index 6d6c4e562400f..ade9cbaace77e 100644
--- a/clang/test/Misc/warning-wall.c
+++ b/clang/test/Misc/warning-wall.c
@@ -73,6 +73,8 @@ CHECK-NEXT: -Wunused-argument
CHECK-NEXT: -Wunused-function
CHECK-NEXT: -Wunneeded-internal-declaration
CHECK-NEXT: -Wunused-label
+CHECK-NEXT: -Wunused-template
+CHECK-NEXT: -Wunneeded-internal-declaration
CHECK-NEXT: -Wunused-private-field
CHECK-NEXT: -Wunused-lambda-capture
CHECK-NEXT: -Wunused-local-typedef
diff --git a/clang/test/SemaCXX/warn-func-not-needed.cpp b/clang/test/SemaCXX/warn-func-not-needed.cpp
index cb3cae4cd6c76..74438543c43b7 100644
--- a/clang/test/SemaCXX/warn-func-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-func-not-needed.cpp
@@ -10,7 +10,7 @@ void foo() {
}
namespace test1_template {
-template <typename T> static void f() {}
+template <typename T> static void f() {} // expected-warning {{unused function template}}
template <> void f<int>() {} // expected-warning {{function 'f<int>' is not needed and will not be emitted}}
template <typename T>
void foo() {
diff --git a/clang/test/SemaCXX/warn-variable-not-needed.cpp b/clang/test/SemaCXX/warn-variable-not-needed.cpp
index 272c8998d15c0..d234e9140e3fd 100644
--- a/clang/test/SemaCXX/warn-variable-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-variable-not-needed.cpp
@@ -4,7 +4,7 @@ namespace test1 {
static int abc = 42; // expected-warning {{variable 'abc' is not needed and will not be emitted}}
namespace {
- template <typename T> int abc_template = 0;
+ template <typename T> int abc_template = 0; // expected-warning {{unused variable template}}
template <> int abc_template<int> = 0; // expected-warning {{variable 'abc_template<int>' is not needed and will not be emitted}}
} // namespace
template <typename T>
More information about the Openmp-commits
mailing list