[PATCH] D144011: [clang]Fix warning for signed conversion
Yaxun Liu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Feb 15 09:19:23 PST 2023
yaxunl updated this revision to Diff 497703.
yaxunl added a comment.
revised by Fanrui's comments
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D144011/new/
https://reviews.llvm.org/D144011
Files:
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/sign-conversion.c
Index: clang/test/Sema/sign-conversion.c
===================================================================
--- clang/test/Sema/sign-conversion.c
+++ clang/test/Sema/sign-conversion.c
@@ -5,4 +5,8 @@
void test(int x) {
unsigned t0 = x; // expected-warning {{implicit conversion changes signedness}}
unsigned t1 = (t0 == 5 ? x : 0); // expected-warning {{operand of ? changes signedness}}
+
+ // Clang has special treatment for left shift of literal '1'.
+ // Make sure there is no diagnostics.
+ long t2 = 1LL << x;
}
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -14293,6 +14293,12 @@
if (S.SourceMgr.isInSystemMacro(CC))
return;
+ if (SourceBT && SourceBT->isInteger() && TargetBT &&
+ TargetBT->isInteger() &&
+ Source->isSignedIntegerType() == Target->isSignedIntegerType()) {
+ return;
+ }
+
unsigned DiagID = diag::warn_impcast_integer_sign;
// Traditionally, gcc has warned about this under -Wsign-compare.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144011.497703.patch
Type: text/x-patch
Size: 1113 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230215/a040b1aa/attachment.bin>
More information about the cfe-commits
mailing list