[PATCH] D144011: [clang]Fix warning for signed conversion on LP64
    Yaxun Liu via Phabricator via cfe-commits 
    cfe-commits at lists.llvm.org
       
    Tue Feb 21 09:44:08 PST 2023
    
    
  
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rG8cda128c1eff: [clang]Fix warning for signed conversion on LP64 (authored by yaxunl).
Herald added a project: clang.
Changed prior to commit:
  https://reviews.llvm.org/D144011?vs=497703&id=499215#toc
Repository:
  rG LLVM Github Monorepo
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
@@ -1,8 +1,14 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wsign-conversion %s
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fsyntax-only -verify -Wsign-conversion %s
+// RUN: %clang_cc1 -triple x86_64-pc-windows-msvc -fsyntax-only -verify -Wsign-conversion %s
 
 // PR9345: make a subgroup of -Wconversion for signedness changes
 
 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
@@ -14316,6 +14316,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.499215.patch
Type: text/x-patch
Size: 1438 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230221/5e756d32/attachment.bin>
    
    
More information about the cfe-commits
mailing list