Skip to content

Commit

Permalink
[clang][Sema] Subclass -Wshorten-64-to-32 under `-Wimplicit-int-con…
Browse files Browse the repository at this point in the history
…version` (#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`.
  • Loading branch information
whisperity committed Feb 8, 2024
1 parent e50189b commit 4b72c5e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
7 changes: 6 additions & 1 deletion clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------------------
Expand Down
6 changes: 3 additions & 3 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -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]>;
Expand Down Expand Up @@ -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">;
Expand Down Expand Up @@ -942,7 +943,6 @@ def Conversion : DiagGroup<"conversion",
EnumConversion,
BitFieldEnumConversion,
FloatConversion,
Shorten64To32,
IntConversion,
ImplicitIntConversion,
ImplicitFloatConversion,
Expand Down
6 changes: 5 additions & 1 deletion clang/test/Sema/conversion-64-32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
21 changes: 21 additions & 0 deletions clang/test/Sema/conversion-implicit-int-includes-64-to-32.c
Original file line number Diff line number Diff line change
@@ -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'}}
}

0 comments on commit 4b72c5e

Please sign in to comment.