[clang] 4b72c5e - [clang][Sema] Subclass `-Wshorten-64-to-32` under `-Wimplicit-int-conversion` (#80814)
via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 8 04:37:58 PST 2024
Author: whisperity
Date: 2024-02-08T13:37:55+01:00
New Revision: 4b72c5e8277f8688f7ce0bc953f9f3ea54420358
URL: https://github.com/llvm/llvm-project/commit/4b72c5e8277f8688f7ce0bc953f9f3ea54420358
DIFF: https://github.com/llvm/llvm-project/commit/4b72c5e8277f8688f7ce0bc953f9f3ea54420358.diff
LOG: [clang][Sema] Subclass `-Wshorten-64-to-32` under `-Wimplicit-int-conversion` (#80814)
Although "implicit int conversions" is supposed to be a superset
containing the more specific "64-to-32" case, previously they were a
disjoint set, only enabled in common in the much larger `-Wconversion`.
Added:
clang/test/Sema/conversion-implicit-int-includes-64-to-32.c
Modified:
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/test/Sema/conversion-64-32.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 52a48c750fe55b..e158284aabeabc 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -149,7 +149,12 @@ Improvements to Clang's diagnostics
prints.
- Clang now diagnoses member template declarations with multiple declarators.
-- Clang now diagnoses use of the ``template`` keyword after declarative nested name specifiers.
+
+- Clang now diagnoses use of the ``template`` keyword after declarative nested
+ name specifiers.
+
+- The ``-Wshorten-64-to-32`` diagnostic is now grouped under ``-Wimplicit-int-conversion`` instead
+ of ``-Wconversion``. Fixes `#69444 <https://github.com/llvm/llvm-project/issues/69444>`_.
Improvements to Clang's time-trace
----------------------------------
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 6765721ae7002c..975eca0ad9b642 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -108,8 +108,10 @@ def EnumConversion : DiagGroup<"enum-conversion",
EnumCompareConditional]>;
def ObjCSignedCharBoolImplicitIntConversion :
DiagGroup<"objc-signed-char-bool-implicit-int-conversion">;
+def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
def ImplicitIntConversion : DiagGroup<"implicit-int-conversion",
- [ObjCSignedCharBoolImplicitIntConversion]>;
+ [Shorten64To32,
+ ObjCSignedCharBoolImplicitIntConversion]>;
def ImplicitConstIntFloatConversion : DiagGroup<"implicit-const-int-float-conversion">;
def ImplicitIntFloatConversion : DiagGroup<"implicit-int-float-conversion",
[ImplicitConstIntFloatConversion]>;
@@ -631,7 +633,6 @@ def Shadow : DiagGroup<"shadow", [ShadowFieldInConstructorModified,
def ShadowAll : DiagGroup<"shadow-all", [Shadow, ShadowFieldInConstructor,
ShadowUncapturedLocal, ShadowField]>;
-def Shorten64To32 : DiagGroup<"shorten-64-to-32">;
def : DiagGroup<"sign-promo">;
def SignCompare : DiagGroup<"sign-compare">;
def SwitchDefault : DiagGroup<"switch-default">;
@@ -942,7 +943,6 @@ def Conversion : DiagGroup<"conversion",
EnumConversion,
BitFieldEnumConversion,
FloatConversion,
- Shorten64To32,
IntConversion,
ImplicitIntConversion,
ImplicitFloatConversion,
diff --git a/clang/test/Sema/conversion-64-32.c b/clang/test/Sema/conversion-64-32.c
index dc417edcbc2168..c172dd109f3be2 100644
--- a/clang/test/Sema/conversion-64-32.c
+++ b/clang/test/Sema/conversion-64-32.c
@@ -9,9 +9,13 @@ typedef long long long2 __attribute__((__vector_size__(16)));
int4 test1(long2 a) {
int4 v127 = a; // no warning.
- return v127;
+ return v127;
}
int test2(long v) {
return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
}
+
+char test3(short s) {
+ return s * 2; // no warning.
+}
diff --git a/clang/test/Sema/conversion-implicit-int-includes-64-to-32.c b/clang/test/Sema/conversion-implicit-int-includes-64-to-32.c
new file mode 100644
index 00000000000000..e22ccbe821f65c
--- /dev/null
+++ b/clang/test/Sema/conversion-implicit-int-includes-64-to-32.c
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wimplicit-int-conversion -triple x86_64-apple-darwin %s
+
+int test0(long v) {
+ return v; // expected-warning {{implicit conversion loses integer precision}}
+}
+
+typedef int int4 __attribute__ ((vector_size(16)));
+typedef long long long2 __attribute__((__vector_size__(16)));
+
+int4 test1(long2 a) {
+ int4 v127 = a; // no warning.
+ return v127;
+}
+
+int test2(long v) {
+ return v / 2; // expected-warning {{implicit conversion loses integer precision: 'long' to 'int'}}
+}
+
+char test3(short s) {
+ return s * 2; // expected-warning {{implicit conversion loses integer precision: 'int' to 'char'}}
+}
More information about the cfe-commits
mailing list