[clang][Sema] Subclass -Wshorten-64-to-32 under -Wimplicit-int-conversion#80814
Merged
whisperity merged 2 commits intollvm:mainfrom Feb 8, 2024
Merged
Conversation
Member
|
@llvm/pr-subscribers-clang Author: None (whisperity) ChangesAlthough "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 Closes #69444.
-Wconversion
# ...
-Wfloat-conversion
-Wfloat-overflow-conversion
-Wfloat-zero-conversion
- -Wshorten-64-to-32
-Wint-conversion
-Wimplicit-int-conversion
+ -Wshorten-64-to-32
-Wobjc-signed-char-bool-implicit-int-conversion
-Wimplicit-float-conversion
-Wimplicit-int-float-conversion
-Wimplicit-const-int-float-conversion
-Wobjc-signed-char-bool-implicit-float-conversion
# ...3 Files Affected:
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'}}
+}
|
ab626cf to
ac12272
Compare
AaronBallman
reviewed
Feb 7, 2024
Collaborator
AaronBallman
left a comment
There was a problem hiding this comment.
LGTM aside from a minor change to the release notes, thank you for this improvement!
Collaborator
|
(Note, precommit CI failures are unrelated.) |
Contributor
|
This looks right to me, thanks. |
Co-authored-by: Aaron Ballman <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Nov 26, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Nov 26, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Nov 26, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Nov 28, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Nov 30, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Dec 4, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
sayboras
added a commit
to cilium/cilium
that referenced
this pull request
Dec 4, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
github-merge-queue bot
pushed a commit
to cilium/cilium
that referenced
this pull request
Dec 4, 2024
As per the below PR, clang 19.1.x is having -Wshorten-64-to32 under the -Wimplicit-int-conversion, which is already forbidden in Makefile.bpf. This commit is to avoid the conversion error as per below sample ``` ./lib/nodeport.h:1825:18: error: implicit conversion loses integer precision: '__u64' (aka 'unsigned long long') to '__s32' (aka 'int') [-Werror,-Wshorten-64-to-32] 1825 | __s32 len_old = ctx_full_len(ctx); ``` Relates: llvm/llvm-project#80814 Signed-off-by: Tam Mach <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Closes #69444.
diagtool treediff:-Wconversion # ... -Wfloat-conversion -Wfloat-overflow-conversion -Wfloat-zero-conversion - -Wshorten-64-to-32 -Wint-conversion -Wimplicit-int-conversion + -Wshorten-64-to-32 -Wobjc-signed-char-bool-implicit-int-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Wimplicit-const-int-float-conversion -Wobjc-signed-char-bool-implicit-float-conversion # ...